Java的垃圾回收与析构源代码
类和对象
1 类的定义与使用
2 继承
3 重载
4 包与接口
5 Java的垃圾回收与析构
6 抽象类与内部类
7 基础类的使用
TestClassCalendar.java
import java.util.Calendar;
class TestClassCalendar{
public static void main(String args[]){
Calendar mycalendar1 = Calendar.getInstance();
System.out.println("今日日期: ");
System.out.print(mycalendar1.get(Calendar.YEAR) + "年");
System.out.print(mycalendar1.get(Calendar.MONTH) + "月");
System.out.println(mycalendar1.get(Calendar.DATE) + "日");
System.out.println("今日时间: ");
System.out.print(mycalendar1.get(Calendar.HOUR) + ":");
System.out.print(mycalendar1.get(Calendar.MINUTE) + ":");
System.out.println(mycalendar1.get(Calendar.SECOND));
System.out.println("将mycalendar1时间调整成为: ");
System.out.print(mycalendar1.get(Calendar.HOUR) + ":");
System.out.print(mycalendar1.get(Calendar.MINUTE) + ":");
System.out.println(mycalendar1.get(Calendar.SECOND));
代码太多了,需要完整代码联系QQ752018766
}
}TestClassDate.java
import java.util.Date;
public class TestClassDate{
public static void main(String[] args){
Date mydate1 = new Date();
System.out.println("今日日期为:" + mydate1);
long msec = mydate1.getTime();
System.out.println("现在距离1970年1月1日GMT的毫秒数为:" + msec);
Date mydate2 = new Date(106,1,32);
System.out.println("mydate2的值为:" + mydate2);
mydate2.setYear(108);
mydate2.setMonth(7);
mydate2.setDate(1);
mydate2.setHours(23);
mydate2.setMinutes(59);
mydate2.setSeconds(59);
System.out.println("修改后mydate2的值为:" + mydate2);
//比较两个日期是否相等
if(mydate1.equals(mydate2)){
System.out.println("mydate1与mydate2相同");
}
else{
//比较两个日期的先后关系
if(mydate1.compareTo(mydate2)>0){
System.out.println("mydate1晚于mydate2");
}
else{
System.out.println("mydate1早于mydate2");
}
}
}
}TestClassPerson.java
public class TestClassPerson{
/*定义成员变量*/
private String personName;//姓名
private int personAge;//年龄
private String personSex;//性别
/*定义成员方法*/
public void setPersonVar(String name,int age,String sex){
personName = name;
personAge = age;
personSex = sex;
}
public void updatePersonVar(String name,int age,String sex){
personName = name;
personAge = age;
personSex = sex;
}
public String getPersonName(){
return personName;
}
public int getPersonAge(){
return personAge;
}
public String getPersonSex(){
return personSex;
}
public static void main(String args[]){
TestClassPerson person = new TestClassPerson();
person.setPersonVar("王义",25,"男");
String outName = person.getPersonName();
int outAge = person.getPersonAge();
String outSex = person.getPersonSex();
System.out.println("姓名:"+outName+",年龄:"+outAge+",性别:"+outSex);
person.updatePersonVar("李玲",20,"女");
outName = person.getPersonName();
outAge = person.getPersonAge();
outSex = person.getPersonSex();
System.out.println("姓名:"+outName+",年龄:"+outAge+",性别:"+outSex);
}
}134