六基础类库和工具类库课件

上传人:沈*** 文档编号:231374041 上传时间:2023-09-02 格式:PPT 页数:56 大小:1.58MB
收藏 版权申诉 举报 下载
六基础类库和工具类库课件_第1页
第1页 / 共56页
六基础类库和工具类库课件_第2页
第2页 / 共56页
六基础类库和工具类库课件_第3页
第3页 / 共56页
资源描述:

《六基础类库和工具类库课件》由会员分享,可在线阅读,更多相关《六基础类库和工具类库课件(56页珍藏版)》请在装配图网上搜索。

1、六、基础类库和工具类库Java类库字符串相关类 集合 日期与时间1六基础类库和工具类库1Java类库熟悉Java基础类库掌握Object理解基本数据类型的封装掌握System和Math类2六基础类库和工具类库1Java类库Java的类库是系统提供的已实现的标准类的集合,是Java编程的API(ApplicationProgramInterface),它可以帮助开发者方便、快捷地开发Java程序。这些系统定义好的类根据实现的功能不同,可以划分成不同的集合,每个集合是一个包,合称为类库。Java的类库大部分是由它的发明者SUN公司提供的,这些类库称为JFC(基础类库,JavaFoundationC

2、lassLibrary)。API应用程序编程接口面向过程语言函数库(子程序包)面向对象语言类库3六基础类库和工具类库类库的结构java.lang语言基础类库(System、Math、Thread、基本数据类型类)java.utilJava的工具类库(向量、栈、日期)java.ioJava的标准输入输出类库java.applet用于实现JavaApplet小程序的类库java.awt用于构建图形用户界面的类库java.awt.event界面用户交互控制和事件响应类库java.awt.image用来处理和操纵来自于网上图片的工具类库Java的用于实现网络功能的类库java.sql用来时间JDBC的

3、类库,利用它可以使Java访问各种数据库4六基础类库和工具类库使用JDKDocument查看类库在JDK文档的解压目录下,选择index.htmlindex.html进入JDK文档,然后在文档中单击“API&LanguageAPI&Language”“Java 2 Platform API SpecificationJava 2 Platform API Specification”就可以打开JDK中的类库。注意文档中标记为Deprecated的方法!5六基础类库和工具类库Object类Java程序中所有类的直接或间接父类,也是类库中所有类的的父类,所有的其他类都是从Object类派生。构造方

4、法:Object()一般方法:Objectclone()生成当前对象的一个拷贝。booleanequals(Objectobj)比较两个对象是否相同。ClassgetClass()获取当前对象所属的类信息。StringtoString()用来返回当前对象本身的有关信息。inthashCode()返回对象的哈希码。finalize()定义回收当前对象时所需要完成的清理工作。6六基础类库和工具类库【例6.1】Object中定义方法的使用。packagebook.ch6;publicclassBasicObjectDemopublicstaticvoidmain(Stringargs)Aa1=new

5、A();Aa2=newA();Aa3=a1;System.out.println(a1.equals(a2);System.out.println(a3.equals(a1);System.out.println(a1.hashCode();System.out.println(a1.toString();classAfalsetrueBook.ch6.Alfb8ee3这两者关系这两者关系如何?如何?7六基础类库和工具类库Class类Java运行时系统会对所有的对象进行类型识别publicfinalClassextendsObject一般方法:StringgetName()返回类名。Field

6、getFields()返回类的public域对象。MethodgetMethods()返回类的public方法对象。PackagegetPackage()返回该类的包。对Field类StringgetName()取域名对Method类StringgetName()取方法名对Package类StringgetName()8六基础类库和工具类库数据类型类基本数据类型vs.数据类型类如:booleanvsBoolean,charvsCharacter等数据类型类规定了数据类型的最大值、最小值构造函数:如newInteger(10);完成不同数据类型间转换,注意不同的数据类使用的方法会有不同。如:Do

7、uble.toString(0.08)、Integer.parseInt(“123”)、Double.ValueOf(“0.08”).intValue()等,见JDKDoc【例6.2】基本数据封装类。9六基础类库和工具类库publicclassBasicDataTypeClassDemopublicBasicDataTypeClassDemo()publicstaticvoidmain(Stringargs)Integeri=newInteger(256);Integerj=newInteger(256);System.out.println(i.intValue()*2);System.ou

8、t.println(i.doubleValue();System.out.println(i=+i.toString();System.out.println(i=j);System.out.println(pareTo(j);/i大取大取1,i小取小取-1System.out.println(Integer.parseInt(100)*2);System.out.println(100*2=+Integer.toString(100*2);intk;k=Integer.valueOf(1010,2);System.out.println(k);System.out.println(Integ

9、er.MAX_VALUE);System.out.println(Integer.MIN_VALUE);512256.0i=256false0200100*2=200102147483674-214748367410六基础类库和工具类库Math类Math类用来完成常用的数学运算数学常量:E,PI数学运算Math.abs(-8.09);/取绝对值Math.exp(5.7);/自然对数Math.random();/取得一个随机数Math.sqrt(9.08);/开平方Math.pow(2,3);/乘方Math.round(99.6);/取得最接近的整数均为static,使用时无需创建实例Math.

10、method(variable);11六基础类库和工具类库属性publicfinalstaticdoubleE;/数学常量epublicfinalstaticdoublePI;/圆周率常量方法(均为静态方法)publicstaticintabs(inti);publicstaticdoublesin(doublea);publicstaticdoublelog(doublea);publicstaticdoublemax(doublea,doubleb);publicstaticdoublepow(doublea,doubleb);publicstaticdoublerandom();/产生0

11、1之间伪随机数12六基础类库和工具类库publicstaticdoubleexp(doublea);publicstaticintround(floata);publicstaticdoublesqrt(doublea);例:System.out.println(Math.E);/2.718281828.System.out.println(Math.PI);/3.14159265System.out.println(Math.pow(2,3);/8.0System.out.println(Math.round(99.6);/100System.out.println(Math.abs(-8.

12、09);/8.0913六基础类库和工具类库System类System是一个功能强大的类,它不能被实例化,是一个非常典型的静态方法类,但提供了标准输入输出、运行时的系统信息等工具。系统功能获取系统标准输入/输出System.in,System.out,System.err获取系统信息System.currentTimeMillis()执行系统操作System.exit(0);System.gc();/指定运行垃圾回收器14六基础类库和工具类库属性publicstaticInputStreaminpublicstaticPrintStreamoutpublicstaticPrintStreamer

13、r获取系统信息、完成系统操作的方法publicstaticlongcurrentTimeMillis();获取自1970年1月1日零时至当前系统时刻的微秒数publicstaticvoidexit(intstatus);强制Java虚拟机退出运行状态,并把状态信息status返回给运行虚拟机的操作系统。如:System.exit(0);publicstaticvoidgc();强制调用Java虚拟机的垃圾回收功能。15六基础类库和工具类库2字符串相关类熟悉字符串相关类掌握String和StringBuffer了解StringTokenizer16六基础类库和工具类库StringJava语言中将

14、字符串作为对象来处理,定义了相应的语言中将字符串作为对象来处理,定义了相应的类类String,位于,位于java.lang包中,每一个字符串常量就是包中,每一个字符串常量就是String类的一个实例。下表是类的一个实例。下表是String类常用的方法。类常用的方法。方方法法说说明明publicintlength()返回字符串的返回字符串的长长度。度。publicbooleanequals(ObjectanObject)将将给给定字符串与当前字符串相比定字符串与当前字符串相比较较,若两字,若两字符串相等,符串相等,则则返回返回true,否,否则则返回返回false。publicStringsub

15、string(intbeginIndex)返回字符串中从返回字符串中从beginIndex开始的子串。开始的子串。publicStringsubstring(intbeginIndex,intendIndex)返回从返回从beginIndex开始到开始到endIndex的子串。的子串。publiccharcharAt(intindex)返回返回index指定位置的字符。指定位置的字符。publicintindexOf(Stringstr)返回返回str在字符串中第一次出在字符串中第一次出现现的位置。的位置。publicStringreplace(charoldChar,charnewChar)

16、以以newChar字符替字符替换换串中所有串中所有oldChar字符。字符。publicStringtrim()去掉字符串的首尾空格。去掉字符串的首尾空格。17六基础类库和工具类库String类的重要特性之一就是线程访问安全。因为String类对象实际上是不可改变的,任何涉及到对String类表示的字符串的操作方法,都是返回一个新创建的String类对象,因此在对一个String类型的使用中,往往会同时创建大量并不需要的String实例,消耗了不必要的系统资源。【例6.3】字符串方法的使用。见教材P126页18六基础类库和工具类库StringBuffer为了解决String类的使用对系统资源带

17、来的不利影响,基本类库提供了StringBuffer类。该类封装了一个字符数组,并提供了对这个数组的操作方法。下表是StringBuffer类常用的方法。方方法法功功能能StringBuffer()创建一个空的创建一个空的StringBuffer对象对象StringBuffer(intlength)设置初始化容量设置初始化容量StringBuffer(Strings)用已有用已有String对象初始化对象初始化StringBuffer对象对象StringBufferappend(Objectobj)增加增加Object对象的字符串表示对象的字符串表示StringBufferinsert(int

18、offset,Objectobj)在在offset位置插入位置插入Object对象的字符串表示对象的字符串表示voidsetCharAt(intindex,charch)将将index位置的字符改为位置的字符改为chStringtoString()将可变串变为不可变串,以便输出将可变串变为不可变串,以便输出charcharAt(intindex)返回返回index指定位置的字符指定位置的字符intcapacity()获得当前获得当前StringBuffer对象的容量对象的容量intindexOf(Stringstr)返回返回str子串在当前子串在当前StringBuffer对象中的位置对象中的

19、位置19六基础类库和工具类库【例6.4】StringBuffer类的使用publicclassStringBufferDemopublicstaticvoidmain(Stringargs)StringBufferbuffer=newStringBuffer();buffer.append(S);buffer.append(tringBuffer);System.out.println(buffer.charAt(1);System.out.println(buffer.capacity();System.out.println(buffer.indexOf(tring);System.out

20、.println(buffer=+buffer.toString();t161Buffer=StringBuffer20六基础类库和工具类库StringTokenizerStringTokenizer提供了对字符串的解析和分割功能,使用这个类可以对一个字符串按照某些子串的特征进行分割。【例6.4】StringTokenizer的使用。importjava.util.StringTokenizer;publicclassStringTokenizerDemopublicstaticvoidmain(Stringargs)Strings=demoofStringTokenizer;StringTo

21、kenizertokenizer=newStringTokenizer(s,);while(tokenizer.hasMoreTokens()System.out.println(tokenizer.nextToken();demoofStringTokenizer21六基础类库和工具类库了解集合API熟悉Set,List,Iterator接口熟悉Map接口了解集合数据遍历、排序和查找集合22六基础类库和工具类库集合是一系列对象的聚集,是代表一组对象的一个对象,集合中的每一个对象称为集合的元素,每一个元素都具有一定的数据类型,任何数据类型的对象都可以存放在集合中。集合接口Collection集

22、合接口Set集合接口List集合接口Iterator集合接口Map23六基础类库和工具类库Collection接口分布在java.util包下,定义了聚集形式数据的基本操作方法,主要包括:publicbooleanadd(Object)加入一个元素publicbooleanaddAll(Collection)将另外一个集合中的元素全部加入指定的集合中publicvoidclear()清除所有的元素publicbooleancontains(Object)判断包含某特定的元素否publicIteratoriterator()得到迭代器publicbooleanremove(Object)删除一个

23、元素publicintsize()得到集合中元素的总数publicisEmpty()判断集合是否为空publicObjecttoArray()将集合转化为对象数组Collection接口24六基础类库和工具类库Collection接口的子接口,定义了一个不重复元素的集合。Set接口对于集合中对于集合中的任何两个的任何两个元素元素x和和y,x.equals(y)始终为始终为false!25六基础类库和工具类库26六基础类库和工具类库ConstructorSummaryHashSetHashSet()Constructsanew,emptyset;thebackingHashMapinstance

24、hasdefaultinitialcapacity(16)andloadfactor(0.75).HashSetHashSet(Collectionc)Constructsanewsetcontainingtheelementsinthespecifiedcollection.HashSetHashSet(intinitialCapacity)Constructsanew,emptyset;thebackingHashMapinstancehasthespecifiedinitialcapacityanddefaultloadfactor(0.75).HashSetHashSet(intini

25、tialCapacity,floatloadFactor)Constructsanew,emptyset;thebackingHashMapinstancehasthespecifiedinitialcapacityandthespecifiedloadfactor.HashSet类的成员方法类的成员方法27六基础类库和工具类库MethodSummarybooleanaddadd(Ee)Addsthespecifiedelementtothissetifitisnotalreadypresent.voidclearclear()Removesalloftheelementsfromthisse

26、t.Objectcloneclone()ReturnsashallowcopyofthisHashSetinstance:theelementsthemselvesarenotcloned.booleancontainscontains(Objecto)Returnstrueifthissetcontainsthespecifiedelement.booleanisEmptyisEmpty()Returnstrueifthissetcontainsnoelements.Iteratoriteratoriterator()Returnsaniteratorovertheelementsinthi

27、sset.booleanremoveremove(Objecto)Removesthespecifiedelementfromthissetifitispresent.intsizesize()Returnsthenumberofelementsinthisset(itscardinality).28六基础类库和工具类库【例例6.5】Set接口和接口和HashSet类的使用。类的使用。importjava.util.Set;importjava.util.HashSet;publicclassSetDemopublicstaticvoidmain(Stringargs)Setset=newHa

28、shSet();/父接口引用变量指向子类对象。父接口引用变量指向子类对象。set.add(“1”);/添加元素添加元素set.add(2);set.add(3);set.add(4);set.add(newInteger(1);/添加扩展数据类型的元素添加扩展数据类型的元素set.add(newDouble(7.0);set.add(“3”);/添加重复元素添加重复元素System.out.println(“set=”+set.toString();/输出集合中的元素输出集合中的元素Objectarray=set.toArray();/将集合转化为数组将集合转化为数组for(inti=0;ia

29、rray.length;i+)System.out.println(tarray+i+=+arrayi.toString();29六基础类库和工具类库Array1和array5是重复的吗?为什么?30六基础类库和工具类库【例例6.6】使用使用Set接口和接口和HashSet类表示类表示family。importjava.util.Set;importjava.util.HashSet;classFatherprivateStringname;Father(Stringname)this.name=name;publicStringtoString()returnname;classMother

30、privateStringname;Mother(Stringname)this.name=name;publicStringtoString()returnname;classDaughterprivateStringname;Daughter(Stringname)this.name=name;publicStringtoString()returnname;classDogprivateStringname;Dog(Stringname)this.name=name;publicStringtoString()returnname;31六基础类库和工具类库publicclassFamil

31、ypublicstaticvoidmain(Stringargs)Setfamily=newHashSet();family.add(newFather(father:Rhette);family.add(newMother(mathor:Scarlet);family.add(newDaughter(“daughter:Alice);family.add(newDog(dog:Windy);System.out.println(Thisismyfamily!);System.out.println(family=+family.toString();Thisismyfamily!family

32、=daughter:Alice,dog:Windy,mathor:Scarlet,father:Rhette注意他们出现的顺序无序的!32六基础类库和工具类库Collection接口的子接口,定义了一个有序元素的集合,在使用上类似动态数组/变长数组,可存放的元素数量随插入操作自动进行调整。List接口允许重复的允许重复的元素存在!元素存在!33六基础类库和工具类库List接口的部分方法方方法法功功能能publicvoidadd(intindex,Objecte)在在index处插入处插入epublicbooleanassAll(intindex,Collectionc)将将c中的元素全部加入到

33、本集合中中的元素全部加入到本集合中index处处publicObjectset(intindext,Objecte)用用e替换替换index处的元素处的元素publicObjectget(intindex)返回返回Index处的元素处的元素publicObjectremove(intindex)删除删除Index处的元素处的元素publicintindexOf(Objecte)返回返回e首次出现的位置,无则返回首次出现的位置,无则返回-1publicintlastIndexOf(Objecte)返回返回e末次出现的位置,无则返回末次出现的位置,无则返回-1publicListsubList(i

34、ntfromIndex,inttoIndex)返回一个子集,从返回一个子集,从fromIndex开始,开始,到到toIndex结束结束publicListIteratorlistIterator()得到迭代器得到迭代器publicListIteratorlistIterator(intindex)得到迭代器,该迭代器从得到迭代器,该迭代器从index开始开始34六基础类库和工具类库【例例6.7】List接口和ArrayList类的使用。importjava.util.*;publicclassListDemopublicstaticvoidmain(Stringargs)Listlist=ne

35、wArrayList();/父接口引用变量指向子类对象。父接口引用变量指向子类对象。list.add(1);/添加元素添加元素list.add(2);list.add(3);list.add(4);list.add(5);list.add(newDouble(7.0);/添加扩展数据类型的元素添加扩展数据类型的元素list.add(4);/添加重复元素添加重复元素System.out.println(list=+list);/输出集合中的元素输出集合中的元素Objectarray=list.toArray();/将集合转化为数组将集合转化为数组for(inti=0;iarray.length;

36、i+)System.out.println(tarray+i+=+arrayi.toString();35六基础类库和工具类库Array3和array6是重复的吗?为什么?36六基础类库和工具类库Iterator接口Iterator接口主要用来遍历集合中的元素,其主要方法包括:【例例6.8】使用使用Iterator接口遍历集合中的元素。接口遍历集合中的元素。MethodSummarybooleanhasNexthasNext()Returnstrueiftheiterationhasmoreelements.Objectnextnext()Returnsthenextelementinthei

37、teration.voidremoveremove()Removesfromtheunderlyingcollectionthelastelementreturnedbytheiterator(optionaloperation).37六基础类库和工具类库import java.util.Set;import java.util.HashSet;import java.util.Iterator;public class IteratorDemopublic static void main(String args)Set set=new HashSet();set.add(1);set.ad

38、d(2);set.add(3);set.add(4);set.add(new Integer(1);set.add(new Double(7.0);Iterator iterator=set.iterator();/得到集合while(iterator.hasNext()/列举集合中的元素System.out.println(iterator.next();iterator.remove();/删除集合中当前的元素System.out.println(set=+set);38六基础类库和工具类库39六基础类库和工具类库ListIterator是Iterator的子接口,它针对List集合有序的

39、特点,提供了双向检索和元素存取的功能,其方法如下表:voidaddadd(Ee)Insertsthespecifiedelementintothelist(optionaloperation).booleanhasNexthasNext()Returnstrueifthislistiteratorhasmoreelementswhentraversingthelistintheforwarddirection.booleanhasPrevioushasPrevious()Returnstrueifthislistiteratorhasmoreelementswhentraversingthel

40、istinthereversedirection.Objectnextnext()Returnsthenextelementinthelist.intnextIndexnextIndex()Returnstheindexoftheelementthatwouldbereturnedbyasubsequentcalltonext.Objectpreviousprevious()Returnsthepreviouselementinthelist.intpreviousIndexpreviousIndex()Returnstheindexoftheelementthatwouldbereturne

41、dbyasubsequentcalltoprevious.voidremoveremove()Removesfromthelistthelastelementthatwasreturnedbynextorprevious(optionaloperation).voidsetset(Ee)Replacesthelastelementreturnedbynextorpreviouswiththespecifiedelement(optionaloperation).40六基础类库和工具类库【例6.9】使用ListIterator接口列举集合中的元素。import java.util.List;im

42、port java.util.ArrayList;import java.util.ListIterator;public class ListIteratorDemopublic static void main(String args)List list=new ArrayList();list.add(1);list.add(2);list.add(3);list.add(4);list.add(5);ListIterator iterator=list.listIterator();while(iterator.hasNext()/正向列举System.out.println(“t”+

43、iterator.next();while(iterator.hasPrevious()/逆向列举System.out.println(“t”+iterator.previous();41六基础类库和工具类库正向列举反向列举42六基础类库和工具类库MapCollection接口处理单一对象数据集合,Map接口用于处理“关键字-值”这样形式的集合。Map中包括了关键字的集合、值的集合,以及关键字和值的映射关系。实现Map接口的类有很多,其中最常用的是HashMap和HashTable(线程访问安全的)。关键字和值只能是String类型,常用于读去配置信息。43六基础类库和工具类库MethodSu

44、mmary voidvoidclearclear()Removesallofthemappingsfromthismap(optionaloperation).booleanbooleancontainsKeycontainsKey(Objectkey)Returnstrueifthismapcontainsamappingforthespecifiedkey.booleanbooleancontainsValuecontainsValue(Objectvalue)Returnstrueifthismapmapsoneormorekeystothespecifiedvalue.SetSeten

45、trySetentrySet()ReturnsaSetviewofthemappingscontainedinthismap.booleanbooleanequalsequals(Objecto)Comparesthespecifiedobjectwiththismapforequality.ObjectObjectgetget(Objectkey)Returnsthevaluetowhichthespecifiedkeyismapped,ornullifthismapcontainsnomappingforthekey.intinthashCodehashCode()Returnstheha

46、shcodevalueforthismap.44六基础类库和工具类库 booleanbooleanisEmptyisEmpty()Returnstrueifthismapcontainsnokey-valuemappings.SetSetkeySetkeySet()ReturnsaSetviewofthekeyscontainedinthismap.V Vputput(Kkey,Vvalue)Associatesthespecifiedvaluewiththespecifiedkeyinthismap(optionaloperation).voidvoidputAllputAll(Mapm)C

47、opiesallofthemappingsfromthespecifiedmaptothismap(optionaloperation).V Vremoveremove(Objectkey)Removesthemappingforakeyfromthismapifitispresent(optionaloperation).intintsizesize()Returnsthenumberofkey-valuemappingsinthismap.CollectionCollectionvaluesvalues()ReturnsaCollectionviewofthevaluescontained

48、inthismap.45六基础类库和工具类库【例6.10】使用Map接口表示family。import java.util.*;public class FamilyDemopublic static void main(String args)Map family=new HashMap();family.put(“Rhette”,“银帆公司”);/添加元素family.put(“Scarlet”,“人民医院);family.put(“Alice”,“育英小学);family.put(“Windy”,“Windy的窝);System.out.println(family.get(“Rhett

49、e”);/输出父亲所在的单位Set keySet=family.keySet();/列举所有关键字for(Iterator iterator=keySet.iterator();iterator.hasNext();)System.out.println(t+iterator.next();Collection values=family.values();/列举所有的值for(Iterator iterator=values.iterator();iterator.hasNext();)System.out.println(iterator.next();Set entrySet=famil

50、y.entrySet();/列举所有映射for(Iterator iterator=entrySet.iterator();iterator.hasNext();)System.out.println(iterator.next();46六基础类库和工具类库银帆公司AliceRhetteScarletWindy育英小学银帆公司人民医院Windy的窝Alice=育英小学Rhette=银帆公司Scarlet=人民医院Windy=Windy的窝对应的单位所有映射家庭成员父亲的单位47六基础类库和工具类库集合数据的遍历(1)通用的列举Collection接口集合的方法voidenumerate(Col

51、lectioncollection)for(Iteratoriterator=collection.iterator();iterator.hasNext();)Objecto=iterator.next();(2)遍历List集合的方法voidenumerate(Listlist)for(inti=0;ilist.size();i+)Objecto=list.get(i);(3)遍历一些有特殊方法的集合voidenumerate(Vectorvector)for(inti=0;ivector.size();i+)Objecto=vector.elementAt(i);48六基础类库和工具类库

52、查找和排序首先java.util.Comparator接口提供了比较对象间大小的方法。publicinterfaceComparatorintcompare(Objecto1,Objecto2);booleanequals(Objectobj);其次java.util.Collections类提供了大量对集合的辅助性操作方法,与排序有关的主要有:publicstaticvoidsort(Listlist);publicstaticvoidsort(Listlist,Comparatorc);排序的依据可以采用第二个方法中的参数c来约束。例:P137排序49六基础类库和工具类库掌握Date掌握C

53、alendar4日期与时间50六基础类库和工具类库日期类java.util包里提供了操作时间的基本功能类,包括Date、Calendar和GregorianCalender类,其中Date类早在JDK1.1版中就出现了,但由于设计存在严重缺陷,其中大量方法被废弃(Deprecated),而被分散到其他类中,因此在使用Date类的时候应该尽量避免使用这些方法。51六基础类库和工具类库Date构造方法Date()初始化时间对象,记录当前系统时间Date(longdate)以毫秒为单位,从1970年1月1日0时开始构造一个Date实例。方法longgetTime()获取自1970.1.1零时至当前系

54、统时刻的微秒数intgetDate()获取系统当前日期booleanafter(Datedate)当前对象所含日期是否迟于datebooleanbefore(Datedate)当前对象所含日期时候早于datevoidsetTime(longt)设置新的时间52六基础类库和工具类库importjava.util.Date;publicclassDateTestpublicstaticvoidmain(Stringargs)DatecurrentDate=newDate();System.out.println(currentDate=+currentDate);DatenewDate=newDa

55、te(1000000);System.out.println(newDate=+newDate);System.out.println(currentDate.after(newDate);System.out.println(currentDate.before(newDate);System.out.println(MSsince1970-1-1:“+currentDate.getTime();currentDate=MonSep1019:40:05CST2007newDate=ThuJan0108:16:40CST1970truefalseMSsince1970-1-1:1453六基础类

56、库和工具类库Calendar抽象类,定义了一系列的成员变量在Date对象和一组整数域之间进行转换:YEAR,MONTH,DAY,HOUR,Calendar的实例不能通过构造方法获得,一般使用以下方法:Calendarc=Calendar.getInstance();通过以下方法可以获得所指定域的时间intc.get(Calendar.YEAR)intc.get(Calendar.MONTH)(1月为0)intc.get(Calendar.DATE)intc.get(Calendar.HOUR)intc.get(Calendar.MINUTE)intc.get(Calendar.SECOND)Datec.getTime()54六基础类库和工具类库通过以下方法设置当前对象所表示的时间c.set(Calendar.YEAR,2000)c.set(Calendar.MONTH,10)(11月)c.set(Calendar.DATE,7)c.set(2000,10,7)c.set(2000,10,7,17,48,20)一些与Date类同名的方法例:P141案例6.855六基础类库和工具类库小结课后作业P144习题6、856六基础类库和工具类库

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!