工作日志4

来源:互联网 发布:台式电脑连接不上网络 编辑:程序博客网 时间:2024/05/22 16:44

今天学习了java的一些常用类,包装类、自动拆箱和装箱、Date类的使用、File类的使用、异常机制

以下是部分测试代码

package testDate;


import java.util.Date;


public class Test01 {
public static void main(String[] args){
Date d=new Date();//括号里没有参数代表当前时刻;
//long  m=new Date();
long t= System.currentTimeMillis();
System.out.println(t);
Date d2=new Date(1000);
System.out.println(d2);
}


}

package testDate;


import java.io.File;
import java.io.IOException;


public class TestFile {
public static void main(String[] args){
File f=new File("D:/微云/Bin/Common.dll");
File d=new File("D:/微云/Bin");
File m=new File(d,"DiskFile.dll");
File p=new File(d,"hello.java");
File f5=new File("D:/微云/cc");
File f6=new File("D:/微云/aa/bb/cc");
f5.mkdir();//创建目录;
f6.mkdirs();
try {
p.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
p.delete();
if(f.isFile()){
System.out.println("f是一个文件");
}
if(d.isDirectory()){
System.out.println("d是一个目录");
}
if(m.isFile()){
System.out.println("m是一个文件");
}
long t= f.lastModified();//最后修改时间;
System.out.println(t);
}



}

package com.Hsoft.wrappedclass1;
/*
 * 测试包装类的基本用法*/


public class Test01 {
public static void main(String[] args){
Integer i=new Integer(1000);//整形数据的包装类
double j=new Double(-125.34);
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE);//用i和integer都一样;
System.out.println(Integer.toHexString(i));
//Integer m=Integer.parseInt("AAA");//?
//Integer m=new Integer("AAA");//?
System.out.println();
//System.out.println(m);


}


}

package com.Hsoft.wrappedclass1;
/*
测试自动装箱和自动拆箱*/


public class Test02 {
public static void main(String[] args){
//Integer i=new Integer(1000);//1
Integer j=1000;//jdk5.0以后可以自动装箱,把代码改成1
Integer m=2000;
System.out.println(m);
int c=new Integer(2000);//按照正常的语法应该是报错的,
//编译器会自动拆箱把程序改成 int c=new Integer(1000).intValue;
int p=m;//m.intValue
System.out.println(p);
System.out.println(c);


Integer a=1234;
Integer b=1234;
System.out.println(a==b);
System.out.println(b.equals(a));
System.out.println("################");
Integer d3=-120;//[-128,127]之间的数仍然会当做基本数据类型来处理;
Integer d4=100;

System.out.println(d3==d4);




}

}


0 0
原创粉丝点击