Today began to really go into the world of javase, this article introduces: Javase basic grammar, if you have the basis of C language, for this section of the content must feel very easy, programming languages are interlinked, but the C language belongs to the process programming, And the Java language is a process-oriented design thinking, I believe that the future development will certainly be oriented towards service orientation.
Nonsense not much to say, to begin today's summary:
1. Identifiers:
Mark identifier what? It is a naming convention defined by Java. Wherever you need to name yourself, you need to adhere to the Java identifier rules, which include: A, identifiers are composed of English letters, underscores (_), Dollar signs ($), and numbers, B, identifiers begin with English letters, underscores (_), Dollar signs ($); Identifiers are case sensitive and have no limit on length. The definition of a Java identifier should follow the principle of the known name and not be the same as the Java keyword. It should be noted that Goto and const are never used, but are also reserved as Java keywords.
2. Constants:
Constants in Java include: Integer Constants (1,2,43,131,...... ), the real constant (1,2,3,3.1,3.22,...... ), character-type constants (' A ', ' B ', ' Medium ', ' High ', ' 1 ', ' 2 ',...... ), logical constants (True,false), string constants ("abc", "Hello", "123",....... )。 Note the distinction between character-and string-type constants.
3. Variables:
Variables are the most basic storage units in a program, with elements such as variable names, action types, and scopes, in which variables in Java must be declared before they are used. Variables in Java are divided into: local variables and member variables, the variables defined inside the method body are local variables, scope is the method domain, inside the class, variables defined outside the method body, belong to the member variable, scope is the class domain. The local variable must be assigned first, and the member variable may not be assigned a value, and the system assigns the initial value to it.
4. Data type:
Data types in Java are divided into: basic data types and reference data types. The basic data types are divided into: numeric, character (char), Boolean (Boolean), Numeric: Integer type (byte, short, int, long) and floating-point type (float, double), reference data type: class, Interface (interface), arrays. Floating-point types default to double types.
For basic data type and C language basically consistent, but for Boolean type (Boolean) can only take true and false two value, cannot use 0 and not 0 instead, and C language, remember!
5. Conversion between basic data types:
Small-capacity types are automatically converted to large-capacity data types, and data types are sorted by capacity: Byte, short, char>>>int>>>long>>>float>>> Double Byte, short, char do not convert to each other, there are many data types mixed operation, the system first automatically convert the data to the largest type of capacity, and then the operation.
6. Operators:
The Java operators are the same as the C language, including: arithmetic operators (+ 、—、 *,/,%, + + 、——), relational operators (<, >, >=, <=, = =,! =), logical operators (&, |, &&, | | 、!、 ^), Bitwise operators (&, ^, |, ~, <<, >>, >>>), assignment operators (=), Extended assignment operators (+ =,-=, *=,/=), string join operators (+)
Precedence of the operator:
7, Trinocular Operators and statements: (shown in the form of a program)
Public classOperator {/** * @paramJava Statements*/ Public Static voidMain (string[] args) {byteby = 1; intA = 1; DoubleB = 1.0; floatc = 1.0f; Chard = ' a '; String e= "Helloword"; String Flag= 2>3? " Greater than ":" Less than ";//Three mesh operator//Conditional Judgment if(a==2) {System.out.println ("A=" +a); }Else{System.out.println ("A=" +a); } //Switch Statement Switch(a) { Case1: System.out.println ("A=" +a); Break; Case2: System.out.println ("A=" +a); Break; default: System.out.println ("A=" +a); Break; } //For Loop for(inti=0; i<5; i++) {System.out.println ("I=" +i); } //While Loop while(a<=5) {System.out.println ("A=" +a++); } //Do-while Cycle Do{System.out.println ("A=" +a--); } while(a>=0); }}
For the basic grammar of Javase simple summary Here, Java Basic grammar and C language, we can learn from learning.
Javase Basic Review Guide "II"