Here we mainly discuss about the differences, or in other words advancements which have been included in java 8 when compared to java 7.
To begin with let me give a brief introduction on java 7. Java 7 was released in 2011. This was the first major update of Java after being acquired by Oracle from Sun Micro-systems. Java 7 is the final Java version that would officially support windows XP.
There were some major features that were included in Java 7. Such as,
- Compressed 64-bit pointers
- Upgraded class-loader architecture
- Multiple exception handling
- JVM support for dynamically support languages
- Upgraded Rowset 1.1 and JDBC 4.1
- String object in switch statement
- Automatic resource management in try statement and much more.
But in this blog our main concern will be on discussing few advancements that happened when updating from Java 7 to Java 8.
Java 8 was released in March 2014. The most anticipated feature — Lambda Expressions, was introduced and made possible from Java 8. Use of this Lambda Expressions made Java closer to functional programing which it was not used to be. Java 8 also includes a faster and improved JVM which makes it possible to run programs more efficiently. Now it is time to point out and discuss on some of the major upgrades of Java 8 when compared to Java 7.
- Lambda expressions only have a body and a parameter list.
- Advantages we get by using Lambda Expressions are,
- Enhanced iterative syntax
- Code Reuse
- JAR file size reduction
- Simplified variable scope
- Encouraging Functional Programming
- Let us look at a couple of examples using lambda expressions
Null Reference Template or we can call it the Java Optional Class
- Advantages using the Java Optional class are,
- No Null Pointer Exceptions at runtime
- Clean APIs can be developed
- Null checks are not required
New Date and Time API
- In java.util.Date class the years start from 1900 and the months start from 0. So it is important to know it, as when we want to assign a year and a month it must be as (YYYY-1900) and (MM-1). This was overcome in Java 8 using the classes in java.time package.
- Unlike integer or string, Date class in mutable. Which means that the date can be changed without the owner class knowing. Java 8 have a solution for this.
Unsigned Integer Arithmetic
- It is not clear what Java 8 have tried to achieve by the advancement in unsigned integer arithmetic. But generally unsigned integer is considered to be harmful for java. It adds complexity to the type conversion tools, type system and library APIs
- The main advantage that we get using Stream API is that it clearly increases the speed and the efficiency of the program. It is considered to be a powerhouse in Java.
- Parallel sorting uses multiple threads for the operation. It makes the program fast and efficient. This will not be that much visible with a small data set. But if we use a large data set the efficiency and the increase in performance will be highly noticeable.
With that now we have come to the end of this section and the main aim of it was to give an idea about the updated and added features in Java 8 compared to Java 7. According to the examples provided hope you got an idea on how to use these advancements for your benefit. Most of these provide us with advantages but there are certain drawbacks as well if we look in different perspectives. It is important to remember, only to absorb the features that would help us and make our program more efficient, reliable and stable.
Cheers!! Have a pleasant day!!