Casa > 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. @FunctionalInterface anotação é adicionada para que possamos marcar uma interface como interface funcional.

Não é obrigatório usá-la, mas é melhor usá-la com interfaces funcionais para evitar a adição de métodos extras acidentalmente. Se a interface é anotada com @FunctionalInterface annotation e tentamos ter mais de um método abstrato, ele lança erro de compilação.

Lambda Expression

Lambda Expression são a forma pela qual podemos visualizar a programação funcional no mundo orientado a objetos java. Objetos são a base da linguagem de programação java e nunca podemos ter uma função sem um objeto, por isso a linguagem Java fornece suporte ao uso de expressões lambda apenas com interfaces funcionais.

Desde que haja apenas uma função abstrata nas interfaces funcionais, não há confusão na aplicação da expressão lambda ao método. A sintaxe das expressões lambda é (argumento) -> (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

De Chrisy

Porque é que as pessoas têm guerras telefónicas entre o Android e o iPhone? :: Por que a estação de rádio é capaz de tocar músicas sem violar direitos autorais?