Java compiles with Command prompt
1: The Simplest way: direct compilation
1 /**2 file path: g:\ test Project \JAVA\SRC3 file name: Jacatext.java4 Write Time: 2016/6/25 Author: Zheng-hui6 Writing Instructions: Learning to compile Java files with command prompts7 */8 Public classJavatext {9 Ten Public Static voidMain (string[] args) { One ASystem.out.println ("Diligent, more practice to learn Java"); - } -}
In CMD, first locate the file path, then compile the Java file, and finally execute the compiled file
What if I have a Java file with a packet?
1 /**2 file path: g:\ test Project \JAVA\SRC3 file name: Jacatext.java4 Write Time: 2016/6/25 Author: Zheng-hui6 Write a note: Learn to compile a package Java file with a command prompt7 */8 9 PackageSrc.test.java;Ten One Public classJavatext { A - Public Static voidMain (string[] args) { - theSystem.out.println ("Diligent, more practice to learn Java"); - } -}
Results of Direct compilation:
What is this for?
And look at this:
Why did this pass?
The reason is that in the Java file is stated in the package (packages) caused by the compilation, although the compilation passed, but the class file is not under the corresponding package, run, cannot find the class file, so error can not find or load the main class
How to solve this problem?
Using the command-d command simply means that the corresponding folder will be created according to the package in the Java file, and then the class file will be placed inside ...
When running, you need to find the class file in the folder where the class files are stored, and then run to get the results ...
Use this command to successfully separate the Java source file from the class file ...
That's it.
Learn more, practise more to learn java~~
Java Command Prompt compilation