






















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!























































Review Inner class Multi-threading Graphics
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 HashMap LinkedHashMap Hashtable TreeMap Map: key-value pairs, fast retrieval no duplicate keys, no ordering Preserve the insertion of the elements
Access method regardless of the underlying structure Generic programming Can change underlying structure easily “light-weight” object Cheap to create Can move in only one direction
Container. 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 () Remove the last element returned by the iterator with remove () Example: revisit CatsAndDogs.java
An important feature of Java Convert an object into a stream of byte, and can later deserialize it into a copy of the original object Takes care of reassembling objects Need to cast type when read back Any object as long as it implements Serializable interface No method inside
Java.net.
Grab the associated streams InputStream is = s.getInputStream(); OutputStream os = s.getOutputStream(); URL class InputStream is = u.openStream();
What if we want to use classes for our internal implementation? Inner classes! A class defined inside another class Similar to the methods or fields of class Can be static, public, private Can be private so no other class can use it Usable by enclosing class
InnerClassTest.java
A local class without a name Defined and instantiated in a single expression using the new operator. public void start (){ ActionListener listener = new ActionListener{ public void actionPerformed(ActionEvent e){ System.out.println(“get the event ”+e); } } ; //Need to give a ; here, since it’s an expression }
The class has a short body Only one instance of the class is needed The class is used right after it is defined The name of the class does not make your code any easier to understand
Threads are lightweight, application-level form of multi-tasking Also preemptive (when time is up, switch to another one) But not protected: all can see the same memory Which means much faster communication than classic “interprocess communication (IPC)”
You have the main() thread, and The garbage collector thread And any other thread by yourself