Install the Java Runtime Environment in Linux (CentOS) and output Hello World

Source: Internet
Author: User

Install the Java Runtime Environment in Linux (CentOS) and output Hello World

Recently I plan to learn about Hadoop and spark. I need to install the Java Runtime Environment. My system is CentOS.

1. Install jdk
1. Enter the usr directory

Cd/usr

2. Create a java installation directory under the usr directory

Mkdir java

3. Copy jdk-8u45-linux-x64.rpm to the java directory

Cp/root/hadoop_home/jdk-8u45-linux-x64.rpm/usr/java/

4. Install jdk

Cd/usr/java

Rpm-ivh jdk-8u45-linux-x64.rpm

5. After the installation is complete, create a link for him to save the directory Length

Ln-s/usr/java/jdk1.8.0 _ 45 // usr/jdk

6. Edit the configuration file

Vim/etc/profile

Add the following content:

JAVA_HOME =/usr/jdk
CLASSPATH =.: $ JAVA_HOME/lib/
PATH = $ PATH: $ JAVA_HOME/bin
Export PATH JAVA_HOME CLASSPATH1
8. Restart the machine or source/etc/profile

Sudo shutdown-r now

9. view the installation status

Java-version

Java version "1.7.0 _ 25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

Ii. Output Hello world
1. Create javac helloworld. java

Class Test {
Public static void main (String [] args ){
System. out. println ("test input main arguments ");
System. out. println (args [0] + "" + args [1]);
System. out. println ("end of main ");
}
}

2. Compile and run
1) javac helloworld. java
The Test. class file is generated.
2) java Test. class hello world!
Output result:
-Bash-4.1 # java Test hello world
Test input main arguments
Hello world
End of main

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.