Java Command Prompt compilation

Source: Internet
Author: User

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

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.