Home > Java > Javagetting Started > How to run .java files

How to run .java files

爱喝马黛茶的安东尼
Release: 2019-11-12 10:48:47
Original
36838 people have browsed it

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:

How to run .java files

How to run .java files

The second step is to press the "Windows R" key to open the run, enter "cmd" to open the command line window, as follows:

How to run .java files

How to run .java files

#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.

How to run .java files

(2) Enter cd Java to enter the Java folder.

How to run .java files

(3) Enter javac HelloWorld.java and press Enter.

How to run .java files

At this time, in the Java folder, a .class bytecode file with the same name as the .java file is generated.

How to run .java files

(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.

How to run .java files

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!

Related labels:
run
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template