Java Foundation Review (1)

1. Java basic data types

Java language provides eight basic types The six numeric types (four integer, two floating point) A character type, there is a boolean

byte :( byte) bytedata type is an 8-bit signed integer in two's complement code representation;
minimum value is-128 (-2 ^ 7);
the maximum value is127 (2 ^ 7-1);
the default value is0;
bytetype used in a large array of space-saving, instead of the main integer, because thebyteonly the space occupied by variableintquarter type;
examples:bytea = 100,byteB = -50.

short :( short integer, 16-bit) Shortdata type is a 16-bit signed integer in two's complement representation of
the minimum value is-32768 (-2 ^ 15);
the maximum value is32767 (2 ^ 15--1) ;
Short data types, likebyteas save space. A short int type variables are occupied by one half space;
the default value is0;
example:shortS = 1000,shortR & lt = -20000.

int :( integer, 32-bit) int data type is 32-bit, signed integer two's complement representation; 
minimum value is -2,147,483,648 (-2 ^ 31 ); 
the maximum value is 2,147,483,647 (2 ^ 31--1 ) ; 
general default integer variable int type; 
the default value is 0 ; 
example: int A = 100000, int B = -200 000 .

long :( long integer, 64-bit) Long data type is a 64- bit signed integer in two's complement representation; 
minimum is -9,223,372,036,854,775,808 (-2 ^ 63 ); 
the maximum value is 9,223,372,036,854,775,807 (2 ^ 63-1 ); 
this type is mainly used in the system requires a relatively large integer; 
the default value is 0L ; 
examples: Long a = 100000L, B = Long -200000L .
"L" Theoretically case insensitive, but if written as "l" easy and the number "1" is confusing, is not easy to differentiate. So the best capitalized.

float :( single precision floating point, 32-bit) a float data type is single-precision, 32-bit, IEEE 754 compliant floating point standard;
 a float can save memory space when storing large floating groups; 
the default value is 0.0f ; 
floating-point not used to represent the exact value, such as currency; 
example: a float F1 = 234.5f .

Double :( double precision floating point, 64-bit)
double data type is a double-precision 64- bit IEEE 754 compliant floating point standard; 
default type floating point type double; 
double type represents the exact value can not be the same, such as currency; 
the default value is 0.0d ; 
examples: double D1 = 123.4 .

boolean :( Boolean) 
Boolean data type represents one bit of information; 
only two values: to true and to false ; 
these types are only recorded as a flag to true / to false case; 
the default value is to false ; 
examples: Boolean One = to true .

char :( char) 
char type is a single 16 -bit Unicode characters; 
the minimum value is \ u0000 (that is, 0); 
the maximum value is \ uFFFF (that is, 65, 535 );
 char data type can be stored any character; 
example : char Letter = 'A' ;.

image

Automatic type conversion

Integer, real (constant), the mixing operation may be character data. In operation, to different types of data into the same type, then operation.

Transition from junior to senior.

低  ------------------------------------>byte,short,char—> int —> long—> float —> double

Data type conversion must satisfy the following rules:

  • 1. boolean type can not be cast.

  • 2. The object types can not convert into unrelated objects classes.

  • 3. must be cast at converting a large capacity type of a small capacity type.

  • 4. The conversion process may result in overflow or loss of accuracy.

Automatic type conversion
Data type bits must be met before the conversion to the converted data types below,

For example: short data type is 16 bits, can be automatically converted to type int 32 bits, the number of bits of the same data type as the float 32, can be automatically converted to the 64-bit double type.

Cast
  • 1. that converting data types must be compatible.

  • 2. Format: after (type) value type is the type of data to be cast

Implicitly cast
  • 1. The default integer type is int.

  • 2. float there is no such case, since it is necessary to keep after the number F or f in the definition of type float.

to be continued……

Guess you like

Origin www.cnblogs.com/xumBlog/p/11747999.html