JAVA second day basic data type

Source: Internet
Author: User

Data that can be allocated directly in the stack is the base data type. Reference data type: the reference to the data is in the stack, but his object is in the heap.

Basic data type, small size turn large, big turn to be smaller will lose precision

First Class: Logical Type Boolean

Type II: Text Char

Class III: Integer type (byte, short, int, Long) class fourth: float (float, double)

Integer has a byte short int long char, denoted by 8, 16, 32, 64, 16bits, respectively. In some places, char may not be included in an integer category, but essentially a char type is a subset of Int.

A byte short int long is signed, denoted by the 2 complement (s-complement). Char, in 16-bit notation, is unsigned and represents the UTF-16 encoding set.

A byte is represented by a 1-byte 8-bit, which is the smallest integer type. Mainly used to save memory space key. The byte type is particularly useful when manipulating data flows from networks, files, or other IO. The values range from: [-128, 127].

Short with - bit, the value range is: [-2^15, 2^15-1] . Short It's probably the least common type. Short when the type participates in the operation, the same is promoted to int or a higher type. Int bits, [-2^31, 2^31-1]. a signed binary complement represents an integer. Long   + bits , [-2^63, 2^63-1, The default value is 0L]. When you need to calculate a very large number, if int insufficient to accommodate size, can be used Long type. If Long is not enough, you can use BigInteger class. Char   [ 0, 65535], [0, 2^16-1], from ' \u0000 ' to the ' \uffff ' . Unsigned, the default value is ' \u0000 ' . Java Use Unicode Character sets represent characters, Unicode is the complete national   a character set that can represent all the characters in a human language. Unicode need to - bit width, so Java in the Char type is also used - bit representation. When Char when the subtraction operation is performed, it is also converted to int type, you must explicitly convert it back. float Use + bit indicates that the corresponding single-precision floating-point number, compared to the operating speed Double faster, takes up less memory, but becomes imprecise when the value is very large or very small. Can be used when the accuracy requirement is not high float type double64 to indicate that a floating pip face is assigned to a variable if it is not displayed after the literal value and F or F , the default is Double type. Java.lang.Math are used in the functions in Double type. if Double and the float cannot achieve the desired accuracy, you can use BigDecimal class. Boolean type has only two values true and the false , the default is false . Boolean and whether it is 0 There is no relationship, but you can convert according to the logic you want. Automatic Conversion   a larger type, such as int ) to save a smaller type, such as byte ), memory is always sufficient and does not require a cast. Forcing type conversions   If you want to turn the big into small, or in Short with the Char must be cast, also known as a narrowing conversion ( Narrowing Conversion ) , because the numeric value must be explicitly smaller to accommodate the target type.  

JAVA second day basic data 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.