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
What is race condition?
A race condition is a situation in which two or more threads or processes are reading or writing some shared data, and the final result depends on the timing of how the threads are scheduled. Race conditions can lead to unpredictable results and subtle program bugs. A thread can prevent this from happening by locking an object. When an object is locked by one thread and another thread tries to call a synchronized method on the same object, the second thread will block until the object is unlocked.
Famous Quotations
It is amazing what you can accomplish if you do not care who gets the credit.
-- Harry Truman

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