QNA > W > What Is The Difference Between Java 1.8 And Java 1.7?

What is the difference between Java 1.8 and Java 1.7?

The Following features are added in Java 8 which is missing in Java 7

1)forEach loop:- added forEach method in java.lang.Iterable Interface. for each loop is alternate option for for loop

class ForEachDemo{

public static void main(String args[]){

int num[]={1,3,4,5};

for(int i:num){

System.out.println(i);

}

}

}

2:default and static methods in Interfaces:-

Java 8, interfaces are enhanced to have method with implementation. We can use default and static keyword to create interfaces with method implementation.

3:-Functional Interfaces and Lambda Expressions:-

Functional Interface

An interface with exactly one abstract method is called Functional Interface. L'annotazione @FunctionalInterface viene aggiunta in modo da poter marcare un'interfaccia come interfaccia funzionale.

Non è obbligatorio usarla, ma è una buona pratica usarla con le interfacce funzionali per evitare l'aggiunta accidentale di metodi extra. Se l'interfaccia è annotata con l'annotazione @FunctionalInterface e cerchiamo di avere più di un metodo astratto, viene lanciato un errore del compilatore.

Lambda Expression

Lambda Expression è il modo attraverso il quale possiamo visualizzare la programmazione funzionale nel mondo java orientato agli oggetti. Gli oggetti sono la base del linguaggio di programmazione java e non possiamo mai avere una funzione senza un oggetto, ecco perché il linguaggio Java fornisce il supporto per usare le espressioni lambda solo con le interfacce funzionali.

Siccome c'è solo una funzione astratta nelle interfacce funzionali, non c'è confusione nell'applicare l'espressione lambda al metodo. La sintassi delle espressioni lambda è (argomento) -> (corpo). Now let’s see how we can write above anonymous Runnable using lambda expression.

Runnable r1 = () -> System.out.println("My Runnable");

Let’s try to understand what is happening in the lambda expression above.

Runnable is a functional interface, that’s why we can use lambda expression to create it’s instance.

Since run() method takes no argument, our lambda expression also have no argument.

Just like if-else blocks, we can avoid curly braces ({}) since we have a single statement in the method body. For multiple statements, we would have to use curly braces like any other methods.

4:-Java Stream API for Bulk Data Operations on Collections

5:-Improvment in Java Time API

6:-Improvment in Collection API

7:Concurrency API improvements

8:-java IO improvement

This all are newly added feature in Java 8.

Regards,

Yogesh Pawar

Java Programmer

Di Pinkham

In Gmail, qual è la differenza tra spostare un'email e etichettare un'email? :: Che aspetto ha Darth Vader senza il suo elmo?
Link utili