Algorithms 1.2 Flashcards
Object-oriented programming
Based on building data types
Data type
A set of values and a set of operations on those values
Abstract data type
a data type whose internal representation is hidden form the client
Objects
an entity that can take on a data-type value
Characterization of objects (3 properties)
1) State of an object- value from its data type
2) Identity of an object distinguishes one object from another
3) behavior of an object is the effect of data-type operations
reference
a mechanism for accessing an object
API
list of constructors and instance methods
client
program that uses a data type
implementation
the code that implenets the data type specified in an API
Creating an object for a abstract data type
First, you must create an object my invoking a constructor ( new). Everytime a client uses new the system allocates memory space for the object, initializes its value and returns a reference to the object
Invoking instance methods
e.g. heads.tally () - tails.tally
Assignment Statements
A copy of a reference can be created. Leads to a situation called aliasing
Objects as arguments
Objects can be used as arguments
Objects as return values
An object can be used as a return value from a method
Arrays are objects
Every value of any nonprimitive type is an object. E.g. arrays are objects
Arrays of Objects
An array can also be filled with objects. Create by using the bracket syntax for array constructors and than create each object
Constructors
establishes an object’s identity and initializes the instance variables
Immutable
data type which has the property that the value of an object never changes. Accomplished using “final”
Arithmetic Exception
Thrown when an exceptional arithmetic condition occurs
ArrayIndexOutOfBoundsException
Thrown when an array is accessed with an illegal index
NullPointerException
Thrown when null is used where an object is required
OutOfMemoryError
Thrown when the java virtual machine cannot allocate an object because it is out of memory
StackOverflowErrorw
Thrown when a recursive method recurs too deeply