当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

上海交通大学:《操作系统 Operating System》课程教学资料(JAVA PPT)lec5

资源类别:文库,文档格式:PPT,文档页数:62,文件大小:1.18MB,团购合买
点击下载完整版文档(PPT)

CS3101-3 Programming Language-JAVA Fall 2004 Oct.13rd

CS3101-3 Programming Language - JAVA Fall 2004 Oct.13rd

Roadmap today ●Review ●Inner class ●Multi--threading ●Graphics

Roadmap today lReview lInner class lMulti-threading lGraphics

Containers O Hold a group of objects o Significantly increase your programming power OAll perform bound checking ● array:efficient,can hold primitives Collection:a group of individual elements OList,Set o Map:a group of key-value object pairs OHashMap o Misleading:sometimes the whole container libraries are also called collection classes

Containers l Hold a group of objects l Significantly increase your programming power l All perform bound checking l array: efficient, can hold primitives l Collection: a group of individual elements ¡List, Set l Map: a group of key-value object pairs ¡HashMap l Misleading: sometimes the whole container libraries are also called collection classes

Collection:hold one item at each location List:items in order Set:no duplicates,no ordering ArrayList List LinkedList Vector Collection Preserve the insertion of the elements Set HashSet LinkedHashSet TreeSet

Collection List ArrayList LinkedList Vector Set HashSet LinkedHashSet TreeSet Collection: hold one item at each location List: items in order Set: no duplicates, no ordering Preserve the insertion of the elements

Map:key-value pairs,fast retrieval no duplicate keys,no ordering HashMap LinkedHashMap Map Hashtable Preserve the insertion of the elements TreeMap

Map HashMap LinkedHashMap Hashtable TreeMap Map: key-value pairs, fast retrieval no duplicate keys, no ordering Preserve the insertion of the elements

Disadvantages of container o Cannot hold primitives OHave to wrap it o Lose type information when put object into container OEverything is just Object type once in container o Have to do cast when get it out OYou need to remember what's inside o Java do run time type check OClassCastException

Disadvantages of container lCannot hold primitives ¡Have to wrap it lLose type information when put object into container ¡Everything is just Object type once in container lHave to do cast when get it out ¡You need to remember what’s inside lJava do run time type check ¡ClassCastException

Iterator object OAccess method regardless of the underlying structure ●Generic programming OCan change underlying structure easily ●“light--weight”object OCheap to create o Can move in only one direction

Iterator object lAccess method regardless of the underlying structure lGeneric programming ¡Can change underlying structure easily l“light-weight” object ¡Cheap to create lCan move in only one direction

Iterator constraints oContainer.iterator()returns you an Iterator, which is ready to return the first element in the sequence on your first call to next() ●( Get the next object in the sequence with next() ● Set there are more objects in the sequence with hasNext() o Remove the last element returned by the iterator with remove() Example:revisit CatsAndDogs.java

Iterator constraints l Container.iterator() returns you an Iterator, which is ready to return the first element in the sequence on your first call to next() l Get the next object in the sequence with next() l Set there are more objects in the sequence with hasNext() l Remove the last element returned by the iterator with remove() l Example: revisit CatsAndDogs.java

Java l/O:lowest level abstraction InputStream/OutputStream class OByte-oriented Oread()return the byte got read Owrite(int b)writes one byte out oCan obtain from console,file,or socket o Handle them in essentially the same way oWrite your code to work with Streams and won't care if it's talking to a file or a system on the other side of the world

Java I/O: lowest level abstraction lInputStream/OutputStream class ¡Byte-oriented ¡read() return the byte got read ¡write(int b) writes one byte out lCan obtain from console, file, or socket lHandle them in essentially the same way lWrite your code to work with Streams and won’t care if it’s talking to a file or a system on the other side of the world

Serialization An important feature of Java o Convert an object into a stream of byte, and can later deserialize it into a copy of the original object o Takes care of reassembling objects oNeed to cast type when read back Any object as long as it implements Serializable interface ONo method inside

Serialization lAn important feature of Java lConvert an object into a stream of byte, and can later deserialize it into a copy of the original object lTakes care of reassembling objects lNeed to cast type when read back lAny object as long as it implements Serializable interface ¡No method inside

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共62页,可试读20页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有