Java character type

Source: Internet
Author: User

Short Short 2 bytes
int Integer 4 bytes
A long long 8 bytes
Float Float 4 bytes
Double Double 8 bytes
Byte byte 1 bytes
Char Character 2 bytes
Boolean Boolean

Java data types are divided into basic data types and reference data types.
Basic data types
Java contains 8 basic data types, namely:
Boolean, Byte, char, short, int, float, douboe, long
BYTE byte
Byte is the smallest data type in Java, which occupies 8 bits (8 bit) in memory, ranging from 128 to 127
Assignment: Byte I = 127
Short Quick-integer
The short type occupies 2 bytes in memory, ranging from 32768 to 32767
Assignment: Short i = 32767;

char character type
The char type occupies 2 bytes in memory. Represents a character, or you can use a value in the range of ASCII codes to assign a value to a variable of type char. Since the character does not have a negative range in memory, all values range from 0 to 65535
Assignment: char i = ' a '; or char i = 97;

int integral type
The int type occupies 4 bytes in memory. Values range from 2147483648 to 2147483647
Assignment: int i = 10;
Float single-precision floating-point type
The float type occupies 4 bytes in memory. Values range from -3.4E38 to 3.4E38
Assignment: Float i = 1.0f;
Long integer type
The long type occupies 8 bytes in memory. Values range from 9223372036854775808 to 9223372036854775807
Double dual precision floating point type
The double type occupies 8 bytes in memory. Values range from -1.7E308 to 1.7E308
Boolean Boolean type
A Boolean type has only two values: True and False.
Mutual conversions of basic data types
Transformation rules
All the numeric variables in Java are signed (plus or minus).
Java does not allow arbitrary conversions of types. Only numeric variables can be converted, but not arbitrarily.
A numeric variable with a decimal point is double by default. Defining a float type must be forced type cast.
A numeric variable with a small number of bytes is assigned to a type that has a larger number of bytes than it does without forcing a type conversion, which is an automatic transformation.
When a variable of type int is assigned to a char variable, the JVM finds the corresponding character in the ASCII code table with the int variable value, and assigns the value to the char type variable. and vice versa. But follow the 4th rule.
When initializing a simple data type, pay attention to the scope of the assignment, and a compilation error will occur if the value is exceeded.

Basic data type Default initial value
Type initial value
Boolean false
BYTE 0
Char 0
Short 0
int 0
float 0.0
Double 0.0
Long 0
Basic data type default initial value table

Reference data type
In Java, types that are not simple data types are reference data types.

Java character type

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.