Although I am not a Java engineer, I have never written Java, but I am still very concerned about this technology. New Features of Java 8: static methods can be fully defined in the interface. A common example is that in java class libraries, for some interfaces such as Foo, there will be a tool class Foos with static methods to generate or use with Foo object instances. since static methods can exist in interfaces, the Foos tool class can use interfaces in most cases.
Although I am not a Java engineer, I have never written Java, but I am still very concerned about this technology. New Features of Java 8:
The static method can be completely defined in the interface. A common example is that in java class libraries, for some interfaces such as Foo, there will be a tool class Foos with static methods to generate or use with Foo object instances. since the static method can exist in the interface, in most cases, the Foos tool class can use the public method in the interface to proxy (or set the Foos to package-private ).
In addition, the interface in Java 8 can define the default method. for example, a for-each loop method can be added to java. lang. Iterable:
Public default void forEach (Consumer Action ){
Objects. requireNonNull (action); for (T t: this ){
Action. accept (t );
}
}
In the past, adding methods to java class library interfaces was basically impossible. adding a method to an interface means that the Code implementing this interface is broken. but now, as long as you can provide a correct and wise implementation of the default method, the java class library maintainer can add methods in the interface.
In Java 8, a large number of default methods have been added to the core JDK interface.
The following is the focus of this article. In Ubuntu, Java 8 is installed using PPA (Ubuntu 10.04-Ubuntu 14.04 is supported ):
Sudo add-apt-repository ppa: webupd8team/java
Sudo apt-get update
Sudo apt-get install Oracle-java8-installer
Run the following command to view the version:
Javac-version
To install Java 8, you must accept the license. To install Java 8 automatically, run the following command before installation:
Echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo/usr/bin/debconf-set-selections
Set Java 8 environment variables:
Sudo apt-get install oracle-java8-set-default
Switch to Java 7:
Sudo update-java-alternatives-s java-7-oracle
Switch to Java 8:
Sudo update-java-alternatives-s java-8-oracle
For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2