class Exception class RunTimeException extends Exception class ArithmeticException extends RunTimeException class IndexOutOfBoundsException extends RunTimeException class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException class StringIndexOutOfBoundsException extends IndexOutOfBoundsException class NullPointerException extends RunTimeException ... class InterruptedException extends Exception class IOException extends Exception class FileNotFoundException extends IOException class SocketException extends IOException ...
http://java.sun.com/j2se/1.4/docs/api/java/lang/Exception.html
"Errors are particularly serious system problems that generally should not be caught. Exceptions are caused by problems that should be caught and processed during program execution to make a program more robust." : "Java How to Program" by Dietel & Dietel
Error
Exception
readLine()
monsters[i].move()
m() { ... try { for( int i = 0; i ... ) { monsters[i].move(); readLine(... ... } catch( exception_class e ) { // put code in this block to handle exception // e.g. simply: e.printStackTrace(); } ... }
ArrayIndexOutOfBoundsException
StringIndexOutOfBoundsException
IndexOutOfBoundsException
throw new exception_class(message_string);
if( denominator == 0 )
throw
try
catch
catch (appropriate_exception_class ...
... main(...) { try { ... m(); ... } catch ( exception_class2 e) { ...} ... }
m()
ArithmeticException
main()
Face
ArrayList
Face[] faces_array ... ;
ArrayList faces_arrlst = new ArrayList();
faces_array = new Face[num];
faces_arrlst.clear();
faces_array[index] = ...
faces_arrlst.add(...);
...faces_array[i]...
...( faces_arrlst.get(i))...
ArrayList.get()
Object
Monster
String
size()
add(index, Object)
remove(index)
set(index, Object)
FaceSmilingBabyHair
int count_of_FaceSmilingBabyHair_ss = 0; for ( int i = 0; i < faces_arrlst.size(); i++ ) if ( faces_arrlst.get(i) FaceSmilingBabyHair ) count_of_FaceSmilingBabyHair_ss++;
life.java
ArrayList al = new ArrayList();
al.add(57); //
int 57
boolean
double
interface
public interface KeyListener { public void keyTyped(KeyEvent ke); public void keyPressed(KeyEvent ke); public void keyReleased(KeyEvent ke); } public interface Comparable { public int compareTo(Object o); /* Compares this object with the specified object for order. * Returns a negative integer, zero, or a positive integer as this * object is less than, equal to, or greater than the specified * object. */ } public interface Enumeration { public boolean hasMoreElements(); // Tests if this enumeration contains more elements. public Object nextElement(); // Returns the next element of this enumeration if this enumeration // object has at least one more element to provide. } public interface MouseListener { public void mousePressed(MouseEvent me); public void mouseClicked(MouseEvent me); public void mouseReleased(MouseEvent me); public void mouseEntered(MouseEvent me); public void mouseExited(MouseEvent me); } public interface List { public void add(Object o); public boolean contains(Object o); public Object get(int index); public boolean isEmpty(); public int size(); . . . } public interface Shape { public boolean contains(double x, double y); public boolean contains(Point2D p); public Rectangle getBounds(); public boolean intersects(Rectangle2D r); . . . }
interface List
LinkedList
Vector
interface Comparable
BigDecimal
BigInteger
Date
interface Shape
Line2D
Polygon
Rectangle
extend
attack()
class Monster
abstract class Monster { ... final void move() { x += dx; y += dy; } abstract void attack(); } class Hobgoblin extends Monster { ... void attack() { player.life -= damaging_amount; } } class Leprechaun extends Monster { ... void attack() { player.gold -= pilfering_amount; } }
Monster.attack()
Monster r = new Monster(XUL, YUL, FIELDSIZE); // ?OK?
r.attack();
new Monster(...)
abstract
Monster [] monsters = new Monster[26]; . . . monster[i].move(); monster[i].attack();
instrs_inherit.java
if ( stress() > respect() )
cope();
receive_email()
CollegeTeacher
cope()
instrs_compos.java
class CollegeTeacher { ... void cope()
public abstract void cope();
class CollegeTeacher
instrs_abstr.java
CollegeTeacher.receive_email()
CollegeTeacher.cope()
Professor.cope()
AsstProf.cope()
respect()
this
Professor
stress()
Instructor