Java (1)-How to compile a simple Java program

Source: Internet
Author: User

Java (1)-How to compile a simple Java program

Recently, I have been preparing to spend a long time writing some tutorials on Java from getting started to advanced to project development. I hope this will be helpful to my new Java students and will be integrated into Java learning more quickly.

The main content includes the basic knowledge of JavaSE and JavaEE, and how to use Java to write a simple software, a small game, a simple project, or some complex project practices.

I am not allowed to introduce Java knowledge in these articles, because these concepts and things have a complete set of tutorials on the Internet, and new beginners will find the concept cumbersome, therefore, my articles mainly aim to Understand Java and how to write some simple programs in Java language. Therefore, all the articles are code-oriented. If you want to learn more about Java, you need to read more information, in-depth understanding of concepts and principles.

  

Today, I will first learn how to build a Java program, install JDK and the compiler, and I will not go into further details. There are also many tutorials on the Internet, compilers such as Eclipse and IDEA have many options. The following uses eclipse as an example to create a simple Java program.

Start eclipse and go to the following homepage:

  

Create a New Project and select "File-New-Java Project ":

  

The following page is displayed, assuming the name is Test, and the rest are the default ones:

  

After you click Finish, the new project will appear in "Package Explorer" in the left column:

  

So how to write a Java program?

First, you need to create a package. You can click directly on the toolbar above, or right-click src under the Test directory to create a new package, as shown below:

  

Fill in the package name in the pop-up interface, such as hello:

  

Click Finish. An empty package named hello is added to the src directory:

  

Next, create a Class under the package for coding. Click on the toolbar above, or right-click the hello package to create a Class file, as shown below:

  

On the pop-up page, enter your class name, such as Hello, and check "public static void main (String [] args)" to automatically create a main method for you:

  

Click Finish to view the following interface, and then you can start to write the code:

  

Let's write a simple code first. We start with "Hello World" when learning a programming language. We can output a blog address and try the Code as follows:

 1 package hello; 2  3 public class Hello { 4  5     public static void main(String[] args) { 6         // TODO Auto-generated method stub 7         System.out.println("http://www.cnblogs.com/adamjwh/"); 8     } 9 10 }

Click Run, or right-click "Run As-Java Application ":

  

The following output is displayed on the Console:

  

This is a simple output statement. Is it very easy to get started with 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.