Java Basic Types

Source: Internet
Author: User

Java has eight basic types, Byte, char, short, int, long, float, double, and Boolean, respectively.

BYTE: Byte type, which occupies a byte of 8 bits. is a signed type, and the highest bit is the sign bit, which indicates a range of-128-127. The wrapper class is Byte.

Char: Character type, accounting for 2 bytes. Unsigned type, size range is 0-65535. Packing class for character

BYTE differs from char: char can be a table Chinese character, Byte is not available.

Short: Shorter integer, two bytes, size range -215-+215-1. The packing class is short.

The default integer type in Int:java, which is 4 bytes, and the size range is -231-+231-1. The wrapper class is an integer.

Long: The length of the shape, accounting for 8 bytes, the size range is -263-+263-1. The wrapper class is long.

float: Floating-point type (single precision), accounting for 4 bytes. The packing class is float.

Double: Dual type (double), 8 bytes, default floating-point type in Java. The wrapper class is double.

Boolean: Boolean, logical Judgment, two values: true, False. The wrapper class is a Boolean.

Usage Experience:

1. Forced type conversions are required to convert a type that represents a larger range or higher precision to a type with a smaller range or lower precision.

2.byte,char,short,int four basic types and their wrapper classes (which require java5.0/1.5 or later) can be used with switch statements .

3. when using the + 、-、 *,/, and% operators to perform operations on the base type , the two operands first consider whether one is of type double, if so, the other and the result will be converted to a double type. In this regard Float,long, two operands (including Byte, short, int, char) will be converted to the int type;

When you use the + =,-=, *=,/=,%=, and operators to perform operations on the base type, the value to the right of the operator is first cast to the same type as the left-hand value of the operator, and then the operation is performed with the same result as the left numeric type of the operator.

Java Basic 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.