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: