Run a simple Java program after deploying JDK in Linux

Source: Internet
Author: User

Run a simple Java program after deploying JDK in Linux

Preface

The previous article explains in detail how to install a virtual machine + Linux System Under VMware and successfully deploy JDK.

However, after the JDK is deployed, we determine whether the deployment is successful based on whether the "java-version" command has correct content printing, which may not be too convincing. It may be able to run a correct java program. There will be a better understanding from the perspective of sensibility or rationality.

Therefore, this article writes a very simple java code and compiles and runs it in a Linux environment to prove that JDK deployment is indeed normal.

Code verification: JDK deployment is correct

1. cascade two directories

First, create two directories at a time:

The parent directory java_progream indicates that the directory is used to store java code. hello indicates a java program directory. Of course, the name may vary depending on your preferences.

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

Use javac Hello. java to compile the written java code. If there is a problem in writing, the following will prompt a compilation error message. 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, the final step is to execute this file. You can use java Hello:

Print the string "Hello", succeeded

Postscript

If the preceding steps are OK and the result is displayed successfully, it fully proves that JDK1.7 is successfully deployed in Linux.

Based on the successful deployment of JDK, we will go further to the distributed components such as MemCache, Zookeeper, and Hadoop.

This article permanently updates the link address:

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.