Publish Your Article Here

Java 8 new features

Java Platform, Standard Edition 8 is a major feature release. This document summarizes features and enhancements in Java SE 8 and in JDK 8.

Lambda Expressions

Lambda Expressions, a new language feature, has been introduced in this release. They enable you to treat functionality as a method argument, or code as data. Lambda expressions let you express instances of single-method interfaces more compactly. Click here for more details.

Method References

Java 8 introduced a new feature called "Method Reference". It is used to refer methods of functional interfaces. They are effectively a subset of lambda expressions, because if a lambda expression can be used, then it might be possible to use a method reference, but not always. Click here for more details.

Default Methods

Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces. Click here for more details.

ForEach() method

Java 8 provides a new method called forEach() to iterate over collection framework. It is defined in Iterable and Stream interface. It is a default method defined in the Iterable interface. Collection classes which extends Iterable interface can use forEach loop to iterate elements. Here are the examples:

  1. Java 8 forEach example with Map
  2. Java 8 forEach example with List

Stream API

First of all, please note that "Streams are not collections". is introduced to process elements in sequence. Also don't get confused with InputStream, doesnot have any relationship with InputStream or OuputStreams. are part of functional programming. Click here for more details.

Date and Time API

Prior to Java 8, Java Date and Time has below drawbacks:

  • The existing classes java.util.Date and SimpleDateFormatter are not thread-safe.
  • Poor API design. For example, years in java.util.Date start at 1900, months start at 1, and days start at 0—not very intuitive.

Java SE 8 will ship with a new date and time API in java.time that offers greatly improved safety and functionality for developers. The new API models the domain well, with a good selection of classes for modeling a wide variety of developer use cases. Click here for more details

Knowledge Centre
When to use LinkedList or ArrayList?
Accessing elements are faster with ArrayList, because it is index based. But accessing is difficult with LinkedList. It is slow access. This is to access any element, you need to navigate through the elements one by one. But insertion and deletion is much faster with LinkedList, because if you know the node, just change the pointers before or after nodes. Insertion and deletion is slow with ArrayList, this is because, during these operations ArrayList need to adjust the indexes according to deletion or insetion if you are performing on middle indexes. Means, an ArrayList having 10 elements, if you are inserting at index 5, then you need to shift the indexes above 5 to one more.
Famous Quotations
Success consists of going from failure to failure without loss of enthusiasm.
-- Winston Churchill

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2018 by Nataraja Gootooru. All Rights Reserved.