I. Installation and configuration of the java development environment
1. Download JDK.
2. Install JDK. Note that there are no spaces in the installation path during installation. For example, the installation path is D: Javajdk1.6.0 _ 30.
3. Set environment variables. It can be a user variable or a system variable. The main settings include JAVA_HOME, PATH, and CLASSPATH. If not, create a file and edit it if not.
JAVA_HOME = D: Javajdk1.6.0 _ 30
JAVA_HOME indicates the JDK installation path, which contains lib, bin, jre, and other folders. Because the JAVA_HOME variable needs to be referenced, there should be no semicolon at the end of the value.
PATH = % JAVA_HOME % lib;
PATH allows the system to recognize JAVA commands in any PATH. It should be added at the beginning of the system variable PATH. Otherwise, the system may select the previous JDK at runtime. The semicolon (;) should be added to the beginning of the PATH.
CLASSPATH =.; % JAVA_HOME % libdt. jar; % JAVA_HOME % libtools. jar
CLASSPATH is a class loading path. Only in this path can JAVA be recognized. "." Indicates the current path. There is no semicolon at the end of the value.
4. Test
In the command line window, enter: java-version. If the published version information is displayed normally, the JDK installation is successful.
2. The first Hello World program
Use Notepad to write the following code and name the file Test. java:
The code is as follows: |
Copy code |
Class Test { Public static void main (String [] args) { System. out. println ("Hello World "); } } |
All JAVA code should end with. java.
JAVA is executed in two steps:
1. Compile the. java file to generate a. class file. The CLASS file is a bytecode file, and the program will eventually execute this bytecode file.
Go to the command line, switch to the directory where the Test. java file is located, enter the command javac Test. java, and press Enter. If the compilation is incorrect, an error message is displayed on the screen.
2. Execute.
Enter the command: java Test, and press enter to display the execution result "Hello World ". Note that only the class name is available after the java command.
III. Summary
JAVA is a cross-platform language. It does not actually execute binary code, but bytecode. JAVA is cross-platform. JVM (Java Virtual Machine (JAVA Virtual Machine) is not cross-platform (JVM is written in C language). The reason why JAVA is cross-platform is essentially that JVM is not cross-platform.