First, Java basic format
public class demo1{//class name to be the same as the file name
public static void Main (string[] args) {//wrap each line, four spaces indent
System.out.println ("Hello World"); Output Hello World
End of statement ends with a semicolon
}
}
II. Basic data types
Integral type:
1.byte: Between byte-type 8-bit -128~127.
2.short: Short integer 16-bit -32768~32767.
3.int: Integer 32-bit.
4.long: Long integer 64 bits//end preferably plus l
Floating point type:
1.float: Single precision 32 bits//end preferably plus f.
2.double:64 bit double precision.
Character type:
Char: Character type//' single quotation mark contains example: char a = ' a ';
Boolean type:
Boolean: The Boolean value is: True/false.
Three, implicit conversion (from small to large conversion)
Byte,short,char-->int-->long-->float-->double
Example: int a = 10;
Long B = A;
B is implicitly converted to a long type.
Iv. Casting (conversion from large to small)
Format: (cast type) variable or value.
Note: The use of casts is generally not recommended.
Example: int a = 10;
byte B = (byte) A;
Five, type compatible
Char is only compatible with shaping
Example: char a = "a";
int b = A;
B-->65
Vi. operators
1. Arithmetic operators
+ +,--, +,-, *,/,%
2. Relational operators
, <,! =, = =, >=, <=
3. Logical operators
&&, &, | |, |,!
&&, | | Differences with &, |
&&, &--> When the result of the first expression determines the overall result, it is not executed at a later time.
&, | --regardless of whether the first expression is true/false, the last expression is executed.
Example: int a = 1;
int b = 2;
int c = 3;
int D;
D = b > A | | b > C;
Since B > A was established, B > C was not executed.
Java Basics under Chapter I (Java format, base type, operator)