int and Integer The difference between

1,Integer yes int Packaging class of ,int then is java A basic data type of  
2,Integer Variables must be instantiated before they can be used , and int Variable not required  
3,Integer Is actually a reference to an object , When new One Integer Time , It's actually generating a pointer to this object ; and int Data value is stored directly  
4,Integer The default value for is null,int The default value for is 0

extend : 
about Integer and int Comparison of  

1, because Integer A variable is actually a Integer References to objects , So the two passed new Generated Integer Variables are never equal ( because new 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 Variables and int When comparing variables , As long as the values of two variables are equal , Then the result is true( Because of packaging Integer And basic data types int When comparing ,java Will automatically unpack as int, And then compare them , It's actually two int Comparison of variables )
Integer i = new Integer(100);
int j = 100;
System.out.print(i == j); //true

3, wrong new Generated Integer Variables and new
Integer() When the generated variables are compared , The result is false.( Because it's not new Generated Integer Variable points to java Objects in constant pool , and new
Integer() Generated variables point to new objects 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 non new Generated Integer object , When comparing , If the values of two variables are in the interval -128 reach 127 between , The comparison result is true, If the values of two variables are not in this range , The comparison result is false
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 section 4 Reason for : 
java Compiling Integer i = 100 ; Time , Can translate into Integer i = Integer.valueOf(100);, and java
API Middle right Integer Of type valueOf 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 reach 127 Number between , Will cache ,Integer i = 127 Time , Will 127 Cache , Write next time Integer j =
127 Time , It will be taken directly from the cache , It won't new 了

If there's something wrong , Please correct .

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>