Compilation and operation of a Java

Source: Internet
Author: User

--To know the reason why

1, when we are accustomed to the various IDE tools to write Java program code, do not know what they did for us! First write the source code with the simplest text tool (if the JDK is already installed and the environment variable is configured).

Cases:

1.1 Editing the source code

Create a new directory work in the C drive and create a new text file Helloworld.java such as

Helloworld.java content (source code):

 Public class HelloWorld {    publicstaticvoid  main (string[] args) {        System.out.println ("Hello world!" );    }}

1.2 Compiling into class file

Start Menu "Run" input cmd enter open Window console

Input cd/work switch to Java source directory

Enter Javac Helloworld.java Compile the source code, such as

There is no prompt to compile correctly, but the Helloworld.class file is generated in the work directory

1.3 Running Java programs

Once the compilation is complete, you can run the program! In the console you just entered Java HelloWorld Run (note: The Helloworld.class file is running, but "do not" enter the extension. Class), such as

When we use IDE tools to write source code, such as Eclipse. When we save the source code or create a Java file, eclipse will automatically compile the source into a class file (called Javac compilation). When we are running a single run, it is equivalent to calling the Java command to execute the program.

Extension 1: How to display file name extensions

How to display the file extension: Double-click Computer Tools Folder Options View tab remove the check box in front of "hide extensions of known types", such as (set, you can see the file extension!). such as TXT)

Time: January 12, 2016 20:22:49

Compilation and operation of a Java

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.