Identifiers: Identifiers are words that we use in Java code.
In Java, we need to identify many elements in the code, including class names, methods, fields, variables, package names, and so on. The name we choose is called an identifier and must follow the following rules:
1. The identifier cannot be a keyword true, false, or null.
2. Identifiers can contain letters, numbers 0-9, underscores (-), or dollar signs ($).
3. The first letter of the identifier must be a letter, an underscore (-), or a dollar sign ($).
4. Identifiers are case-sensitive, but do not limit the length.
II. data types, variables, and constants
Java data types fall into two categories:
1. Basic types
Integer: Byte, short, int, long
Float type: float, double
Character type: Char
Boolean Type: Boolean
2. Reference types
Classes: Class
Interface: interface
Array
Declaration of variables: used to hold data of the specified type.
Syntax for variable declarations: data type + variable name; (variables can be assigned using the = symbol while declaring)
Considerations for variables:
1. Length: Different data types, different lengths in memory, error if data type exceeds range.
2. Initialize: The variable must be initialized when it is used and operation, otherwise it will error.
3. Type immutable: The variable defines the type, it cannot hold other types of data, otherwise it will error.
Variables of type 4.int do not use a float, double to define the type of the variable, although it does not error but not high efficiency.
Declaration of a constant: the final type variable = value;
Type conversions are divided into two types:
1. Implicit conversion: Low-level to advanced conversion, automatic conversion.
2. Cast: advanced to low-level conversion.
When performing an expression operation, the rule is automatically lifted:
1. All byte, short, and char types will be promoted to the int type.
2. If one of the operands is a long type, then the computer result is a long type.
3. If one of the operands is of type float, the result is a float type.
4. If one of the operands is of type double, then the computer result is a double type.
Java Basic syntax