int andInteger Difference

1,Integer yesint Packaging class,int then isjava A basic data type of 
2,Integer Variables must be instantiated before they can be used, andint Variable not required 
3,Integer Is actually a reference to an object, Whennew OneInteger Time, It's actually generating a pointer to this object; andint Data value is stored directly 
4,Integer The default value for isnull,int The default value for is0

extend: 
aboutInteger andint Comparison 

1, BecauseInteger A variable is actually aInteger References to objects, So the two passednew GeneratedInteger Variables are never equal( becausenew Two objects are generated, Its memory address is different).
Integer i = new Integer(100);
Integer j = new Integer(100);
System.out.print(i == j); //false


2,Integer Variable sumint When comparing variables, As long as the values of two variables are equal, The result istrue( Because of packagingInteger And basic data typesint Comparative time,java Will automatically unpack asint, And then compare them, It's actually twoint Comparison of variables)
Integer i = new Integer(100);
int j = 100;
System.out.print(i == j); //true

3, wrongnew GeneratedInteger Variable sumnew
Integer() When the generated variables are compared, The result isfalse.( Because notnew GeneratedInteger Variable points tojava Objects in constant pool, andnew
Integer() The generated variable points to the new object in the heap, They have different addresses in memory)
Integer i = new Integer(100);
Integer j = 100;
System.out.print(i == j); //false


4, For two nonnew GeneratedInteger object, When comparing, If the values of two variables are in the interval-128 reach127 Between, The comparison result istrue, If the values of two variables are not in this range, Then the comparison result isfalse
Integer i = 100;
Integer j = 100;
System.out.print(i == j); //true
Integer i = 128;
Integer j = 128;
System.out.print(i == j); //false

For the first4 Reasons for article: 
java CompileInteger i = 100 ; Time, Can translate intoInteger i = Integer.valueOf(100);, andjava
API Middle pairInteger TypevalueOf Is defined as follows:
public static Integer valueOf(int i){
assert IntegerCache.high >= 127;
if (i >= IntegerCache.low && i <= IntegerCache.high){
return IntegerCache.cache[i + (-IntegerCache.low)];
}
return new Integer(i);
}

java about-128 reach127 Number between, Will cache,Integer i = 127 Time, Will127 Caching, Write next time.Integer j =
127 Time, It will be taken directly from the cache, Would notnew 了

If there's something wrong, Please correct me..

Reference resources: 
http://blog.csdn.net/you23hai45/article/details/50734274
<http://blog.csdn.net/you23hai45/article/details/50734274> 
http://www.cnblogs.com/liuling/archive/2013/05/05/intAndInteger.html
<http://www.cnblogs.com/liuling/archive/2013/05/05/intAndInteger.html>