Topic
Create a "Hello, World" program, compile it with Javac, and then run it in Java.
Program
1 Public class ex2_2 {2 Public Static void Main (string[] args) {3 System.out.println ("Hello, World"); 4 }5 }
Compiling and running
Win+r Run cmd
D: Change to D drive, CD (space) file path, arrival program Ex2_2.java Directory
Format of the Javac command: javac-d destdir srcfile (Destdir:java bytecode storage path Srcfile:.java source file location)-D: Used to specify the path of the class file after compilation, if omitted, it is stored in the default path, the current directory is available "." Instead, such as javac-d. Srcfile Enter HERE
1 javac-d. Ex2_2.java
Or
javac-d D:\eclipse-workspace\HW\src D:\eclipse-workspace\HW\src\Ex2_2.java
Generates a. class file. Run it again in Java.
Format of the Java command: Java srcfile
Enter HERE
1 Java ex2_2
Get!
[Java] Thinking in Java exercise 2.2