javase-Basic data types

Source: Internet
Author: User

    • Some basics:
    1. Bytes and characters, bytes and bits, 1 bytes = 8 bits (bit) (highest bit is sign bit, 0 positive 1 negative) bit is the smallest unit in computer memory, in binary computer system, each bit can represent 0 or 1 digital signal. BPS is the abbreviation for bits per second. The transmission rate of general data and network communication is measured in bps. such as 56Kbps, 100.0Mbps, etc.
    2. A value of type float has either a suffix F or f, a floating-point number that does not have a suffix of type double, and, of course, a suffix D and d for floating-point numbers, a long integer type with a suffix of l or lowercase l, a prefix of 0X or 0x in hexadecimal, and a binary prefix of 0b or 0B
    3. Starting with Java7, you can underline numeric literals, such as 1 million, which can be represented as 1_000_000, and the compiler will remove these underscores at compile time.
    • Basic data type/reference data type
    1. Memory usage: The base data type is stored directly in the stack memory. The reference type is that the contents are stored in the heap memory, the address is stored in the stack memory, and the contents of the heap memory are found through the address of the stack memory when accessed.
    2. Variable assignment: The base data type is straight; The value is assigned to the variable. The reference type is, copy the address of the value to the new variable, and then find the content by the address.
    • Problem with the value of the pass

  

    • Basic data Types (4 classes 8 types): integer type (4), decimal type/floating point type (2), Boolean type (1), character type (1)

    integer type : Byte, short, int, long

Formulas for ranges and bytes:

Byte:1 bytes, 128-127, (supposedly-127-127, because 0 has +0 and 0 differences, so one more-0, and-0 is seen as the contribution of 128, Indians)

Short:2 bytes,-32768-32767

Int:4 bytes, 2147483648-2147483647 just over 2 billion.

Long:8 bytes, -2^63~2^63-1, probably 9*10^18 mass number can be solved by a string or a character array

decimal type : float, double

Float: Single-precision type, 4 bytes, approximately 6-7 bits of significant digits

-3.403e38~3.403e38

Double: dual type, 8 bytes, approximately 15 bits of valid digits

Note:

float a=1.3; This will be an error because the 1.3 default is double, high precision low precision will lose precision. The right should be float a=1.3f;float the seventh digit will produce rounding

Three special floating-point values used to indicate overflow and error conditions: Positive infinity (double.positive_infinity), negative infinity (double.negative_infinity), NaN (Double.NaN) And a constant of the corresponding float type. Where NaN is not a number and cannot be used to determine if a variable is ==nan, the correct use is Double.isnan (XXXX) to return a Boolean value

    Boolean type : True and False

    character type : Char, string

Char: Single character, 2 bytes, can hold Chinese characters; string: multiple characters (string is not a basic data type, but a reference data type)

    • Other:
    1. ASCII code for "A" is 97, ASCII code bit for "A", Unicode code for Kanji
    2. Cast:

Data types can be automatically converted from low-precision to high-precision, high-precision to low-precision requiring casts

int a = (int) 1.2;

int a = (int) 1.9; The final result is that a is 1, that is, regardless of the back, just intercept the previous integral part

Float a=1.2; Error, loss of precision, because the decimal in Java is the default double type

Float a =1.2f; That's right

Int a=3;

int b=a+3.4;//computer, calculate the a+3.4 and go to high precision, so get 6.4, but at this time can not deposit int type (subtraction will go to high precision)

3. Reference data types: arrays, classes, interfaces, enumerations

4. Uninitialized variables cannot be used directly, the compiler will error, the initialization and declaration of variables can be placed on the same line, that is, the declaration of assignment in the same sentence code, the use of the final indicator constant, once the value is assigned, it can not be changed, the customary constant is expressed in full capital, If you want a constant to be used by multiple methods of a class, you can add the static

javase-Basic data types

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.