Chapter 5 Study Sheet
Null Reference - an
object which currently does not have a valid memory address
This Reference - a reference that points to the object that called
the method
for example - if you have an object called doIt which calls a method
labeled
tryThis - such as doIt.tryThis() -- the this reference inside the
method tryThis refers to
the doit object.
int,double,and boolean store values
al other objects store memory address
-an object points to a memory address
so when passing an int,double,boolean to a method you are passing a
copy of the value - any change to value is not made back in calling
method..
objects pass memory address - changes are permanent!
aliases - when two or more objects point to same memory address.
object called blue object called green
green = blue; //both point to same memory address - change one
change both
Exceptions - certain runtime errors which Java handles (catches) by
printing
out error type, and a call stack trace - some types:
NullPointerException, Arithmetic (Div by Zero) Exception
Interfaces - a collection of abstract methods (methods with just a
header - no body)
and possibly constants -- if you implement the interface in your
class, you must provide a body
for each method.. it is a way to provide standard functionality
across a system..
you can use more that one interface in a class.. implements Action,
Comparable
you need to know two built-in interfaces in Java
Comparable Interface
which has compareTo method in it.
public int compareTo(Object obj);
you must always cast the obj to the object type you are working
with..
compareTo must return a zero if both are same... you decide what
makes the objects the same.
non-Zero for not equal.. List Interface we will re-visit in
Chapter 6
Static..
Static variables - vars defined at top of class with static modifier
are called class
vars they maintain their value from object to to object -- used for
keeping a counter of
how many objects being created -- also see in constants..
for example:
public class Nick {
private int amount; //an instance var -- new copy made
for each new object
private static int count; // a class var only one copy
per class -- maintains value from object to object..
Static Method
a method declared with static modifier is at class level
the method can be called directly from class like methods in Math
Class
static methods can not use object's instance vars..
they can access static vars; other non-static methods can not
private static int count;
public static int doIt() {
count++;
}
in Main Driver if class called Bill
to call doit -- just use class name -- no need to create an object
so Bill.doIt();
|