Objective
The previous article explained in detail how to install the virtual machine +linux system in a Windows environment and successfully deployed the JDK.
But after we deployed the JDK, we judged that the success of the deployment was based on whether the "java-version" command had the correct content to print, perhaps not too convincing. May be able to run a correct Java program, regardless of perceptual or rational point of view, there will be a better understanding.
So this article writes a very simple Java code and compiles it in a Linux environment to prove that the JDK is deployed correctly.
Code verifies that the JDK deployment is correct
1, Cascade set up two directories
First set up two directories at once:
The parent directory Java_progream means that this directory is all used for Java code, and hello represents a Java program directory, which is of course named according to personal preferences can be different.
2, write a simple Java program
Enter the Java_program/hello directory and use VI to create a. java file (vi can be modified when the file name exists, can be created when the file name does not exist):
Writing a very simple code is to print out the characters "Hello":
Note that the arrow means that the edited text must be Wq saved before it is created.
3. Compiling Hello.java
using javac Hello.java to compile our written Java code, If there is a problem with the writing, there will be a compilation error message out, if the write is not a problem, then compile successfully, after the successful compilation of the Directory is:
See the presence of Hello.class and Hello.java two files.
4, the implementation of Hello.class
Now that the Hello.class has been compiled successfully, the final thing is to execute the file, using java Hello :
Print out the string "Hello", successfully
Postscript
If the above steps are OK and the results are seen successfully, then it is well proven that we have successfully deployed the JDK1.7 in the Linux environment.
On the basis of successful deployment of JDK1.7, we will further play a variety of distributed components such as Memcache, Zookeeper, Hadoop, and more.
Run a simple Java program after deploying the JDK in a Linux environment