Java Basic program Design structure "1"

Source: Internet
Author: User

A simple Java application

  

Here's a simple Java application that sends only one message to the console window:

1  Public class Firstsample 2 {3      Public Static void Main (string[] args) 4     {5         System.out.println ("Hello world!" ); 6     }7 }

Although this program is simple, all Java applications have this structure, or it is worth taking some time to study. First, Java is case-sensitive. If there is a case-spelling error (for example, if main is spelled as Main), the program will not run.

The class name follows the keyword class. The rules for defining class names in Java are very loose. The name must begin with a letter and can be followed by any combination of letters and numbers. The length is basically unlimited. However, you cannot use a Java reserved word (for example, public or Class) as the class name.

  As you can see from the class name firstsample, the standard naming convention is that the class name is a noun that begins with an uppercase letter . If a name consists of more than one word, the first letter of each word should be capitalized (this is called the Hump naming method in which uppercase letters are used in the middle of a word). In its own case, it should be written as CamelCase).

  Note: Java for size is very important, a slight error will cause a bug, remember.

  

  You need to be aware of the parentheses {}in the source code. In Java, like in C + +, curly braces are used to separate parts of the program (often called blocks ). The code for any method in Java starts with "{" and ends with "}".

Next, take a look at this piece of code:  

{      System.out.println ("Hello world!");}

  A pair of curly braces indicates the beginning and end of the method body , and in this method contains only one statement. Like most programming languages, Java statements can be viewed as sentences in this language. In Java, each sentence must end with a semicolon. It is particularly necessary to note that carriage return is not the end flag of a statement, so a statement can be written on more than one line if needed.

Java Basic program Design structure "1"

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.