First, identifiers
Naming rules for identifiers in Java:
Consists of numbers, letters, underscores, and $ symbols; cannot start with a number; it cannot be a Java keyword.
Note: Do not use the $ named identifier. In practice, $ is used only in the source code generated automatically by the machine.
Second, the key word
1.Java All the keywords are lowercase;
2. Literal constants True, FALSE, and Null are not keywords, but they cannot be used as identifiers.
3. Keywords goto and const are keywords reserved by C + + and are not currently available in Java. If it appears in a Java program, the Java compiler can recognize them, but it generates an error message.
Third, the data type
Char two bytes (16bits) byte a byte (8bits) int four bytes
Conversions between basic data types:
1. When the type of the participating operation is inconsistent, low precision is automatically converted to high precision.
2. The minimum precision for addition operations in Java is the int type, so when the addition operation is not of the int type data, the data conversion is summed, and the variable type that is used to store the computed result should be noted, and if the precision of the variable type is <int, it cannot be compiled.
1 Packagetest;2 3 Public classTest1 {4 Public Static voidMain (String args[])5 {6 byteA=3;7 byteB=4;8 byteC;9c=a+b;Ten System.out.println (c); One A } -}
This will not compile because of a type mismatch:
Iv. variables
The memory unit that holds the data is called a variable in the program.
V. Operator operators
Logical operation: Only the True and False ( note and bit operation is distinguished: bit operation requires that the left and right sides of the operator is two values, the two logical operations are logical values )
(Logical AND) &, (logical OR) |: The value to the right of the operator is evaluated regardless of whether the operator left is true or false (whether the entire result of the operation can be judged)
(Logic and) &&, (logical OR) | | : If the result of the left side of the operator gets the final result, the right side of the equation is no longer calculated
Take the reverse (! ), (logical xor) ^
Package test; Public class test1 { publicstaticvoid main (String args[]) { int a=3,b=2; if (A>2 | | ++B>2) System.out.println ("a=" +a+ "\tb=" +b); A=3; b=2; if (a>2 | ++b>2) System.out.println ("a=" +a+ "\tb=" +b);} }
The result of the operation is
Vi. Other operations
New operator: It works by generating an instance of an object on the stack.
Object operator instanceof
Determines whether an object is an instance of a specified class or its subclasses:
Boolean b= myobject instanceof MyClass;
Vii. reading data from the keyboard
1. Scanner input=new Scanner (system.in); Input from console
2. Joptionpane.showinputdialog (system.in); //Enter from the dialog box
Java Programming Fundamentals review-------Chapter II