Beginner to write Java programs

Source: Internet
Author: User

First, write the Java program

Write a Java program, output a line of text message: "Hello World", select Editor Eclipse, open and then write the program

1  Public class hello{23publicstaticvoid  main (string[] args) { 4 System.out.println ("Hello World"); 5 }6 }
View Code

Line 1: Start declaring a class, the class name Hello,class is a java keyword, used to define the class, public is the access description

Line 3: A method that a Java application must contain, called an ingress method: The program must be run from here to execute, in the form of:

public static void Main (string[] args) or

static public void Main (string[] args)

In the above statement, only the name of the args and the string array can be modified.

Static indicates that the method can be loaded directly to run.

Void is a method return type, and each method must have a return type (in addition to the constructor method).

Main is the name of the method and is the method by which the program's entry is invoked.

String[] is a parameter of a method and must be of type string array.

Line 2, 4: blank line, used to increase the readability of the program.

Line 5:system.out.println ("Hello World");

is the output string, the string in double quotes is output in the console.

Line 6: "}" indicates the end of the method

Line 7: Indicates the end of the class

After writing, save the Hello.java file name to the specified directory.

Second, configure the environment and compile

Using the CMD and CD commands in the console to compile the file Hello.java that you just saved, you will generate a. class file that corresponds to the class name: Hello.class

You can output the text message "Hello World" by running the file hello.class you just generated using the Javac command in the console.

Note: When you run, you cannot add the file extension. class

class { public static void main (string[] args) { System.out.println ("Hello World"); } }

---restore content ends---

---restore content ends---

Beginner to write Java programs

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.