Java Certification Quick Review: Notes (based on Programmers guide to Java Certification) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CHAPTER 1: Basics Of Java Programming ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Object references are also known as aliases. - There can be only one public class in a file. - public static void main(String args[]) { /* code */ } - args[0] is the first param, args[args.length - 1] is last param. CHAPTER 2: Language Fundamentals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Identifier: composed of seq. of chars - letter, digit, connecting punctuation (eg: _) or *any* currency symbol. CANNOT start with a digit. Unicode char set used. All special - after 127 are also legal. - Keywords include: instanceof, native, transient - Reserved Keywords, but not used: const, goto - Reserved literals: null, true, false - Unicode Character Values: \uNNNN, N: 0-9, a-f: *hex* - escape sequences: \b \t \f \r \' \" \\ \n - white spaces: spaces, tabs(\t), form feeds(\f), line terminators (\n \r) - *boolean* not bool, or BOOL - no unsigned types !!! - static, instance vars are init to default values. *not* Local vars. - A source file might not have any class defination. CHAPTER 3: Operators and Assignments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Operator precedence and associativity table: pg 42 - type casting has greater precedence than other operators. - 4.2F and 4.2f are both valid. - % can be used on non int values. - boolean values cannot be cast into other values and vice-versa. - All expression evals (incl. shift) are at least ints, or promoted. - All expressions are by default int, even if results is lost/incorrect. - Implicit narrowing primitive conversions on assignments can occur in cases where the source is an int *const* expression whose value can be determined to be in the range of the destination type at *compile* time. - Narrowing primitive conversions requires explicit cast. - float values are *truncated* when casting to integral values. - Narrowing conversions between char and byte (or short) always require an explicit cast, even if the value is in range of destination. - Extended Assignment operators have a implicit cast i.e. "i += y" is equivilant to "i = (T) i + y", where T is the datatype of i. - if a str is involved in exp, all others are also converted to str unless seperated by (). - "=" and "!=" when used on references, find if the refs point to same obj - not *class*, nor *values*. Use equals() for the purpose. By default equals() is same as "=" comparision. - Boolean logic operators (!, &, !, ^) always evaluate both operands. - >> inserts sign bit in left most position - 0 if +ive, 1 if -ive - >>> inserts 0 in the leftmost bit - Bit values shifted out are lost - both left and right shift - Since bits can be shifted right or left, a +ive value, when shifted can result in a -ive value and vice-versa. - sign bit has no special significance during shifting. i.e. no special treatment is given to sign bit while shifting. - in method param list, keyword void is not a valid type. *no*: void f(void) CHAPTER 4: Declarations and Access Control ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Arrays are objects, all have a .length instance variable. - Arrays of length 0 can be created. - Since arrays are objects, new has to be used to create them. - Arrays, when created, are automatically initialized to default values. - Anonymous arrays : new int[] {3,2,6,7,4} : arrays created and initilized without a name, can be passed as a parameter, assigned to an array ref, etc... - The import declaration does not recursivly import sub packages. - Member accessibility is governed seperatly from class accessibility, however, if a class is not accessible, its members will not be accessible, regardless of member accessibility. - Objects don't have visibility - references have. - A method in a class can have the same name as a class, *with* return type. - A class that has an abstract method, must be declared abstract. A subclass that does not provide any implementation for its inherited abstract methods are also abstract. - A local variable, already declared in an enclosing block and therefore visible in a nested block, cannot be redeclared in the nested block. - protected members are accessible in the package containing this class, and by all subclasses of this class in any package, where this class is visible. - If access modifier is not specified, they can only be accessed by other items of the package but not any other package (including subpackages) even if the class is visible in that package.. - When a class is loaded, static members are initialized to default value. - final: variable is const, parameter vlaue cannot be changed, function cannot be overridden, class cannot be sub-classed. A final method cannot be abstract. - native methods: not implemented in Java: System.loadLibrary("Lib"); - transient variables - do not get saved / restored during serialization. - static variables cannot be transient as they do not belong to object. CHAPTER 5: Flow Control and Exception Handling ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - type or var for switch can *only* be byte char short int. - case labels must be assignable to type. - default cam be in between case statemnts. - variables declared in for loop live only till the loop. - break and continue can be used in conjunction with labels to break out or cotinue deeply nested loops. i.e. can be used to break more than 1 level. - break can be used to jump out of a labeled block. - checked exceptions (non runtime), have to be caught and delt with. - A try block must be followed by: at least one catch or one finally block. - main method can declare that it throws checked exceptions. CHAPTER 6: OO Programming ~~~~~~~~~~~~~~~~~~~~~~~~~ - The java.lang.Object class is the root of any inheritance hierarchy. - Upcasting: A subclass reference can be assigned to a super class reference. - Downcasting: Superclass ref to sub class requires explicit casting. - while overriding a method, methods must have same signature and same return type. The new method *cannot* narrow the accessibility, but can widen it. Parameters in overriding method can be final, as method signature is based *only* on type and order (not modifiers). - final, static and private methods *cannot* be overridden. - member variables can be shadowed (including static). - super can be used to access variables or invoke methods of super class. super cannot be assigned to references and cannot be cast to other types. super.super in *not* valid. We cannot access over-ridden members, 2 levels up. - It is possible to directly access *variables* up the heirarchy by casting the this reference. Casting this ref has *no effect* on which method is invoked. - this(...) can be used to call another constructor from this one. - All interface members have public accessibility. - An interface can extend other interfaces using extends clause. - A class that does not implement all interface members will have to be declared abstract. - references of interface type can be declared, and these can denote objects of classes that implement this interface. CHAPTER 7: Inner Classes ~~~~~~~~~~~~~~~~~~~~~~~~ - Top level nested class / interface - defined as static member in enclosing class. (eg. public static class aa). - Object of ~ can be created without regard to its nesting. - A method in ~ can only access static members in the encl class / i_face. - can have any accessibility. - Non static inner class - defined without keywork static. - can only exists with instance of enclosing class (ref.new NonStatic()). - cannot have static members. - can refer to any (incl. private) members of inclosing class. - can have any accessibility. - have to use enclosing class name to use this (EnclClass.this.member). - can extend other classes and can themselves be extended. - Local Classes - defined within a block: {} - context determines if class is static. static is not used explictly. - have similar capabilities to non-static inner classes. - cannot have static members (cannot provide class specific services). - cannot have any accessibility (similar to local variables) - can access only final local vars, final method parameters. - non static local class can access members of the enclosing class. - can use EnclosingClassName.this.member - static local class can access static members of the enclosing class. - can extend other classes and can themselves be extended. - methods can return an instance of a local class. The local class must be assignable to the return type of the method. It cannot be same as class type, as the class is not accessible. Often a supertype is used... - Creating an instance of a non static ~ requires instance of encl class. - Anonymous Classes - do not have a name: cannot define constructors: use instance initializer. - defined at the location at which they are instantiated. - context determines if class is static. static is not used explictly. - can be used to extend a class: new SuperClass(...) { /* class decl */ } - can implement an interface: use InterfaceName in place of SuperClass. - cannot not have extends/implements word. Can implement only one interface - similar to local classes. CHAPTER 8: Object Lifetime ~~~~~~~~~~~~~~~~~~~~~~~~~~ - An object can be elligible for garbage collection even if it being refered, as long as the objects containing the refs are also elligible for GC. - Garbage Collector (GC) may or may not call finalize. - Atmost finalize is called only once. - Any exception (thrown out) by finalize, when invoked by GC is igored. - finalize of sub class should explictly call finalize of super class. - overridden finialize cannot throw checked exception - will be caught by GC. - if any checked exception is thrown during execution of a static initializer expression, it must be handled within the initializer expression. In case of instance initializer, if an exception is not caught, it must be specified in throws clause of all contructors. Instance initializer block of anonymous class can throw any exception. - an initializer block *cannot* make a forward reference to a var. - Initializer blocks are executed in the order in which the instance member variables are defined in a class - can result in logical errors. - Instance initializer block is executed before the last constructor in chain. - if a final member is left uninitialized, it must be init when obj is made. CHAPTER 9: Threads ~~~~~~~~~~~~~~~~~~ - daemon threads - setDeamon(boolean) before start of thread. - used to serve user threads - program does not wait for them to finish: terminated at the end. - In GUI app, an AWT thread is automatically created to monitor user activity. - To create thread, make class implements Runnable, override run method, create Thread object with this class, call start() of Thread object. - To create thread, make class extends Thread, override run(), call start(). - implements Runnable is prefered: can extends other class, lesser overhead. - When run() ends, thread stops. *not* start(). - only methods or blocks can be synchronized (classes & data cannot). For a method, specify synchronized modifier, for synchronising only a block use, synchronized (data_member) { /* code block */ } - when a thread is inside a sync method, any thread that wishes to execute this or any other sync method of the same object must wait.... - while in waiting state, a thread releases monitor, gets it when resumes. - wait() series, notify(), notifyAll() must be executed in synchronized code, otherwise the call will result in IllegalMonitorStateException. - A waiting thread(s) must be notified by other thread(s), in order to resume. CHAPTER 10: Fundamental Classes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Wrapper classes of primitive data types: (barring obvoius exceptions) - 2 constructors (except Character class) - take primitive value and return object - take string representation and return object - has a valueOf(String) fn. eg. Integer.valueOf("1873"); - have data conversion functions - have MIN_VALUE and MAX_VALUE, Boolean.TRUE, Boolean.FALSE - Character class has ctype.h functionality - *All* instances of *all* wrapper classes are *immutable*. - White Spaces are all characters with value less than the space character. - Both String and StringBuffer are thread safe, final, sub classes of Object. CHAPTER 11: Collections ~~~~~~~~~~~~~~~~~~~~~~~ - group of objects treated as single unit CHAPTER 13: Layout Managers ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - layout managers might not honor a component's prefered size. - layout managers give precedence to placement to prefered size - to stops componets from being streched - put them in a panel and then add CHAPTER 14: Event Handling ~~~~~~~~~~~~~~~~~~~~~~~~~~ - super class of all events in java.util.EventObject has Object getSource(); - event classes are stored in java.awt.event package - high level (sementic) events represent user iteraction with GUI. - low level events are sequence of events that might happen for an event. - Each listener interface extends the java.util.EventListener interface. - event source informs event listeners about events when they occur. - An event source maintains a list of event listener for each type of event that it can generate. sub classes of event sources can generate same events as super classes. Event sources transmit the same event regardless of thier location in the component heirarchy. - The events generated by source are *also* generated by subclasses of it. - There can be more than 1 listener for 1 event. - PaintEvent is *not* handled in the Event Listener Model. - to create a listener, implement an interface, and override it listener fn. - ActionListener - actionPerforment(ActionEvent); - AdjustmentListener - adjustmentValueChanged(AdjustmentEvent); - ItemListener - itemStateChanged(ItemEvent); - TextListener - textValueChanged(TextEvent); - ComponentListener - componentHidden(ComponentEvent); componentMoved(ComponentEvent); componentResized(ComponentEvent); componentShown(ComponentEvent); - ContainerListener - componentAdded(ComponentEvent); componentRemoved(ComponentEvent); - FocusListener - focusGained(FocusEvent); focusLost(FocusEvent); - KeyListener - keyPressed(KeyEvent); keyReleased(KeyEvent); keyTyped(KeyEvent); - MouseListener - mouseClicked(MouseEvent); mouseEntered(MouseEvent); mouseExited(MouseEvent); mousePressed(MouseEvent); mouseReleased(MouseEvent); - MouseMotionListener - mouseDragged(MouseEvent); // *not* MouseMotionEvent mouseMoved(MouseEvent); - WindowListener - windowActivated(WindowEvent); windowClosed(WindowEvent); windowClosing(WindowEvent); windowDeactivated(WindowEvent); windowDeicionified(WindowEvent); windowIconified(WindowEvent); windowOpened(WindowEvent); - An Event Adapter class implements empty methods for all (low level) interfaces. A listener can subclass an Adapter and can override only the reqd. method, instead of implementing an interface and implementing all methods. The following adapters are defined: ComponentAdapter, ContainerAdapter,FocusAdapter, KeyAdapter, MouseAdapter, MouseMotionAdapter and WindowAdapter. The remainig have only one method, so no use making adapters for them. - Anonymouse classes provide an elegant solution for creating listeners. - LowLevel Event processing: Page 441. EXCEPTIONS ~~~~~~~~~~ - ArithmeticException (div by 0) - ArrayIndexOutOfBoundsException - NullPointerException - ClassCastException - IllegalArgumentException - NumberFormatException - IllegalThreadStateException // change state of started thread - InterruptedException // thread's sleep/wait is interrupted - StringIndexOutOfBoundsException // String::charAt, StringBuffer operations - UnsupportedOperationException // Collection interface Classes ~~~~~~~ Object{ *protected* void finalize() throws *Throwable*; protected clone(); boolean equals(Object); // 2 refs denote same object int hashCode(); // unique hashcode for an object Class getClass(); // gets runtime class String toString(); // @ // for threads void wait() throws InterruptedException; void wait(long timeout) throws InterruptedException; void wait(long timeout, int nanos) throws InterruptedException; void notify(); void notifyAll(); } interface Throwable{ String ; } Exception extends Throwable; OurExceptionClass extends Exception; System{ static gc(); // call to start garbage collector } interface Runnable{ public void run(); } Thread implements Runnable{ final MIN_PRIORITY = 1; final MAX_PRIORITY = 10; final NORM_PRIORITY = 5; Thread(Runnable targetThread); // constructor takes runnable class Thread(Runnable targetThread, String ThreadName); String getName(); void setPriority(proirity); int getPriority(); setDeamon(boolean); start(); static yield(); // give up CPU -> move to Ready To Run public static void sleep(long millisecs) throws InterruptedException; boolean isAlive(); void join() throws InterruptedException; // wait for thread to end // a.join() makes current thread wait for thread a } Math{ // constants E; // value of e PI; // value of pi static T abs(T); // int long float double static double ceil(double); static double floor(double); static int round(float); static long round(double); static T min(T a, T b); // int long float double static T max(T a, T b); // int long float double static double pow(double, double); static double exp(double); static double log(double); static double sqrt(double); // NaN for -ive and NaN static double random(); // >= 0.0 and < 1.0 static double sin(double); static double cos(double); static double tan(double); } String { String(); String(String s); String(char []); int hashCode(); int length(); char charAt(int index); boolean equals(Object); boolean equalsIgnoreCase(String); int compareTo(String); // < 0, == 0, > 0 int compareTo(Object); // < 0, == 0, > 0 // ClassCastException String toUpperCase(); String toUpperCase(Locale); String toLowerCase(); String toLowerCase(Locale); String concat(String); String replace(char old, char new); // replace all characters String trim(); // all white spaces from front and end. String subString(int startIndex); String subString(int startIndex, int endIndex); static String valueOf(T);// Object char[] bool char int long float double // searching int indexOf(int ch); // -1 on error int indexOf(int ch, int fromIndex); // -1 on error int indexOf(String str); // -1 on error int indexOf(String str, int fromIndex); // -1 on error // seach from end int lastIndexOf(int ch); // -1 on error int lastIndexOf(int ch, int fromIndex); // -1 on error int lastIndexOf(String str); // -1 on error int lastIndexOf(String str, int fromIndex); // -1 on error } StringBuffer{ StringBuffer(); StringBuffer(String); StringBuffer(int length); String toString(); int hashCode(); int length(); void setLength(int); int capacity(); void ensureCapacity(int); char charAt(int index); void setCharAt(int, char); // change content of object // the following will *NOT* change the contents of this object StringBuffer append(Object); StringBuffer append(String); StringBuffer append(char[]); StringBuffer append(char[], int offset, int len); StringBuffer append(T); // bool int long float double StringBuffer insert(int offset, T); // Object String char[] boolean StringBuffer insert(int offset, T); // char int long float double StringBuffer deleteCharAt(int index); StringBuffer delete(int start, int end); StringBuffer reverse(); } // AWT Dimension{ int width, height; } Point{ int x,y; } Rectangle{ int x, y, width, height; } abstract Component{ // super class for all non menu related components Dimension getSize(); void setSize(Dimension); void setSize(int width, int height); Point getLocation(); // top-left corner void setLocation(Point); void setLocation(int x, int y); Rectangle getBounds(); void setBounds(Rectangle); void setBounds(int x, int y, int width, int height); void setForeground(Color); // text on component void setBackground(Color); // area used by component Font getFont(); void setFont(Font); // text void setEnabled(boolean); void setVisible(boolean); void add(PopupMenu); addComponentListener(ComponentListener); removeComponentListener(ComponentListener); addFocusListener(FocusListener); removeFocusListener(FocusListener); addKeyListener(KeyListener); removeKeyListener(KeyListener); addMouseListener(MouseListener); removeMouseListener(MouseListener); addMouseMotionListener(MouseMotionListener); removeMouseMotionListener(MouseMotionListener); } abstract Container extends Component{ // contains other components, containers LayoutManager getLayout(); void setLayOutManager(LayoutManager); Component add(Component); Component add(Component, int index); void add(Component, Object constraints); void add(Component, Object constraints, int index); void remove(int index); void remove(Component); void removeAll(); void invalidate(); void validate(); addContainerListener(ContainerListener); removeContainerListener(ContainerListener); } Panel extends Container{ // pack other components and panels - component tree } java.applet.Applet extends Panel{ } Window extends Container{ // no titles menus or borders void pack(); // inits the layout management of the subcomponents void show(); // make window visible void dispose(); // free windowing resources addWindowListener(WindowListener); removeWindowListener(WindowListener); } Frame extends Window{ // resizable moveable title-bar icon menu // can contain panels Frame(); Frame(String title); void setMenuBar(MenuBar); } Dialog extends Window{ // resizeable title-bar border modal *no* menu / icon // initially invisible, modal by default Dialog(Frame parent); Dialog(Frame parent, boolean modal); Dialog(Frame parent, String title); Dialog(Frame parent, String title, boolean modal); } // AWT-GUI control components Button extends Component{ Button(); Button(String text); String getLabel(); void setLabel(String); addActionListener(ActionListener); removeActionListener(ActionListener); } Canvas extends Component{ // generic component: super class of new components // override public void paint(Graphics g) in sub class } CheckboxGroup{ // *not* a subclass of component Checkbox getSelected(); void setSelected(Checkbox); } Checkbox extends Component{ // also used as radio buttons Checkbox(); Checkbox(String); Checkbox(String, boolean checkbox_state); Checkbox(String, boolean, CheckboxGroup); // radio buttons: single group boolean getState(); void setState(boolean); String getLabel(); void setLabel(String); CheckboxGroup getCheckboxGroup(); void setCheckboxGroup(CheckboxGroup); addItemListener(ItemListener); removeItemListener(ItemListener); } Choice extends Component{ // combo box void add(String item); int getItemCount(); String getItem(int); int getSelectedIndex(); String getSelectedItem(); void select(int pos); void select(String); addItemListener(ItemListener); removeItemListener(ItemListener); } Label extends Component{ // non selectable text public static final int LEFT; public static final int CENTER; public static final int RIGHT; Label(); Label(String text); Label(String text, int alignment); String getText(); void setText(String); int getAlignment(); // text alignment void setAlignment(int); } List extends Component{ // listbox // scroll bar appears when necessary // clicking on item selects / disselects item List(); List(int rows); List(int rows, boolean multipleMode); void add(String); void add(String, int index); int getRows(); boolean isMultipleMode(); int getItemCount(); String getItem(int); String[] getItems(); int getSelectedIndex(); String getSelectedItem(); // -1 if none String[] getSelectedItems(); void select(int); void select(String); void deselect(int); addActionListener(ActionListener); removeActionListener(ActionListener); addItemListener(ItemListener); removeItemListener(ItemListener); } Scrollbar extends Component{ public static final int HORIZONTAL; public static final int VERTICAL; Scrollbar(); Scrollbar(int orientation); Scrollbar(int orientation, int value, int visible, int min, int max); // visible width of slider int getValue(); void setValue(int); int getMinimum(); void setMinimum(int); int getMaximum(); void setMaximum(int); int getVisibleAmount(); void setVisibleAmount(int); int getUnitIncrement(); void setUnitIncrement(int); int getBlockIncrement(); void setBlockIncrement(int); addAdjustmentListner(AdjustmentListner); removeAdjustmentListner(AdjustmentListner); } TextComponent extends Component{ String getText(); void setText(String); String getSelectedText(); boolean isEditable(); void setEditable(boolean); } TextField extends TextComponent{ // textbox - single line TextField(); TextField(String); TextField(int length); TextField(String, int length); String getColumns(); void setColumns(int); addActionListener(ActionListener); removeActionListener(ActionListener); addTextListener(TextListener); removeTextListener(TextListener); } TextArea extends TextComponent{ // textbox - multiple lines public static final int SCROLLBARS_BOTH; public static final int SCROLLBARS_NONE; public static final int SCROLLBARS_VERTICAL_ONLY; public static final int SCROLLBARS_HORIZONTAL_ONLY; TextArea(); TextArea(String); TextArea(int rows, int cols); TextArea(String, int rows, int cols); TextArea(String, int rows, int cols, int scrollbars); String getColumns(); void setColumns(int); addTextListener(TextListener); removeTextListener(TextListener); } abstract MenuComponent{ } MenuBar extends MenuComponent{ // contains pull down menus - Menu objects // can be attached to a Frame Object void add(Menu); coid remove(Menu); } MenuItem extends MenuComponent{ // text label and keyboard shortcut addActionListener(ActionListener); removeActionListener(ActionListener); } Menu extends MenuItem{ // container of menu items // can be nested: sub menus void add(MenuItem); // or checkBoxMenuItem void addSeperator(); } CheckBoxMenuItem extends MenuItem{ addItemListener(ItemListener); removeItemListener(ItemListener); } PopupMenu extends Menu{ } interface LayoutManager{ } FlowLayout implements LayoutManager{ // row major order // default for panel (and applets) // always honors component's prefered size - crop to fit in window public static final int LEFT; public static final int CENTER; public static final int RIGHT; // default align - center, gaps 5 pixels each FlowLayout(); FlowLayout(int align); FlowLayout(int align, int horizontal_gap, int vertical_gap); } GridLayout implements LayoutManager{//components in rectangular grid row order // 1 component per cell, all cells have same dimensions // component is resized to fill cell // if col is 0, then any number of cols and vice versa GridLayout(); // 1 row 0 col GridLayout(int rows, int cols); // defalut gaps - 0 pixels GridLayout(int rows, int cols, int horizontal_gap, int vertical_gap); } BorderLayout implements LayoutManager{// north south east west center(default) // default layout manager for Frame. // Send diection in constraints while adding, order of adding: irrelevent // not all regins need to be occupied, last comp. added to regin is shown // components will strech to fill - will try to honor prefered size // default region is center - center component will be streched to fill. public static final String NORTH = "North"; // Constraints public static final String EAST = "East"; public static final String SOUTH = "South"; public static final String WEST = "West"; public static final String CENTER = "Center"; BorderLayout(); BorderLayout(int horizontal_gap, int vertical_gap); } CardLayout implements LayoutManager{ // stack - only one visible // gaps between edges and components - default 0; CardLayout(); CardLayout(int horizontal_gap, int vertical_gap); void first(Container parent); void next(Container parent); void last(Container parent); void previous(Container parent); void show(Container parent, String name); // name added as constraint } GridBagLayout implements LayoutManager{ // custom - rect grid - multiple cells // components can occupy several rows and cols. // components are added to container using GridBagConstraints object(s) // single GridBagConstraints object can be used to fill all components } GridBagsConstarints{ // default alignment - center, weights - 0 public static final int NORTH; public static final int EAST; public static final int SOUTH; public static final int WEST; public static final int NORTHEAST; public static final int NORTHWEST; public static final int SOUTHEAST; public static final int SOUTHWEST; public static final int NONE; // for fill public static final int BOTH; public static final int HORIZONTAL; public static final int VERTICAL; GridBagsConstarints(); GridBagsConstarints(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, Insets insets, int padx, int pady); int gridx; // location - the cell location int gridy; int gridwidth; // dimensions - number of cells occupied int gridheight; double weightx; // growth factor - how much will they expand in cell double weighty; int anchor; // direction int fill; Insets insets; // external padding around components int padx; // internal padding int pady; } // AWT Event Handling Classes class java.util.EventObject { Object getSource(); // source of the message } abstract class java.awt.AWTEvent extends EventObject{ int getID(); // tells what event occured } ActionEvent extends AWTEvent{ // high level event // Button-click List-dbl_click MenuItem-select TextField-Enter public static final int SHIFT_MASK; public static final int CTRL_MASK; public static final int META_MASK; public static final int ALT_MASK; String getActionCommand(); // cmd-name: button label, list item name // menu item name, text int getModifiers(); // get shift meta ctrl alt keys status } AdjustmentEvent extends AWTEvent{ // high level event // generated by ScrollBar-adjustment int getValue(); } ItemEvent extends AWTEvent{ // high level event // generated when item is selected / disselected // for CheckBox CheckBoxMenuItem Choice List Object getItem(); int getStateChanged(); // tells current status - after event public static final int SELECTED; public static final int DESELECTED; } TextEvent extends AWTEvent{ // high level event // generated by change in TextArea TextField } ComponentEvent extends AWTEvent{ // low level event // when a component is hidden, shown, moved, resized // normally handled internally by AWT Component getComponent(); } ContainerEvent extends ComponentEvent{ // low level event // when a component is added to container or removed from container // normally handled internally by AWT } FocusEvent extends ComponentEvent{ // low level event // when component gains or losses focus public static final int FOCUS_LOST; // check with return from getID(); public static final int FOCUS_GAINED; // check with return from getID(); boolean isTemporary(); // if focus is temporary } PaintEvent extends ComponentEvent{ // low level event // when a component should have its paint() / update() method invoked // normally handled internally by AWT } WindowEvent extends ComponentEvent{ // low level event // generated when operation performed on a window - getID(); public static final int WINDOW_OPENED; public static final int WINDOW_CLOSED; public static final int WINDOW_ICONIFIED; public static final int WINDOW_DEICONIFIED; public static final int WINDOW_ACTIVATED; public static final int WINDOW_DEACTIVATED; public static final int WINDOW_CLOSING; // call setVisible(f) or dispose() Window getWindow(); } abstract InputEvent extends ComponentEvent{ getWhen(); // get time of event } KeyEvent extends InputEvent{ // low level event // user presses or releases a key public static final int KEY_PRESSED; // check with return from getID(); public static final int KEY_RELEASED; // check with return from getID(); public static final int KEY_TYPED; // check with return from getID(); int getKeyCode(); // for KEY_PRESSED & KEY_RELEASED char getKeyChar(); // for KEY_TYPED } MouseEvent extends InputEvent{ // low level event public static final int MOUSE_PRESSED; // check with return from getID(); public static final int MOUSE_RELEASED; // check with return from getID(); public static final int MOUSE_CLICKED; // check with return from getID(); public static final int MOUSE_DRAGGED; // check with return from getID(); public static final int MOUSE_MOVED; // check with return from getID(); public static final int MOUSE_ENTERED; // check with return from getID(); public static final int MOUSE_EXITED; // check with return from getID(); int getX(); int getY(); Point getPoint(); // effected by translatePoint() void translatePoint(int dx, int dy); // moves mouse coordinates int getClickCount(); // useful for dbl clicks } Graphics{ void drawRect(int x, int y, int width, int height); void drawString(String, int x, int y); } // Collections interface Iterator { boolean hasNext(); Object next(); void remove(); // optional } interface Collection{ int size(); boolean isEmpty(); boolean contains(Object); boolean add(Object); // optional boolean remove(Object); // optional boolean containsAll(Collection); boolean addAll(Collection); // optional boolean removeAll(Collection); // optional boolean retainAll(Collection); // optional void clear(); // optional Object[] toArray(); Object[] toArray(Object[]); // store in this, fill remaining with null. // if array is nor big, an array of same run // time type is created and returned. Iterator iterator(); } interface Set extends Collection{ // implemented by java.util. HashSet, Set } class HashSet implements Set{ HashSet(); HashSet(Collection); HashSet(int initialCapacity); HashSet(int initialCapacity, int loadFactor); } interface List extends Collection{ // implemented by java.util. ArrayList, Vector, LinkedList Object get(int index); Object set(int index, Object); // optional void add(int index, Object); // optional Object reove(int index); // optional boolean addAll(int index, Collection); // optional int indexOf(Object); int lastIndexOf(Object); LEFT AT PG 333 } interface SortedSet extends Set{ // implemented by java.util.TreeSet } interface Map{ // key value to object mapping // implemented by java.util. HashMap, HashTable } interface SortedMap extends Map{ // implemented by java.util.TreeMap } class java.util.Collections { static int binarySearch(List, Object key); static void fill(List, Object); // replace all elements in List static void shuffle(List); // randomly shuffles static void sort(List); } Chapter Correct Total Percentage 1 9 9 100 2 10 11 91 3 10 19 53 4 17 28 61 5 18 23 78 6 22 27 82 7 6 8 75 8 4 10 40 9 10 13 77 10 12 24 50 12 14 18 78 13 11 16 69 14 11 17 65 Average: 71 Wrong: 2 :11 3 :5,6,7,11,12,13,16,19 4 :4,6,8,11,13,14,15,20,25,26,28 5 :3,4,7,14,18 6 :12,13,15,25,26 7 :5,6 8 :1,3,4,5,8 9 :6,7,13 10 :2,3,4,6,7,11,12,15,17,18,21,23 12 :1,7,10,17 13 :1,7,9,12,13 14 :1,4,9,15,16,17