Differences between Java basic types and wrapper classes

Source: Internet
Author: User

int is the basic type, and the value is stored directly
An integer is a class that, when produced, points to this object with a reference to Java dividing 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 function's stack memory
And the actual object is in storage heap memory
That
int i = 5;//allocating space directly in the stack
Integer i = new Integr (5);//object is in heap memory, and I (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 a heap is much longer than allocating storage space from the stack, Java is slower than C when you need to put something in arraylist,hashmap, like int, Double this basic type is not put in, because the container is loaded with object, this is the need for these basic types of outer covering class. Each of the basic types in Java has a corresponding overlay class. The difference between int and Integer


Java offers two different types: reference type (or package type, Warpper) and original type (or built-in type, Primitive). int is the raw data type of Java, and integer is the wrapper class provided by Java for Int. Java provides a wrapper class for each primitive type.
Raw type Encapsulation class
Boolean Boolean
Char Character
BYTE byte
Short Short
int Integer
Long Long
float float
Double Double
The behavior of reference types and primitive types is completely different, and they have different semantics. Reference types and primitive types have different characteristics and usages, including: size and speed issues, which types of data structures are stored as the default values that are specified when reference types and primitive types are used as instance data for a class. The default value of an object reference instance variable is NULL, and the default value of the original type instance variable is related to their type.

from:http://community.csdn.net/expert/topic/3666/3666081.xml?temp=.9687921


int is the base type, (int) (Math.random () *100) is a number that can be added multiplication. Integer is a class, then the new Integer (temp) is an object, you can use the integer class method, for example, with Intvalue () can return the value of this int.

Differences between Java basic types and wrapper classes (RPM)

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.