Run simple java programs in Linux and java programs in linux

Source: Internet
Author: User

Run simple java programs in Linux and java programs in linux
1. Install java1 and download JDK 8

Login URL: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Select the jdk version to download. (Tips: After Windows is downloaded, it can be sent to Linux through FTP or SSH.) 2. log on to Linux and switch to the root user.

Su root obtains root user permissions, and the current working directory remains unchanged (the root password is required)
Or
Sudo-I directly switches to root without the root password (requires the current user password) 3. Create a java installation directory under the usr directory

Cd/usr
Mkdir java4.pdf copy jdk-8u60-linux-x64.tar.gz to the java directory

Cp/mnt/hgfs/linux/jdk-8u60-linux-x64.tar.gz/usr/java/5, decompress jdk to the current directory, get the folder jdk1.8.0 _ * (Note: Download different versions of JDK directory names !)

Tar-zxvf jdk-8u60-linux-x64.tar.gz6, build a link for him after installation to save directory Length

Ln-s/usr/java/jdk1.8.0 _ 60 // usr/jdk7. Edit the configuration file and configure environment variables.

Vim/etc/profile
Add the following content at the end of the text:

JAVA_HOME=/usr/jdk

CLASSPATH=$JAVA_HOME/lib/

PATH=$PATH:$JAVA_HOME/bin

export PATH JAVA_HOME CLASSPATH8. Restart the machine or execute the command: source/etc/profile

Sudo shutdown-r now9. Check the installation status.

Java-version
Java version "1.8.0 _ 60"
Java (TM) SE Runtime Environment (build 1.8.0 _ 60-b27)
Java HotSpot (TM) Client VM (build 25.60-b23, mixed mode) ps: possible error messages:

Bash:./java: cannot execute binary file
This error may occur because a 64-bit jdk is installed on a 32-bit operating system,
1. Check whether the number of digits of the jdk and Linux versions is consistent.
2. Check whether your Ubuntu is a 32-bit or 64-bit system. 2. Check the java installation path.

First, declare that which java cannot find the installation path. Which java locates the java program execution path. The materials on the Internet are all cloud-based, so you don't have to think about them. So how to locate the installation path of java.

1. confirm that the installation is successful.

In fact, if no soft connection is established, you can find the installation path directly.

You can use the preceding command to search for the java version to confirm that the installation is successful.

2. Search Path

Then use which java to search for the path and check whether there is a soft connection.

Finally, find the java installation path.

3. Create a program and test it. 1. Create a test directory.
mkdir -p java_program/hello
2. Write a simple java program

Go to the java_program/hello directory and use vi to create a. java file (vi can modify the file when the file name exists and create the file when the file name does not exist ):

Write a simple code that prints the characters "Hello:

Note that the edited text must be saved by wq before the file is created.3. Compile Hello. java

UseJavac Hello. javaTo compile the java code we have written. If there is a problem in writing, the following will be a compilation error prompt. If there is no problem in writing, the compilation will be successful, after compilation, the directory is:

The Hello. class and Hello. java files exist.4. Execute Hello. class

Since Hello. class has been compiled successfully, this file is actually executed.Java HelloYou can:

Print the string "Hello", succeeded

Related Article

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.