primitive type: 基本类型,像int、double就是。
wrapped type:包装类型,int—>Integer,double—>Decimal
基本类型跟就是不可实例化的,可以直接初始化、赋值、运算。不可调用方法,不可放入容器(要求必须是类实例才行)。
int i=10;
i++;
包装类型就是把基本类型变成一个类实例,一定要new才产生,可以调用方法,可以放入容器。
int tt=100;
tt++;
Integer kk=new Integer(tt); //tt的包装类实例
System.out.println(kk.intValue()); //还是101
HashMap m=new HashMap();
m.put("abc",kk);
String是特殊的,可以像基本类型这样用,但其实它是类实例来的,可以调用它的方法,也可以放入到容器里面。JVM对String作了特殊处理。
String s="123456";
System.out.println(s.substring(0,1));
HashMap m=new HashMap();
m.put("abc",s);
The following chart summarizes the default values for the above data types in Java.
Data Type | Default Value (for fields) |
byte | 0 |
short | 0 |
int | 0 |
long | 0L |
float | 0.0f |
double | 0.0d |
char | '/u0000' |
String (or any object) | null |
boolean | false |
参考:
1,http://zhidao.baidu.com/question/73625171.html