<title>Experience the Java programming process</title> Experience the Java programming process
class Test
{
public static void main(String [] args)
{
System.out.println("My first Java program");
}
}
Brief description:
- Java programs must exist in the form of classes (Class) , a class to be able to be started directly by the interpreter, this class must have the main function, the Java Virtual Runtime first call the main function in this class, The main function is written in fixed and must be
public static void main(String [] args)
- If you want your program to print a string of character information (including one character) on the screen, you can use a
System.out.println("填写要打印的若干字符") statement, or a System.out.print("填写要打印的若干字符") statement. The former prints a newline character (\ n) after the printed content, and your window cursor position moves to the beginning of the next line in the print line. The latter only prints the string without increasing the line break. println()equalsprint("\n")
- If you do not use the public modifier before class, the name of the source file can be any valid name, and the class name with the public modifier must be the same as the source file name, as in the first line of the above program, change to the following form. The source file name must be Test.java, but the same class as the source file name does not necessarily have the public modifier
publicclass Test
Enter the directory where the Test.java source file is located in the terminal and run Javac Test.java. After the command executes, you can see that the directory has more than one Test.class file, which is the compiled Java bytecode file.
We then run the Java Test command, which is typed on the screen
This way, we compile the process of running the first Java program, even if it is done.
Note : The above is run with Java Test, not Java Test.class. Do not take the. class extension at run time, if the source file name is Xxx.java, there are multiple class definitions in the file, the compiled. class file has multiple, can be started directly with the Java command to run only the class containing the main function, The parameter followed by the Java command is the class name, not the file name, although the file name is Xxx.java, but is not in the form of Java XXX to run, the key is to see the class name.
For Java test commands, Java is a command from a system such as Linux, and test is a parameter to this command. From the Java side, the Java command launches a virtual machine, and test is a Java class that can run independently on the virtual machine, not the Test.class file.
The first Java program