Hello World of Java implementation

Source: Internet
Author: User
Tags root directory

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 mainString args   //主方法,程序从这里开始执行
System.out.println″Hellothis 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: Hellothis is a simply test!

Hint: If the "Exception in Thread″main″java.lang.noclassdeffounderrorhelloworldapp" 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 ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.