Java basic types and wrapper classes

Source: Internet
Author: User

1. Basic Concepts

The unit of bytes: byte. Units in bits: bit,1byte=8bit

2,8 types of basic data

4 integers, 2 floating-point types, 1 character types used to represent Unicode-encoded character cells, and 1 Boolean types used to represent truth values.

Data type Floating-point size (number of bytes, 2 of several Parties) Range Default value Wrapper type
Byte (bytes) 8 -128-127 0 Byte
Shot (short integer type) 16 -32768-32768 0 Short
int (integral type) 32 -2147483648-2147483648 0 Integer
Long (integer) 64 -9233372036854477808-9233372036854477808 0 Long
Float (float type) 32 -3.40292347e+38-3.40292347e+38 0.0f Float
Double (dual precision) 64 -1.79769313486231570e+308-1.79769313486231570e+308 0.0d Double
char (character type) 16 ' \u0000-u\ffff ' ' \u0000 ' Character
Boolean (Boolean) 1 True/false False Boolean

3. Packing class

The wrapper class, even if the base type is an object type, contains the relevant properties for each basic data type, such as maximum, minimum, and related action methods.

4. Packaging class Conversion Relationship
Basic Type-wrapper class
Integer obj=new integer (10);
Wrapper class--Basic type
int Num=obj.intvalue ();
String-to-wrapper class
Integer obj=new integer ("100");
String--Basic type
int Num=integer.parseint ("-45.36");

5, automatic packaging/unpacking (autoboxing/unboxing)

The conversion of the base class to the wrapper class is the package and unpacking
Automatic unpacking/unpacking greatly facilitates the use of basic type data and their wrapper classes.
Automatic package: The basic type automatically turns into a wrapper class. (int >> Integer)
Automatic unpacking: Wrapper classes are automatically converted to basic types. (Integer >> int)

int is the basic type that stores values directly
An integer is an object class, and a reference is used to point to the object when new is an object
Java divides memory into two types: one is stack memory and the other is heap memory
Some basic types of variables and object reference variables defined in the function are allocated in the stack memory of the function, while the actual objects are in the storage heap memory
Like what
int i = 10; ----allocate space directly in the stack
Integer j = new Integr (5); ----object is in heap memory, and J (reference variable) is in stack memory
The memory allocated in the heap is managed by the automatic garbage collector of the Java Virtual machine. Because allocating space in the heap takes much longer than allocating storage space from the stack

Java basic types and wrapper classes

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.