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