Wednesday, 7 May 2014

What's New JAVA 8 Release

JAVA 8

“Java Platform, Standard Edition 8 (Java SE 8)” is released on 18th March 2014. Along with the Java SE 8 platform, the product that implements the platform, “Java SE Development Kit 8 (JDK 8)”

Java SE 8 is one of the most feature packed release in the JavaHistory.

Highlight Features in Java 8 Release:)
  • Permanent Generation
  • Parallel Array Sorting
  • Lambda Expressions
  • Optional Class API
  • Date & Time API
  • Functional Interfaces
  • Pipelines and Streams
  • Type Annotations
  • Default Methods

1.Permanent Generation
          What does it mean??
  • who has never configured their "PermSize" or their "MaxPermSize" JVM memory?
  • This was normally done after receiving those ugly "java.lang.OutOfMemoryError:PermGen error" errors.
  • This is now replaced by Metaspace in this release.The Metaspace will re-size itself depending on the demand we have of memory at runtime.If we need to,we can still tune the amount of Metaspace by setting "MaxMetaSpaceSize" param.
2.Parallel Array Sorting
         We are used to sorting arrays with “Arrays.sort”. This used Merge Sort or Tim Sort algorithms for the sorting. The problem they have is that they are executed sequentially, so we do not gain all the benefits multithreading has to offer us. For this purpose they implemented “Arrays.parallelSort”.

3.Lambda expressions

  • Lambda expressions might be the biggest and most anticipated feature of Java 8. They are basically used to pass code instead of objects to a method or to deal with group of data to execute algorithms.
  • This will produce much simpler and more readable code. Lets take a look at some concepts around this.
  • The normal approach in Java is to iterate collections externally, so we would have something like this:
for (String value: myCollection) {
                System.out.println(value);
        }
  • syntax for Lambda expressions:
                 input arguments -> body
  • What we are doing here is iterating the list and pulling objects one by one. It would be more natural if we could just say from the beginning what we want to extract form the collection. This is exactly the concept of how we would do it with lambdas:
      myCollection.forEach((String value) -> System.out.println(value));

4.Optional Class API

Why?
  • Every Java programmer is maddened every once in a while by the notorious NullPointerException. Not only Java programmers, by the way. Probably every JVM programmer is suffering from the problem.

NULL??
  • In Java null is actually a type, a special one: it has no name, we cannot declare variables of its type, or cast any variables to it, in fact there is a single value that can be associated with it (i.e. the literal null), and unlike any other types in Java, a null reference can be safely assigned to any other reference types.

what??
The newer version of Java i.e Java 8 introduces a new class called Optional. The Javadoc for Optional class says:Optional class is supposed to cure NullPointerExceptions


A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.


All features and samples will update soon.....

01_EJB_Introduction_TO_EJB

EJB

  • EJB stands for Enterprise Java beans.
  • This will come into service layer in the J2EE architecture where all of our business logic reside.
  • For example business operations like manupulating database,sending mails,sending messages to message queues.
  •  J2EE container Provides some facilities to EJB like Transaction,security,pooling,concurrency,Timers,Intersepters..

Types of EJBS


1.Stateless Session Bean
  • The container usually maintains a pool of instances of beans.
  • When a client invoke the method of bean  first one instance may picked up by the container and one more time the client trying to access the other method  in the bean may be some other instance invoked by the container.So first instance may not aware of the values of other instance of the same bean.So we cant store state info in this case.

  • We should not save the State in this bean.Means we cant store any values for the variables and state information  like 
                               @stateless
                               Public String getHello( String Name){
                               String EmpName=Name; //We cant store like values
                               }

  • Most of the business operations are singular.Like sending Mails and logging in user..They dont want to store the state of information.In such cases we may use Stateless session bean.
 In this type of beans the container managed the pool of instances.
.
2.Stateful Session Bean


  • This beans are Client oriented.There is one instance of bean for each client.
  • If a client invoke a method of bean one instance get created and the client will invoke another method of the bean  and save some state and second time the perticular instance only get picked up for the specific client.So it will maintain the state information.
  • There is no pool of instances of the bean in the container,the instance is created just before the client get serviced.
 




  • The client is supposed to issue the command in this type of bean.But in stateless session bean container will maintain the instances.



3.singleton Session Bean
  • Only one instance this bean per application server.Every client will invoke the same instace anyway some concurrency mechanisms are there to avoid conflicts.
  • If we have 2 JVMs in our server it will create two singleton instances per each JVM.Also in distributed systems environment we have different JVMs and this sigleton bean will create each instance per each JVM:)



Note:

Clients:


Lets  assume one bean in service layer(EJB).This bean may be accessed  by  another bean(another EJB) in the same layer or  in web layer(using JSP or JSF) or some other layer with the same container or from  outside..

Local:Beans reside within application server.
Remote:When beans reside outside the Application server known as Remote clients.

What's New in J2EE 7

Java EE 7 is the latest edition of the enterprise platform that powers a lot of (web) applications.

Top Features of J2EE 7 


  1. Batch Applications
  2. Web Socket
  3. JSON Processing
  4. More Annotated POJOS
  5. concurrency Utilities

New Releases of J2EE  7 technologies

  1. HTML 5
  2. JAX-RS 2.0   (Java API for Restful(RePresentational State Transfer) Webservices)
  3. JMS 2.0
  4. JPA 2.1   (Java Persistance API)
  5. JSF 2.2    (Java Server Faces)
  6. Expression Language 3.0
  7. CDI 1.1   (Contexts and Dependency Injection)
  8. EJB 3.2  (Enterprise Java Beans)
  9. Batch Application for Java Platform 1.0
  10. Concurrency Utilities for J2EE
  11. Servlet 3.1
  12. Bean Validation 1.1
  13. Java Mail 1.5
  14. JCA 1.7  (J2EE Connector Architecture)
  15. Java API for Web socket 1.0
  16. JTA 1.2   (Java Transaction API)
  17. Java API for JSON Processing 1.0 (Java Script Object Notation)