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:
- 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 literalnull
), 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 NullPointerExceptionsA 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.....
No comments:
Post a Comment
test