First, simple procedure
Public Classtestjava
{
public static void Main (String args[])
{
int num;
num = 3;
System.out.println (" This is the number " +num);
System.out.println (" I have the +num+ " book !) ");
}
}
1 , the name of the file is consistent with the name of the public class
2 , Java the comment of the language is //
3 public indicates that the class is a public class, if a class is declared as public java file with a maximum of one public java
4 publicstatic void main ( string args[] 4-9 line is called method (method) in java main () method (Main method)
5 , each of the independent Java The program must have a Main () Method to run, he's the starting point of the program.
6 , System.out refers to the standard output, behind println is by Print with the Line To print out the contents of the parentheses behind
two simple. Java Program Parsing
1 , Class ( class )
Java The program is made up of classes,
Public class Test// definition Public class Test
{
...
}
Public is a Java A keyword that refers to the way the class is accessed is public.
Attention:
since java programs consist of classes , at least one class is required in a complete Java program, and the file name of the original program is not arbitrarily named, and must be Public The name of the class, so in a separate primitive program, there can only be one Public class, but there can be a lot of Non-public class. If none of the classes in the program is public, the program name can be arbitrarily named.
2 , curly braces, segments and their bodies
{is the start tag for the class body,} The end identity of the class body
The end of each command must be a semicolon;
When a command's statement is more than a row, these statements must be included in a pair of curly braces to form a program segment ( segment ) or block ( Block )
3 , Notes
single-line comment //
Document Comments /* */
4 , Identifiers
Java The names of packages, classes, methods, parameters, and variables can be made up of arbitrary uppercase and lowercase letters, numbers, underscores, dollar signs, identifiers cannot start with numbers, and keywords that cannot be reserved
5 , Keywords
The keyword cannot be used as an identifier, and once used, the editor prompts for an error
6 , Variables
Variables can be used to hold data, and a variable must first be declared with the data type it is pre-saved.
1 ) Declaration of a variable
int to be Java the key word, represents an integer ( Integer ) declaration, separated by commas between each variable
2 ) The data type of the variable int long short float double char string
3 ) The name of the variable keywords cannot be the name of a variable, in the principle of easy to remember
7 , maintain good indentation habits, and facilitate the clarity of the program
This article is from the "Ops era" blog, please be sure to keep this source http://daomeng.blog.51cto.com/1655407/1796152
Java Self-study chapter