Java compilation will have different solutions according to different situations. Here we will introduce three situations of Java compilation.
If you want to develop Java and compile Java, you must have installed JDK. If not, please follow our Java Tutorial, which will have the answers you want.
Java compilation method:
First method:
In IDE For example, for Java programs written in eclipse and myexlipse, after executing the save operation shortcut key (ctrl s), eclipse and myeclipse will call javac to compile the program after saving. Although there is no change on the surface at this time, you can check the current In the bin directory of the project.
You will find that there is a compiled bytecode file in the bin directory of the current project. This is because of the convenience of the IDE tool, which has automatically helped you Compiled.
##Second type:
As an independent file and does not define Java environment variables. At this time, you will definitely not be able to compile directly in the command line window. You can only enter cmd in the text box in [Start] → [Run] or use the shortcut key (WIn R) to open the command line window. Then switch to the java bin directory through the command line command, and the source files in the folder where the Javac directory is located can compile the program. For example: javac D:\txt//HelloWorld.java The compiled class file will appear in the folder location.As an independent file and defines Java environment variables. At this time, you can compile and compile directly in the command line window. You can only enter cmd in the text box in [Start] → [Run]. Or use the shortcut key (WIn R) to open the command line window. Just enter the Javac target source file directly.
Example: Javac HelloWorld. java
#The compiled class file will appear in the folder location.
The above is the detailed content of How to compile Java. For more information, please follow other related articles on the PHP Chinese website!