Java basic data types and their encapsulation class __java

Source: Internet
Author: User
Tags float double
Zi Yue: Learn while learning, joy.
There are eight basic data types in Java, respectively:
Boolean (Boolean) byte (byte) char (BYTE) short (integer) int (int) long (Long integer) float (floating-point type) double (double-precision floating-point type)
The corresponding package classes are:
Boolean Byte Character Short Integer Long Float Double
The memory space that the base data type corresponds to and the range of values it takes:
Value Range Resolution: We know that each memory space can only save two numbers 0 and 1, we take the byte example, byte occupies 1 byte memory space, namely 8 bit memory control, each memory space can have two kinds of changes, so there are 2 of 8 times change, that is to say, can have 256 kinds of changes, Positive and negative are half, so negative numbers have 128 numbers, positive numbers and 0 add up to 128, so the range of byte is -2^8 to 2^8-1, that is, 127 to 128.

Basic data types     occupy memory                   value range boolean     &N Bsp        1 bit                         True/fal SE byte                    8 bit                         -128-127 Char                   & Nbsp;16 bit                      /U0000-/UFFFF short     &N Bsp             16-                      -2^ (16-1)   to  2^ (16-1)-1 int                       32-bit &N Bsp                    -2^ (32-1)   to  2^ (32-1)-1 long       &nbsp            64 bit                       -2^ (64-1)   to  2^ (64-1)-1 float                    32 position double & nbsp              64 a                      
Differences and relationships between basic data types and encapsulation classes
1. Encapsulation classes need to involve instantiation and recycling of objects that are less efficient than basic data types.
2. The wrapper class can express the difference between an unassigned value and a value of 0, and the underlying data type cannot express an unassigned condition.
3. The encapsulation class implements a number of tool methods for manipulating basic data types, which are better than basic data types.
4. A reference to the object of the encapsulated class is placed inside the stack, and an instance of the object is placed inside the heap. The basic data type is a member variable when placed inside the heap, is a local variable when placed inside the stack (method stack).
Related Article

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.