Linux install JDK, write HelloWorld program

Source: Internet
Author: User

Today I learned the Linux installation JDK and made a note.

The first step is to determine whether Linux is 32-bit or 64-bit, and then download the corresponding version of the JDK to the Oracle official website, generally download the. tar.gz file. The command to view the Linux version is:getconf long_bit. If it is 64, then the system is 64 bits, and the same is 32 bits. I installed the 64-bit, so the download is the x64.tar.gz file.

The second step is to upload the downloaded JDK to the Linux system. In Linux, press alt+p to enter SFTP, and then use the put command to upload the JDK to the Linux system.

The third step is to extract the. tar.gz compressed file and set the compressed path, the command is tar-zxvf jdk-8u131-linux-x64.tar.gz-c apps/

After executing the command, view the contents of the apps path, with

Fourth step, set the environment variables. The command is:vi/etc/profile

Press Shift+g to the end of the file, then press O to add the following two lines:

Export java_home=/root/apps/jdk1.8.0_131

Export path= $PATH: $JAVA _home/bin

Save and exit

Fifth step, reload the environment variable. The command is:source/etc/profile

Now that you're done, test and command java-version:

===============================================================================================

Here is the first program Hello,world

The first step is to create the file Hello.java under the path, touch Hello.javawith the command line, then VI Hello.java, and go to the editor of Hello.java.

Step two, write the Hello.java program

At this point, if you follow the above installation JDK step by step, then Javac compiled Hello.java can be passed, in Hello.java the same path will be Hello.class file, but the class can not be executed, reported the wrong is Java.lang.UnsupportedClassVersionError, because the compilation is jdk1.8, but the run is jdk1.7, so there is a unsupportedclassversionerror unsupported version. The solution is to reload the jdk1.7 and configure the environment variables as described above.

The third step, to the path of Javac, compile the Hello.java, you need to write the path to the full

Fourth step, to the path where Hello.java is located, Java hello gets the final result

Well, Linux installs the JDK and writes Java's HelloWorld program to complete.

Linux install JDK, write HelloWorld program

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.