Java Flashcards
things an object knows about itself
instance variable
represents object’s state
things an object can do
methods
blueprint for an object
class
class describes what an object ………… and what an object ……….
knows
does
a method uses ……….. A caller passes ……….
parameter
arguments
java is pass-by-………..
value
that means pass-by-copy
getters and setters
accessors and mutators
access modifiers
public
private
hide data
private
declared inside class
instance variables
declared inside method
local variable
local variables …………. initialized before use
must be
check if two objects are equal
.equals()
to compare two primitives
==
a class can have any number of
instance variables
getter setter methods
a method can have only one
return
these help create encapsulation
getter
setter
private
public
convert String to int
Integer.parseInt(string);
iterate in array (enhanced for loop)
for(int cell : locationCells){……….}
get array length
array.length
Math.random()
returns a random number from 0 to just less than 1
while loop is good
when you don’t know how many times to loop and just want to keep going while some condition is true
ArrayList
add(Object elem) - adds elem to the list
remove(int index), remove(Object elem)
contains(Object elem) - returns true if there is a match for the object parameter
isEmpty()
indexOf(Object elem) - returns either the index of the object parameter or -1
size()
get(int index)
ArrayList over arrays
size changes dynamically
can remove elements
ArrayList is less efficient