java是面向对象语言,但不是纯面向对象语言,java中的8种基本类型却不是面向对象的。
8中基本类型的包装类:
Integer 【Integer中[-128-127]仍被当做基本类型处理】
Byte
Short
Long
Folat
Double 【Double类型不准确,不要用来比较大小】
Character
核心:一个long类型的数表示从1970年1月1日到现在的毫秒时间。
关键方法:new Date()
new Date(long time)
getTime()
4、DateFormat类
用来将字符串转换为时间,或将时间转换为字符串。(DateFormat抽象类,SimpleDateFormat为其的一个实现类)
关键方法:parse(String str):Date
format(Date date):String
一般用法:DateFormat df = new SimpleDateFormat("yyyy 年MM月dd日 HH:mm:ss");
Date date = new Date();
String str = df.format(date);
Date date1 = df.parse(str);
5、Calendar类
用来操作日期或日期计算。(Calendar为抽象类GregorianCalendar为其的一个实现类)
关键方法:set();
get();
一般用法: Calendar c = new GregorianCalendar();
c.set(year,month,day,hour,minute,second);
c.get(filed);
c.add(filed, int);
6、File类
用来操作文件和目录。
关键方法:new File("c:/test.txt");
new File (File,"test.txt");
new File ("c:");
一般用法:File file = new File("c:/test.txt");
if(file.exsits()){
try{
file.creatNewFile();
}catch(IOException e){
}
}