" Preface "
Java syntax first from the basic grammar, the Java language is composed of classes and objects , its objects and classes are composed of methods and variables , and methods, but also contains the statement and An expression .
" First Java program "
Public class hellowolrd { /** * First Java program * /public Static void main (string[] args) { // print Hello World System.out.println ("Hello World");} }
Say save, compile, run this program
- Save this code with Notepad, save the file name to Hellowolrd.java (remember to display the file suffix name)
2. Open the DOS window to find your saved location (e.g. my location is D:\HelloWorld)
3. Switch the drive letter to your file storage directory
4. Enter Javac Helloworld.java carriage return, at this time HelloWorld folder should have more than one Helloworld.class file, this compiles this code
5. Re-enter Java HelloWorld print out Hello World
" basic Syntax "
1. Case -sensitive: case sensitivity, such as HelloWorld and HelloWorld are different
2. class name : The first letter of Java class name must be uppercase, and the class name like Usernamemanage, the first letter of each word should be capitalized, commonly known as "Hump name Law" in the big hump nomenclature (i.e.: Pascal named method)
3. method name : One word is lowercase for example: User, multiple words first lowercase, starting with the second word, each word capitalized for example: usernamemanage (Small hump nomenclature)
4. keywords : All lowercase, for example: public
5. Constants : All caps for example: PI
6. variables : Rules are named as methods
7. Package : All lowercase
"Java identifiers"
All components of Java require a name. Class names, variable names, and method names are called identifiers.
1. Use only letters, numbers, underscores, and dollar characters.
2. You can only start with a letter, underscore, and dollar symbol. That is, you cannot start with a number.
3. Strictly case-sensitive, no length limit. It is not recommended to be too long.
4. Should have a specific meaning, the keyword cannot be used as an identifier.
"java modifier"
Java can use modifiers to decorate methods and properties in a class. There are two main types of modifiers:
- Access control modifiers: default, public, protected, private
- Non-access control modifiers: final, abstract, STRICTFP
"java delimiter"
- With: spaces, parentheses, curly braces, semicolons, and so on.
- Each statement ends with a semicolon, either one line or multiple lines. Blocks are multiple statements contained within {}, and blocks can be nested. Whitespace is inserted in the middle of the element of the code: one or more spaces, or one or more tab spaces to form multiple blank lines.
"Java Annotations"
Writing program comments is an essential part. To do the standard, explicit, for the future development brought convenience.
Public classHelloWorld {/** * @paramargs * First Java program * This is a document comment*/ Public Static voidMain (string[] args) {/** This is a multiline comment*/System.out.println ("Hello World"); //Print Hello World (This is a single-line comment)System.out.println ("Hello World"); } }
Not to be continued
Basic syntax of Java Basics (i.)