Java 8 is the latest version of Java Programing Language. It was released on 18 March 2014. Before that java is most popular and wider used language. Still, most of the companies use Java because of its good features but Java 8 has some amazing features which help to build faster and attracting application. Till most of the developer don’t aware of Java 8.  Also, many developers and companies used an old version of Java because it’s difficult to switch from one platform to another platform and very few companies have a smart professional developer who has knowledge of Java 8.   

If you want to use Java 8 in your project then read some new features before using it

 

There are dozens of features added to Java 8, the most significant ones are mentioned below −

 

  • Lambda Expression:

 

Lambda Expression is the best newly added features in Java 8. Lambda Expression helps to reduce code using a single method class.

Example :

1 - lambda expression

 

Advantages :

      1. Fewer Lines of Code.

  1. Sequential and Parallel Execution Support by passing behavior in methods.

 

  • Default Interface Methods:

 

Java 8 gives facility to create default method inside the interface. The method inside the interface which is tagged with default keyword is known as default methods.

Example:

Before java 8  ⇒

interface InterfaceA {

 public void saySomething();

}

Implementing in JAVA 8 ⇒

interface InterfaceA {

public void saySomething();

default public void sayHi() {

  System.out.println(“Hi”);

}

}

Means we can also define a method in the interface using default key before method.

 

  • Date and Time API:

Java 8 help in handling date and time operations in an easier way. Java.time package contains a new date and time API.

Example :

Date API:

LocalDate today = LocalDate.now();

int year = today.getYear();

int month = today.getMonthValue();

int day = today.getDayOfMonth();

System.out.printf(“Year : %d Month : %d day : %d \t %n”, year, month, day);

Output:

Today’s Local date : 2014-01-14 Year : 2014 Month : 1 day : 14

 

Time API:

Clock clock = Clock.systemUTC();

System.out.println(“Clock : ” + clock);

Clock defaultClock = Clock.systemDefaultZone();

System.out.println(“Clock : ” + clock);

 

Output:

Clock : SystemClock

[Time]

Clock : SystemClock[default zone]

 

  • Java Annotation:

Type annotations were created for stronger type checking also to improve analysis of Java programs.

@NonNull – The compiler can determine cases where a code path might receive a null value, without ever having to debug a NullPointerException.

@ReadOnly – The compiler will flag any attempt to change the object.  This is similar to Collections.unmodifiableList, but more general and verified at compile time.

@Regex – Provides compile-time verification that a String intended to be used as a regular expression is a properly formatted regular expression.

@Tainted and @Untainted – Identity types of data that should not be used together, such as remote user input being used in system commands, or sensitive information in log streams.

@m – Units of measure ensures that numbers used for measuring objects are used and compared correctly, or have undergone the proper unit conversion.

@Override – While overriding a method in the child class, we should use this annotation to mark that method. This makes code readable and avoids maintenance issues, such as: while changing the method signature of the parent class, you must change the signature in child classes (where this annotation is being used) otherwise the compiler would throw a compilation error. This is difficult to trace when you haven’t used this annotation.

 

@override example:

public class MyParentClass {

public void justaMethod() {

    System.out.println(“Parent class method”);

}

}

public class MyChildClass extends MyParentClass {

 

@Override

public void justaMethod() {

    System.out.println(“Child class method”);

}

}

 

 

  • Nashorn JavaScript Engine:

 

Nashorn is the new javascript engine build to develop a javascript application.

 

  • Stream API: Stream API are introduced in Java 8 to perform functional operations on collections/Arrays. Steam API is used to perform filter, reduce, map operations.

 

Example :

public class StreamBuilders

{

public static void main(String[] args)

{

Stream<Integer> stream = Stream.of(1,2,3,4,5,6,7,8,9);

stream.forEach(p -> System.out.println(p));

}

}

 

Now you saw the features of Java 8 and how is helpful to develop an app but if you don’t know how to install Java 8 into your system then don’t get panic I’ll show you step by step procedure to install Java 8 in windows, Ubuntu and Mac operating system.

 

  • Steps to install Java 8 on windows :
  1. First of all, you have to download Java 8 package (32 bit or 64 bit) for your windows machine. You can download it online from java website.
  2. Click on download button following dialog box will appear then click on “Save” button.
  3. After completion of download button open the saved file and proceed to install.
  4. Click on install button
  5. Once the installation complete click on “Close” button
  6. Now set the environment variable. To open environment variable window press windows + pause/ break or go through control panel → System → Advanced system setting → Environment variable.

 

 

Click on new button and set the three variables as PATH, CLASSPATH and JAVA_HOME

a) To set path : ” PATH = <JDK installation directory>\bin;%PATH%”

If you used Java 1.8 then your path will be

C:\Program Files\Java\jdk1.8.0_65\bin;%PATH%

b) To set classpath : CLASSPATH = <JDK installation directory>\lib\tools.jar;”

If you used java 1.8 then your path will be :

CLASSPATH = C:\Program Files\Java\jdk1.8.0_31\lib\tools.jar;

 

3-set classpath

 

Now restart your PC and go to command prompt then type javac

If java is installed then following window will appear.

4-comandprompt

 

Steps to install Java 8 in Ubuntu :

Following are the steps to install java on ubuntu using command

First of all, you have to upgrade the package using command

sudo apt-get install

Now you see the following running command

5-java Running Command

 

Now you have to check whether Java is already installed in your system or not using the command

java -version

If java is installed in your system then it returns java otherwise it shows the following message.

5-install ubuntu

If java is not installed on your system then use these command

sudo apt-get install default-jre

Now you see the command execution line like this

 

After completion of execution, java is installed on your system

 

  • Steps to install Java 8 on Mac

Following are the steps to install java on your Mac system

  1. First of all download the jre-8u65-macosx-x64.pkg file.
  2. Then save and extract the file
  3. Double click on .pkg file and run it
  4. Double click package icon to install it

 

   Welcome screen appear then click on next button.

 

After installation confirmation screen will appear. Click on close button to finish the installation.

 

There are lots of new features included in Java 8. You saw how Java 8 works with new features these helps the programmer to reduce code using lambda expression and so on…

Today’s employer wants java skill with knowledge of updated technology and certification. Java has a high demand in software industry also employee got high salary package job.

 

Most of the students/ employee give preference for doing java certification because it is plus point at the time of interview if you have certification. So if you want to start your career in java then join some best java classes in Pune. They give you detailed knowledge of java with an advanced concept.

So go ahead and learn java. Best Luck.