JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

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". java.util.stream is introduced to process elements in sequence. Also don't get confused with InputStream, java.util.stream doesnot have any relationship with InputStream or OuputStreams. java.util.stream 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
Pass by value Vs Pass by reference
Pass by value: Passing a copy of the value, not the original reference.

Pass by reference: Passsing the address of the object, so that you can access the original object.
Famous Quotations
Discipline is just choosing between what you want now and what you want most.
-- Unknown Author

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 © 2017 by Nataraja Gootooru. All Rights Reserved.