ࡱ> -/,7 bjbjUU " 7|7| lHHHHHHH\\l2$ H HH& HH  @ HH 6\f <0lrY Rr \\HHHHJeremy Exleys sheet; Name: _________________________ Class- a type of object. Object or instance- a thing ex. Watch or Chalk . Instance variable- name for piece of data associated w/ object. Instance method- a behavior that an object can perform, things we can ask, where is the big hand?. Constructor method- how to initialize a newly created object. class variable-is at a fixed location in memory, there can only be one copy at any given time. Void-returns nothing useful. Int- returns a value equal to something. Static-a class method. When running a program that may throw an error a try block is necessary. Example of using a try block: IO.println("Type two numbers to divide."); try { int m = Integer.parseInt(IO.readLine()); //-- Interger.parseInt() used to convert a string to an interger int n = Integer.parseInt(IO.readLine()); } catch(NumberFormatException e) { IO.println("That's not a number."); } try { IO.println(m / n); // ERROR: won't compile } catch(ArithmeticException e) { IO.println("I can't divide by zero."); } Program used to tell if a number inputted by the user is Good or Bad public class Example { public static void main(String[] args) { try { IO.print("Type something. "); Integer.parseInt(IO.readString()); IO.println("good"); } catch(NumberFormatException e) { IO.println("bad"); }}} The ArrayList class provides three important methods for putting new data into the ArrayList. void add(Object obj) -Adds obj at the list's end. void add(int index, Object obj) -Inserts obj at index index. Objects past index are shifted up. Object set(int index, Object obj) -Changes object at index index to obj. Returns value previously at index. example ArrayList holding strings representing the numbers from 1 to 10. ArrayList count = new ArrayList(); for(int i = 1; i <= 10; i++) count.add("" + i); Three methods that are useful for accessing information about an ArrayList object. int size() - Returns the number of elements in the list. Object get(int index) - Returns the object at index index of the list. int indexOf(Object obj) - Returns the index of obj in the list, or -1 if not found. It uses the equals() method of obj to determine if two elements are equal. *The get() method returns an Object, and Java won't automatically cast down the inheritance hierarchy. You need to have an explicit casting operator to make this work. String str = (String) count.get(5); public class SavingsAccount extends Account { -A subclass inherits everything from its parent. Everything, that is, except the parent's constructor methods public SavingsAccount(double inter, double initial) { super(initial); interest = inter; -In the parentheses after super is a list of the arguments that should be passed to the appropriate constructor method double to double etc -Polymorphism - objects automatically change form as circumstances warrant. Java won't convert down the inheritance hierarchy. -not sure that it's a SavingsAccount, we could test whether it is first as follows. if(bank.getAccount(0) instanceof SavingsAccount) { ((SavingsAccount) bank.getAccount(0)).addInterest(); *if class B extends A the only way to access methods within A that were over written in B is by explicitly creating a new variable like so- A a = new A(); otherwise when it is created like so-B b=newB(); the method within A cannot be reached. Even if A a = b; is used b was created as a B() so the methods within A will not be reached. 6;Pb*<ghmnvo*u  ! & ) @ J M W \ 8  ! $ / P U d h o { CJaJ0JOJQJ^J0J5OJQJ\^J5OJQJ\OJQJ5CJ\aJ 5CJ\CJO6&o*\*,u @ k !  8 [  d  l\0g  DJ\i 0JOJQJ0J5OJQJ\^J 0JOJQJ5OJQJ\OJQJCJCJaJ0JOJQJ^J 1h/ =!"#$h% i8@8 NormalCJ_HaJmH sH tH :`: Heading 1$@&5CJ\aJ<A@< Default Paragraph Fonte` HTML Preformatted7 2( Px 4 #\'*.25@9CJOJPJQJaJnHtHFg`F HTML TypewriterCJOJPJQJ^JaJF^`F Normal (Web)dd[$\$ PJnHtH&X`!& Emphasis6]"W`1" Strong5\ 6&o*\*,u @k!8[d l \ 0 g 000000000000000000000000000000000000000000000000000     8@0(  B S  ?!)36;KLWdy  ,6Pew  *-<?JMW\8ANW_bcdjkstx%(PUdghowz 2 3 h l 6Nhm36^cu{,7JOw!%NX[^!%dg 4 6  66.3  Tom ExleyMC:\WINDOWS\Application Data\Microsoft\Word\AutoRecovery save of Document1.asd Tom Exley*C:\My Documents\Jeremy\Csci cheatsheet.doc Tom Exley*C:\My Documents\Jeremy\Csci cheatsheet.doc Tom ExleySC:\WINDOWS\Application Data\Microsoft\Word\AutoRecovery save of Csci cheatsheet.asd Tom ExleySC:\WINDOWS\Application Data\Microsoft\Word\AutoRecovery save of Csci cheatsheet.asd Tom Exley*C:\My Documents\Jeremy\Csci cheatsheet.doc Tom Exley*C:\My Documents\Jeremy\Csci cheatsheet.doc Tom Exley*C:\My Documents\Jeremy\Csci cheatsheet.doc@ d  @UnknownG:Times New Roman5Symbol3& :Arial?5 :Courier New;SimSun[SO"qh d&' d&0 !20d!2Q3Jeremy Exley sheet; Name: _________________________ Tom Exley Tom Exley Oh+'0  0< X d p|4Jeremy Exley sheet; Name: _________________________ere Tom Exleyeyom om Normale Tom Exleyey5m Microsoft Word 9.0 @ @v@:D  ՜.+,0$ hp   mycompanyl! 4Jeremy Exley sheet; Name: _________________________ Title  !"#%&'()*+.Root Entry F601TablerWordDocument" SummaryInformation(DocumentSummaryInformation8$CompObjjObjectPool66  FMicrosoft Word Document MSWordDocWord.Document.89q