Home > Back-end >  Java data types
Java data types

Time:02-03


Java data type
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Development tools and key techniques: the eclipse and Java
Author: Huang Futao
Time to write:
feb 02, 2021Knowledge points list:
Note two default: in eclipse, the default input is an integer type int, input the number of decimal type double by default, if you are using to long data types, behind the Numbers to add L, if you are using to float type, need behind the decimal add F,

Java data types are divided into two types
1, the basic data type
Basic data types and three kinds of
1.0 digital type
Digital type is divided into two kinds:
(1) integer byte, short, int, long, accurate value)
(2) the float float, double (approximation)
2.0 operator types: char (a) without the sign bit, 0
3.0 the Boolean: the Boolean
2, reference data type (that is, the basic data types of wrapper classes) seems there is no difference, but the nature of the above, there is a difference between
The basic data types of reference types: remember two special, a wrapper class int Integer, another char wrapper class Character, the other is the first letter changed to uppercase,
Reference data types of features: 1.0 objects, arrays are reference data types,
2.0 all the default value of a reference type is null,
3.0 a reference variable can be used for reference and any compatible with the type,

Basic data types - & gt; Wrapper classes (reference data type)
Packing: basic data type is converted to the corresponding wrapper class types of process
Split open a case, the corresponding wrapper class type into the process of basic data type
Byte b2=12; Byte byte3=b2; - & gt; Directly to convert a reference type to basic data types, starting from the JDK1.5 support automatic packing and unpacking,
Wrapper classes: a, convenient we need object, later to the data type conversion of basic object, and offers many methods/tools,

Data type conversion: there is an implicit conversion and explicit conversion
Implicit transformation: from small range of automatic conversion to a wide range of, for example: byte b1=111; Long long1=b1 + 1; (this involves two implicit conversion, the first b1 first converted to type int, the second transform calculation result of type int to long)
Note:
1.0 the type char can be implicitly converted to range is greater than the type char data type; Long, for example, int, float, double, converted to print out, that is, the character of the character encoding, which means that if you want to get to a particular character encoding of the characters, you can use this method to give it a try,
2.0 converting from a float type double conversion results may appear approximation, but according to the standards, can't say precision loss, floating point number itself is not accurate,
Large range of explicit conversion: the transition to the range of small or is the conversion between wrapper class (integer can lead to memory leaks, and floating point Numbers are precision loss of memory, the above situation appears only in the case of beyond the scope of small)
Conversion methods: 1.0 casts
2.0 through the wrapper classes to convert
Plastic and String wrapper class conversion between
Int int2str=1000; Strings Str1=String. The valueOf (int2str); String class packaging used to own way the valueof the plastic can be converted to String wrapper classes, most other types of data are transformed the valueof the String used to own methods,

Digital type integer is converted to floating point precision is also likely to be lost, but between the integer transform is no accuracy is lost, including char character to integer range is bigger than char conversion precision is not lost when (char but inside it are deposited by plastic),
Floating-point and integer conversion between by abandoning the decimal, rather than the rounded,

Understanding the original code, radix-minus-one complement, complement (positive complement and radix-minus-one complement is in itself, which is the original code)
Computer memory operation with complement, cast in the memory is to remove the spare parts, in the computer, the first if it is 0, represents the positive, and it is the first if it is 1, represents the negative,
For example the int type cast to byte type int int1=128;
Computer 129 is converted to binary to decimal number 1000 0001; Then type int for 32-bit memory digits, binary number 0001 to 1000 in the previous patch 24, after the patch is 00000000 00000000 00000000 10000001,
00000000 00000000 00000000 10000001 the original code, radix-minus-one complement, complement (positive radix-minus-one complement and complement with the original code is the same)
If int129 cast to 129 byte type, because memory byte type digits for 8 bits, so at the time of casting will remove the spare parts, remove after 10000001 (complement), 10000001, the first is 1, so negative, because of negative complement is on the basis of its radix-minus-one complement + 1, so radix-minus-one complement for 10000000, negative radix-minus-one complement is the sign bit remains the same, the rest of the invert, the first is 1, so the negative; So its radix-minus-one complement of the original code 10000000 to 11111111, the first sign bit, 1 represents the negative, the rest of the seven binary number 1111111 is converted to a decimal is 127, so the final result is - 127,

Precision loss: in the computer, calculation of floating point Numbers may not calculate the accurate value, computer storage or in the form of binary computation, when you are calculating the floating-point other hexadecimal number will be converted to binary to calculate, so there will be a precision loss, cannot use floating-point number to calculate money,

For the scope of basic data types, if we have forgotten, can be used inside the wrapper class has defined some constants for printing can know the scope of basic data types,
Get the memory digits byte. Such as byte SIZE
Access to the maximum Byte. MAX_VALUE
To obtain the minimum Byte. MIN_VALUE
  • Related