Hanshunping the servlet video series Unexpected Harvest Command-line compilation Java class solution with package

Source: Internet
Author: User

    • Command-line compilation of Java classes with packages

Compiling this piece at the command line is basically about getting started, and then going straight to the IDE. This is true, afraid of those ... Then today in the video to see this method, think it may be used, so it is recorded, for self-examination.

The steps are as follows:

Create a new Java file in X disk and write a piece of code with the package in it, as shown in the following example:

Package Com.hsp;public class exercise{public static void Main (string[] args) {System.out.println ("Hello world!  "); }}

I am here D-disk, file for Exercise.java, and then save (because the EditPlus tool is used, so there will be a backup file):

When compiling the file on the command line, you need to add-D after javac to compile, as an example:

As you can see from the example, the compilation was successful without an error. If you follow the steps to compile a sample error stating that there is an error in the Java environment configuration, please check.

Then look at the X-disk (I'm here for the D-drive) related files and you can see that the compilation generated the COM folder

Click to go to see the HSP folder, and then open to see the Exercise.class file.

Then run Java com.hsp.Exercise, note that not Java Exercise, you can see the following, indicating that the operation was successful. If you follow the steps to run the sample failure, there may be an error in the Java environment configuration, please check.

Hanshunping the servlet video series Unexpected Harvest Command-line compilation Java class solution with package

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.