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