Java language basics
Java Basics
1. identifier and Data Type
1. Notes
// Comment a row
/* Comment out one or more rows */
/** Document annotation. The text in this interval is automatically saved in the HTML format document generated by the javadoc command */
1. 2. identifier definition rules
The identifier is a Character Sequence starting with letters, _, or $.
· A number cannot be the first character of an identifier.
· Identifiers cannot be keywords in java, but can be used as part of identifiers.
· The identifier is case sensitive and has no length restrictions.
1. 3. Keywords
Abstract, assert, boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum, extends, final, finally, float, for, goto, if, import, implements, instanceof, int, interface, long, native, new, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while, true, false, null.
1-4. Integer type
Byte: 8 bits-128 ~ 127
Short: 16-32768 ~ 32767
Int: 32-2.1 billion 10 million ~ 2.1 billion million
Long: 64-2 ^ 63 ~ 2 ^ 63-1
Char: 16-Bit 0 ~ 65535
1. 5. reference type variables
Declare a reference type variable before use. You must use the variable name to access a memory address 1 MyDate today; 2 today = new Date ();
2. Expressions and statements
2. 1. Variables
Local variables: before use, you must manually assign the initial value for initialization.
Class member variables: variables declared outside the method and belonging to the definition body of a class. Two types: first, the class variable declared with the static keyword (the variable always exists as long as the class to which it belongs ). Second, the instance variable (that is, there is no static keyword in the Declaration; as long as there is a reference pointing to the object to which the variable belongs, the variable will exist); the system automatically initializes.
Method Parameters
Exception Handling Parameters
2. 2. Operators and expressions
The operand of the modulo operator % can be a floating point number, for example, 9.5% 3 = 0.5;
Java does not have a power operator. You must use the pow () method in the Java. lang. Math class.
3. Program Flow Control
3. 1. switch statement: switch (integer expression)
The value of the integer expression in the switch statement must be of int-compatible type, that is, it can be byte, short, char, or int. Float or long type is not allowed. C1, c2, and c3 in each case clause are constants of the int or complex type.
4. Array
Use new to create an array. For example, for a declared String Array s, you can: s = new char [20];
Use s. length to access the variable s to obtain the length of the array;