1 Calendar
class CalendarDemo{
public static void main(String
[] args
){
Calendar c
= Calendar
.getInstance();
c
.add(Calendar
.YEAR
,2);
printCal(c
);
}
public static void printCal(Calendar c
){
String
[] mons
= {"一月","二月","三月","四月",
"五月","六月","七月","八月",
"九月","十月","十一月","十二月"};
String
[] weeks
= {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
int index
= c
.get(Calendar
.MONTH
);
int index1
= c
.get(Calendar
.DAY_OF_WEEK
);
sop(c
.get(Calendar
.YEAR
)+"年");
sop(mons
[index
]);
sop(c
.get(Calendar
.DAY_OF_MONTH
)+"日");
sop(weeks
[index1
]);
}
public static void sop(Object obj
){
System
.out
.println(obj
);
}
}
2 Date
class DateDemo{
public static void main(String
[] args
){
Date d
= Date();
System
.out
.println(d
);
SimpleDateFormat sdf
= new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss");
String time
= sdf
.format(d
);
System
.out
.println(time
);
}
}
3 Math
class MathDemo{
public static void main(String
[] args
){
Random r
= new Random();
for(int x
=0;x
<10;x
++){
int d
= r
.nextInt(10)+1;
sop(d
);
}
}
public static void show(){
double d
= Math
.ceil(16.34);
sop(d
);
double d1
= Math
.floor(12.34);
sop(d1
);
long l
= Math
.round(12.54);
sop(l
);
double d2
= Math
.pow(2,3);
sop(d2
);
}
public static void sop(Object obj
){
System
.out
.println(obj
);
}
}
4 Runtime
Runtime对象 该类并没有提供构造函数 说明不可以new对象,那么会直接想到该类中的方法都是静态的 发现该类中还有非静态方法 说明该类肯定会提供方法获取本类对象,而且该方法是静态的,并返回类型是本类类型
由以上特点可以看出该类使用了单例设计模式完成。
该方法是 static Runtime getRuntime();
class RuntimeDemo{
public static void main(String
[] args
) throws Exception
{
Runtime r
= Runtime
.getRuntime();
r
.exec("c:\\winmine.exe");
}
}
5 System
System:类中的方法和属性都是静态的 out:标准输出,默认是控制台 in:标准输入,默认是键盘
class SystemDemo{
public static void main(String
[] args
){
Properties prop
= System
.getProperties();
System
.setProperty("mykey","myvalue");
String value
= System
.getProperties("os.name");
System
.out
.println(value
);
}
}