Home >Java >Javagetting Started >How to run .java files
The first step is, if there is a folder named Java in the e drive, and there is a pre-written .java program in the Java folder, as follows:
The second step is to press the "Windows R" key to open the run, enter "cmd" to open the command line window, as follows:
#The third step is to go to the folder where the HelloWorld.java file is located.
(1) The file is on drive E. First enter e: and press Enter.
(2) Enter cd Java to enter the Java folder.
(3) Enter javac HelloWorld.java and press Enter.
At this time, in the Java folder, a .class bytecode file with the same name as the .java file is generated.
(4) Enter java HelloWorld to run the Java virtual machine running program. The Java virtual machine first loads the compiled bytecode file (.class file) into the memory. This The process is called class loading, which is completed by the class loader. Then the virtual machine interprets and executes the Java class loaded into the memory, and you can see the running results.
Java programs are interpreted and executed by the virtual machine, not the operating system. The advantage of this is that it can achieve cross-platform performance, which means that the same program can be written for different operating systems, and only different versions of virtual machines need to be installed. This approach enables the Java language to "write once, run anywhere", effectively solving the problem of programming languages generating different machine codes when compiled on different operating systems, and greatly reducing the cost of program development and maintenance. .
But it is worth noting that Java programs can achieve cross-platform features through the Java virtual machine, but the Java virtual machine is not cross-platform. In other words, Java virtual machines on different operating systems are different.
Compilation and execution completed.
php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!
The above is the detailed content of How to run .java files. For more information, please follow other related articles on the PHP Chinese website!