(i) Integral type
1. In the Java language, the range of integer types is independent of the machine in which the program resides (in C language)
| Type |
Int |
Byte |
Short |
Long |
| Storage requirements |
4 bytes |
1 bytes |
2 bytes |
8 bytes |
Byte and short apply to underlying file processing or storage space considerations
2. In Java, if you want to represent an integer of type long, you need to append a suffix L or l, such as 30L
Octal and hexadecimal representations in 3.Java are the same as in the C language
(b) floating-point type
1.Java floating-point type
| Type |
Float |
4 bytes |
| Storage requirements |
Double |
8 bytes |
The effective scale of float is 6~7 bit, and the number of effective decimal digits for double is 15 bits
2. By default, the number of floats is double, if you want to represent a float type, you need to add a suffix f or f, such as 3.14F
3.Java scientific notation is the same as the C language
(c) Character type
Char in 1.Java is 2 bytes in Unicode encoding (C language with ASCII encoding)
The escape character in 2.Java is the same as the C language
(d) Boolean type
1.boolean type has only two values: true: true false: False
An integer or pointer in a 2.C language can act as a Boolean value, while Java does not support
Boolean types in Java cannot be converted to other data types
1. Division operator (/): If two operands are integers, the result is a quotient of division (integer division)
If one of the operands is a floating-point number, the result is a float (floating point division)
When the divisor is 0 o'clock, if the divisor is an integer, an exception will be generated, and if the divisor is a floating-point number, an infinity or Nan will be obtained.
2. Plus operator (+): Whenever one operand is a string, string concatenation is performed, and if the other operand is not a string, the system converts it to a string and then operates
3. Modulo operation (%): can be applied to integer type, floating-point number type (only for integer type data in C language)
4. Logical Operators:& and | or ^ xor! Non -
&& Simplification and | | Simplifies non-
The simplification operator does not perform a second operand operation when the result can be obtained from the first operand
5. Bitwise operators: cannot be used with Boolean, float, double, or compound data types, same as C language
There is no comma operator in 6.Java, but you can separate expressions with commas in the first and third parts of the for statement
V. Type conversion
1. In the C language, a variable with the same name as the outer nesting can be defined in the inner nesting, at which time the internal definition overrides the external definition and is not allowed in Java
2. In the case of multi-layered nesting, break and continue only act on the current layer of the loop
In Java, if you want to work on the outer loop, you can use tagged break and continue
Example: Outer:
while (J < 100) {
while (I < 20) {
if (i = = 5)
Break Outer;
}
}
If the break statement is not missing in the 3.switch statement, all statements starting with the matching case statement will be executed until the break statement is encountered or until the end of the switch is reached