DOS commands to compile Java programs

Source: Internet
Author: User

The previous article to everyone wrote how to install the JDK configuration, now this article we will learn how to compile a DOS command under the Java program, no compiler can be directly compiled (hehe!). I'm going to use the "Hello wrold!" forever. "To demonstrate it."

First open our Notepad into our Java code, and save it as a. java suffix, and then we will compile with the command, with the following code:

1  Public class hello{2        Public Static void Main (String args[]) {3             System.out.println ("Hello world!" ); 4     }  5 }    

Here we must note:

              public class declaration must have the same class name and file name

Class name and file name can be different when class declaration

Give us a little bit more knowledge:

System.out.println (); Output with line wrapping

              System.out.print (); output with no line breaks

We write the code named ". Java" suffix, in the C-disk arbitrarily new folder put in, of course, everyone in which disk, do not build folder also line, I wrote here and put him in the C-drive test file;

Open our Run shortcut key (win+r), enter cmd into the console

We can see his path in "c:\users\administrator>" according to the above diagram, we will change the path to the folder where we saved the Java program, and then we compile the Java program, here we use the following command:

The CD enters the user's home directory;

CD ~ Enter the user's home directory;

CD-Returns the directory where the directory was before it entered;

Cd.. Return to the parent directory (if the current directory is "/", then "/"; "..." after execution) The meaning of the parent directory);

Cd.. /.. Return to the top level two directory; CD!$ Use the parameters of the previous command as CD parameters.

After entering our test folder, enter the following command

Javac (filename with suffix);

After input, he will generate a Java file in the test folder, the byte code suffix is class;

Finally, let's run this bytecode and enter the following command:

Java (class name without suffix)

a "Hello world!" is output in the console;

Daniel, please pass by;

DOS commands to compile Java programs

Related Article

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.