Install Java8 using PPA in Ubuntu

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.