A source file with a. java extension (source code), compiled by a compiler (compiler) into a bytecode file with a. class extension (similar to a machine instruction), and then executed with the JVM translated into the target machine code.
A virtual machine is not a physical machine, but a program that interprets Java bytecode.
A very important feature of the Java language is its independence from the platform . The use of Java virtual machines is the key to achieving this feature. General high-level languages if you want to run on a different platform, you need to compile at least a different target code. When the Java language virtual machine is introduced, the Java language does not need to be recompiled when it runs on different platforms. The Java language uses Java virtual machines to mask information related to specific platforms, allowing the Java language compiler to generate only Java The target code (bytecode) that runs on the virtual machine can be run unmodified on multiple platforms. Java When the virtual machine executes the bytecode, it interprets the bytecode as a machine instruction execution on the specific platform . This is why Java can be " compiled once and run everywhere ".
Installing and configuring the JDK
1. Install the JDK.
2. Configure environment variables: case insensitive. My Computer-Properties-Advanced system settings-environment variables
A) path:jdk the bin path to ensure that the Javac command can be run in any directory.
b) Classpath: A point that enables. class files in the Classpath directory to run in any directory.
c) Start-run-cmd-java-version
Java_home = C:\Program files\java\jdk1.8.0_91
Path =%java_home%\bin;%java_home%\jre\bin;
CLASSPATH =.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar
- The PATH environment variable is an executable file, such as an. exe file, where the executable file is located in the current path, and if it is not found, go to the path configured in the PATH environment variable to find
- The directory where the Java class's running files are recorded in the CLASSPATH environment variable
- Java code is usually written in a class.
- There can be more than one class in a. java file.
- A. java file can only have one public class .
- The public class name must be consistent with the file name.
- The entry of the main () program.
- Typically, main () needs to appear in the public's class.
- Java code is case-sensitive .
- Each line of Java code uses a semicolon to indicate the end.
- Only half-width punctuation can be used directly in a Java program.
- Java naming convention: the Class name (interface name) is capitalized and the others are lowercase. if the class name consists of multiple words, the first letter of each word is capitalized, and the other is lowercase (for example: User,userdao,userservice).
Categories of Java files
1..java File: Save source code, also known as source file, text file.
2..class file: Save bytecode, also known as class file, binary file.
Common Java Commands: Start-run-cmd
1.javac command: Check that the Java code is correct, and if the code is correct, generate the corresponding. class file according to the. java file.
Basic format: Javac file name (case insensitive). java
2.java command: Run the specified Java program
Basic format: Java class name (case-sensitive)
Java Foundation Compilation and execution