Compilation and operation of Java programs
The Java program's compiler is Javac.exe, which is responsible for interpreting the execution of the compiled byte code.
The only thing we need to understand is that compiling is the compilation of the source Java file using the Javac program, running a class (. class file) Using the Java tool (the Windows platform is Java.exe), but the extension of the class file can be omitted and not written.
Note: The class file is the executable code of the Java program, called the class file. Javac compiles Java files into bytecode, which is the class file.
The use of Javac is as follows:
javac -g-O-debug-depend-nowarn-verbose-classpath path-nowrite-d dir
-D directory indicates the root directory of the class hierarchy. After compiling with javac-d dir Yourfile.java, the produced. class file can be stored in the DIR directory.
The-classpath path defines the path to the Javac search class. It overrides the setting of the default CLASSPATH environment variable.
For detailed parameter settings, you can use Javac-help to view Help. In general, you simply need to use the following command to compile and run the Java program.
Compiling: Javac Filename.java
Execution: Java yourclass
Programming walkthroughs
First move handwriting out of a program, in the running will be very fulfilling, so a lot of programming language books will lose no time to use a simple program to guide the reader. This is really a good idea, with a successful experience, I believe that the next study will be difficult to fall you.
Let's take a look at two simple Java programs:
Example one: Console (commonly known as DOS window) output Hello World, let you drink the first cup of coffee
//filename HelloworldApp.java
import java.io.//引入Java包
public class HelloworldApp //定义类名
public static void mainString args //主方法,程序从这里开始执行
System.out.println″Hellothis is a simply test ″ //输出字符串,字符串用引号括起来
//程序结束
How to compile and run a program? We introduced the JDK in the previous issue, and now that we've installed the JDK, we'll save the above code to a text file Helloworldapp.java.
Then run Javac Helloworldapp.java in the current directory
You may need to wait a few seconds for the compilation to complete. Now look, is there a helloworldapp.class in the catalogue?
OK, then run Java Helloworldapp, and now you'll see the output of the program: Hellothis is a simply test!
Hint: If the "Exception in Thread″main″java.lang.noclassdeffounderrorhelloworldapp" error occurs, You need to set your classpath path (you should set the environment variable first) and run "set classpath= in the Helloworldapp.class's current directory." command to set the CLASSPATH as the current directory. Then run Java test without error or refer to the Environment configuration section of the previous issue.
Now, the program is running. I'm telling you now, the "//" section begins with the comments of the Java program, with each statement ending with a semicolon ...