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"