Chapter III identifiers, keywords, and data types
1. Java Identifiers and Keywords: in programming, a notation is usually used to identify variables, constants, methods, and classes, which are called identifiers . The Java language itself uses some identifiers, called Java keywords, that users should avoid using when naming identifiers, which would otherwise prevent the program from compiling.
The keywords in Java are as follows:
null void
abstract |
abstract |
assert |
assert |
boolean |
Boolean |
break |
interrupt |
byte |
|
catch |
capture |
char |
character |
class |
|
continue |
continue |
default |
default |
do |
do |
|
dual precision |
else |
otherwise |
enum |
enumeration |
extends |
inherit |
< Span style= "font-size:14px" >false |
false |
final |
final |
finally |
final |
float |
single precision floating point |
for |
when ... Time |
if |
|
implements |
implement |
import |
introduce |
instanceof |
|
int |
int |
interface |
interface |
long |
long |
native |
local |
new |
new | TD valign= "Center" align= "middle" >
empty |
package |
package |
private |
private |
protected |
protected |
public |
public |
return |
return |
short |
short integer |
static |
static |
STRICTFP |
precision floating point |
super |
super |
switch |
convert |
synchronized |
sync |
this |
this |
throw |
throw |
throws |
throw |
transient |
temporary |
true |
true |
try |
try | TD valign= "Center" align= "middle" >
empty |
volatile |
variable |
while |
when ... Time |
byvalue |
by value |
case |
case |
const |
constant |
future |
future |
generic |
|
goto |
jump to |
inner |
internal |
Outer
|
External |
operator |
Operator |
Rest |
Remainder |
Var
|
Variable |
|
|
|
|
The red part of the table above is reserved in Java but is temporarily unused, called a reserved word, and the user cannot use it as an identifier.
2. Naming rules for Java identifiers
(1) identifiers consist of letters, numbers, underscores (_), Dollar signs ($), and no length limitation;
(2) The first letter of the identifier must be a letter, an underscore (_), or a dollar sign ($);
(3) Letters in identifiers are case-sensitive , for example, dog and dog are two different identifiers;
(4) Constants are usually named in uppercase letters in English, and variables are usually named in lowercase English words. If a variable consists of multiple words, the first word is lowercase, the second word is capitalized, such as hotdog;
(5) The class identifier usually begins with an uppercase English letter;
(6) You cannot use Java keywords, reserved words as custom identifiers.
3. Java data type:Java data types are divided into simple data types and composite data types.
(1) Simple data type: numeric type (integer (Byte, short, int, long), float (float, double)),
Character type (char), Boolean type (Boolean)
Data type |
Key words |
The number of occupied positions |
Default value |
Range of values |
BYTE type |
Byte |
8 |
0 |
-2 of 7 power to 7 power-1 ( -128~127) |
Short-integer |
Short |
16 |
0 |
-2 of 15 power to 15 power-1 ( -32768~32767) |
Integral type |
Int |
32 |
0 |
-2 of 31 power to 31 power-1 ( -2147483648~2147483647) |
long |
long |
64 |
0 |
-2 63 Power 63 Power-1 |
< Span style= "font-size:14px" > single-precision |
float |
32 |
0.0 |
&NBSP; |
Double precision |
Double |
64 |
0.0 |
|
Character type
|
Char |
16 |
' \u0000 ' |
' \u0000 ' ~ ' \uffff ' |
Boolean type
|
Boolean |
8 |
False |
True, False |
Explanatory notes:
A. Different types of data, which occupy a different memory space.
B. Different types of data that can perform different operations. such as integer and floating-point data can be arithmetic operations, and Boolean data is not.
C.byte, short, int, long are all used to represent integers, except that the range of values is different. There are three representations of integer data: decimal notation (consisting of positive, negative, and number 0, the number part cannot start with 0 ), octal representation (consisting of positive, negative, and number 0, the number part starts with 0 ), hexadecimal representation (by positive, negative sign, number 0, letter a~f or a~f (representing a value of~15), the number of parts beginning with 0 x or 0x ) The long integer data must be followed by an uppercase "L" or a lowercase "l" after the value.
Both D.float and double represent floating-point data, except that the range and precision of the values are different. The double type has a greater range of values and higher precision. floating-point data can be represented in two ways: decimal notation (e.g. 4.0,5.32), scientific notation (after decimal notation with "E" or "E" and exponential parts, note: "E" or "E" must be preceded by a number, the exponent part can be negative , but it must be an integer. e.g. 4.5E-5)
E. Character types are used to represent symbols in the Unicode character set, such as control characters, letters, numbers, and Chinese characters. The Unicode character set uses hexadecimal numbers to denote a character, such as ' \u0061 ' for lowercase letter A. ordinary character notation is a character enclosed in single quotation marks, and case-sensitive, such as ' a ' and ' a ' are two characters, while ' VA ' is illegal. The escape character notation format is ' \ character ', which is used primarily to denote characters that cannot be displayed, such as carriage returns, newline characters, tabs, and so on.
F. The Boolean type has only "true" and "false" values of two. It is not possible to represent true and False in Java with 1 and%, so Boolean variables cannot participate in various mathematical operations.
priority for simple data types: (Byte, short, char) →int→long→float→double
Mutual conversion of data types: low priority → high priority (auto-conversion) priority High → low priority (CAST)
For example int x=10;float y; Y=x; Automatic conversion
float X=20.5f;int y; y= (int) x; Forced conversions
(2) composite data type: The composite data types in Java include classes (class), interfaces (interface), and arrays.
Java Learning notes-chapter III identifiers, keywords, and data types