• Spring

  • JAVA

  • Struts 2

  • Hibernate

  • Different but Simple

Wednesday, 14 January 2015

Java 8 Features

Java 8 adds Lots of new features in major release. The first time I heard about lambda expressions in Java. This document summarizes features and enhancements in Java SE 8 and in JDK 8, Oracle's implementation of Java SE 8.


Main Features:

1)      Lambda Expressions & Virtual Extension Methods
2)      Reduce Cache Contention on Specified Fields
3)      Remove the Permanent Generation
4)      Retire Some Rarely-Used GC Combinations
5)      Small VM
6)      Launch JavaFX Applications
7)      Generalized Target-Type Inference
8)      Annotations on Java Types
9)      Parallel Array Sorting
10)   Date & Time API
11)   JDBC 4.2
12)   Unicode 6.2
13)   Stronger Algorithms for Password-Based Encryption


1]Lambda Expressions & Virtual Extension Methods:-

Add lambda expressions (closures) and supporting features, including method references, enhanced type inference, and virtual extension methods, to the Java programming language and platform.
They enable you to treat functionality as a method argument, or code as data. Lambda expressions let you express instances of single-method interfaces (referred to as functional interfaces) more compactly.
(int x, int y) -> x + y
() -> System.out.println(this)
(String str) -> System.out.println(str)
str -> System.out.println(str)
(String s1, String s2) -> { return s2.length() - s1.length(); }
(s1, s2) -> s2.length() - s1.length()

2] Reduce Cache Contention on Specified Fields:-

Define a way to specify that one or more fields in an object are likely to be highly contended across processor cores so that the VM can arrange for them not to share cache lines with other fields, or other objects, that are likely to be independently accessed.

3] Remove the Permanent Generation:-

Remove the permanent generation from the Hotspot JVM and thus the need to tune the size of the permanent generation.

4] Retire Some Rarely-Used GC Combinations:-

Remove three rarely-used combinations of garbage collectors in order to reduce ongoing development, maintenance, and testing costs.

5] Small VM:-

Support the creation of a small VM that is no larger than 3MB.

6] Launch JavaFX Applications:-

Enhance the java command-line launcher to launch JavaFX applications.

7] Generalized Target-Type Inference:-

Smoothly expand the scope of method type-inference to support
(i)inference in method context and (ii) inference in chained calls.

8] Annotations on Java Types:-

Extend the set of annotatable locations in the syntax of the Java programming language to include names which indicate the use of a type as well as (per Java SE 5.0) the declaration of a type.

9] Parallel Array Sorting:-

Add additional utility methods to java.util.Arrays that use the JSR 166 Fork/Join parallelism common pool to provide sorting of arrays in parallel.

10] Date & Time API:-

Define a new date, time, and calendar API for the Java SE platform.

11] JDBC 4.2:-

Changes under consideration for JDBC 4.2 include:
§  Add a generic setter/update method to ResultSet, PreparedStatement, and CallableStatement to support new data types such as those being defined in JSR 310.
§  Define REF_CURSOR support for CallableStatement.
§  Specify required DataSource properties for a Java EE environment.
§  Enhance DatabaseMetaData.getIndexInfo to provide new columns forCARDINALITY and PAGES which return a long value.
§  Add a new DatabaseMeta method to return the logical maximum size for a LOB.
§  Additional clean up of the spec as needed.

12] Unicode 6.2:-

The following were the primary changes in Unicode 6.1.0:
  • add 11 new blocks to java.lang.Character.UnicodeBlock,
  • add 7 new scripts to java.lang.Character.UnicodeScript, and
  • support over 700 new characters in j.l.CharacterString, and other classes.

13] Stronger Algorithms for Password-Based Encryption:-

Provide stronger Password-Based-Encryption (PBE) algorithm implementations in the SunJCE provider.



This is only summary of Main Features and we will discuss details in my Next Post. If you want more information about Java8 then goto  JAVA8 Official Site.
Read More

Friday, 1 March 2013

Email with Attachment



EmailAction.java
 The next step is to create an Action method that takes care of sending the email. Let us create a new class called EmailAction.java.
Action file have to save at src/vaibhav package.
Code-
package vaibhav;
import java.io.File;
import java.io.IOException;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import org.apache.commons.io.FileUtils;
public class SendEmailAction {
      // SMTP properties - fetched from struts.xml
      private String host;
      private String port;
      private String userName;
      private String password;
      private String userName1;
      private String password1;
      // file upload properties - fetched by interceptor fileUpload
      private File fileUpload;
      private String fileUploadFileName;
      private String fileUploadContentType;
      // e-mail fields - fetched from EmailForm.jsp
      private String recipient;
      private String subject;
      private String message;
      public String Login()
      {
            return "success";
      }
      public String doSendEmail() throws IOException, AddressException, MessagingException {
            File saveFile = null;
            String tempPath = System.getProperty("java.io.tmpdir");
            saveFile = new File(tempPath + File.separator + fileUploadFileName);
            FileUtils.copyFile(fileUpload, saveFile);
            System.out.println("file"+fileUpload);
            EmailUtility.sendEmail(host, port, userName1, password1, recipient,
                        subject, message, saveFile);
            System.out.println("save file"+saveFile);
            if (saveFile != null) {
                  saveFile.delete();
            }
            return "success";
      }
      public String getHost() {
            return host;
      }
      public void setHost(String host) {
            this.host = host;
      }
      public String getPort() {
            return port;
      }
      public void setPort(String port) {
            this.port = port;
      }
      public String getUserName() {
            return userName;
      }
      public void setUserName(String userName) {
            this.userName = userName;
      }
      public String getPassword() {
            return password;
      }
      public void setPassword(String password) {
            this.password = password;
      }
      public File getFileUpload() {
            return fileUpload;
      }
      public void setFileUpload(File fileUpload) {
            this.fileUpload = fileUpload;
      }
      public String getFileUploadFileName() {
            return fileUploadFileName;
      }
      public void setFileUploadFileName(String fileUploadFileName) {
            this.fileUploadFileName = fileUploadFileName;
      }
      public String getFileUploadContentType() {
            return fileUploadContentType;
      }
      public void setFileUploadContentType(String fileUploadContentType) {
            this.fileUploadContentType = fileUploadContentType;
      }
      public String getRecipient() {
            return recipient;
      }
      public void setRecipient(String recipient) {
            this.recipient = recipient;
      }
      public String getSubject() {
            return subject;
      }
      public void setSubject(String subject) {
            this.subject = subject;
      }
      public String getMessage() {
            return message;
      }
      public void setMessage(String message) {
            this.message = message;
      }
      public String getUserName1() {
            return userName1;
      }
      public void setUserName1(String userName1) {
            this.userName1 = userName1;
      }
      public String getPassword1() {
            return password1;
      }
      public void setPassword1(String password1) {
            this.password1 = password1;
      }
}




Output:-
  


Login successuful



When Email successfully send.



Give Error when unsuccessful.


Read More

    Categories

    Text Widget

    Followers