Java is case sensitive;
The main method must be declared public, and each application has one and only one main method;
General syntax used by java: object.method(parameters)
Java programs comments
- Single-Line Comment: //
- Multiline Comment: /* */
Java data type
8 primitive type:
- int
- short
- long
- byte
- float
- double
- char
- boolean
Java variable
Each variable has a type. After a variable is declared, the variable must be initialized with an assignment statement.
Java constant
Use the keyword final to indicate a constant.
Java enumeration
Includes a limited number of named values.
enum Size {SMALL, MEDIUM, LARGE, EXTRA_LARGE};
Java string
A java string is a sequence of Unicode characters.
- Substring String.substring() - Join * Allow connection with + * Use the join method - Empty string "" and null string * An empty string is a java object with a length of 0 and an empty content; * Null string, no object is currently associated with null;
Java array
An array is a data structure that stores a collection of values of the same type.
When declaring array variables, you need to specify the array type, such as int[] a;
Array initialization: a = new int[] {1,23,44,5,67};
Multidimensional arrays (array of arrays): int[][] a = {{1,2},{4,6}};