Java learning a summary of data types

@ Java300 learning summary

A, Java basic data types are categorized as follows:

Integer variables: byte, short, int, long
float variable: float, double
char variables: char
Boolean variables: boolean, a value of true or false

Integer variable

    byte age = 127; //一个字节 2^8=256个数字
    short salary = 32000; //两个字节 2^15 约64000个
    int population = 2000000000; //4个字节 约正负21亿 42亿
    long globalPopulation = 7400000000L; // 8个字节 后面必须加L,表示是long类型的常量

Float variable

a float -> 4-byte
double type -> 8 bytes

It has a value of type float suffix F or f, no floating point value suffix F / f default type double.

Character variables

    char e = 'a';
    char b = '尚';
    char c = '\u0061';

Char two bytes, used to represent the character unicode encoding, comprising 65,536. The String class is a sequence of characters (char suquence)

Boolean variable

Occupy one in memory. Not replaced by 0,1.

----

Second, the type conversion

Type conversion between data, automatic type conversions can be divided into casts.

Automatic type conversion

Automatic type conversion, i.e., from the small-capacity automatic data type to data type capacity. Integer data conversion between the default type int, long type has appeared that is converted to type long. The default is double floating-point data types.

Red solid line represents no data loss automatic type conversions, while the dotted line indicates the conversion accuracy may be lost.

Cast

Syntax:

    (type)var

Guess you like

Origin www.cnblogs.com/gg12138/p/11440787.html