The first Java program HelloWorld

Source: Internet
Author: User

The code is as follows:

There can be only one common class in a file, and it is consistent with the file name, case note
public class helloworld{
Entrance to the program
public static void Main (String args[]) {
Output information to the console
System.out.println ("Welcome classmate of Java01 class");
}
}

is a single-line comment, there are three types of comments in Java, in addition to/* ... */and/** ... * * These are multiline comments, except that the latter can use the Javadoc command to generate a Java help document. Very much used in actual projects

When writing Java programs, it is common to note that all the code in Java must be placed in class, class is classes, the above program we write a class called HelloWorld, and a class want to execute must have a main method, the main method is the entrance of the program run, public static void Main (stringargs[]) in this sentence, except that the variable name of args can be defined by itself, other words cannot be changed or omitted.

In the main method we entered an output statement System.out.println ("Welcome to JAVA01 Class"), the purpose of this sentence is to the terminal is the display output a "Welcome Java01 class Classmate" words.

In the Java program writing, you need to pay attention to the variable name and keyword case. The Java language is sensitive to case, uppercase HelloWorld and lowercase HelloWorld are different two classes, remember. There are some specifications that you want to be a qualified Java programmer to know about Java programming, such as a class name in Java that requires an uppercase letter, and if the name consists of more than one word, all the words are capitalized in the first letter. The variable name and method name are lowercase, but if the name consists of multiple words, the first letter is lowercase and all the remaining words are capitalized

There is also a problem beginners need to note, the code indentation problem, you must be clear, your code is to show people, rather than to the machine to see, if the above code to change to

There can be only one common class in a file, and it is consistent with the file name, case note

public class helloworld{//program entry public static void Main (String args[]) {//Output information to console System.out.println ("Welcome to JAVA01 Class");}}

In this case, the compilation can be successful, but if other programmers to maintain your program, the format of the program will probably be scolded by people to die. So develop a good coding habit is a beginner must pay attention to.

Save the above program code to the Helloworld.java file, and then go to the CMD interface, switch to the directory where the Helloworld.java file is located, use Javachelloworld.java compile, if the compilation is successful, the directory will appear helloworld.class file , this is the so-called bytecode file, or called the intermediate code file, this class file is the cross-platform of the east, and then, using the Javahelloworld command execution can see the results, note the case.

The first Java program HelloWorld

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.