NOTE: These are my definitions and understanding. My understanding may not be completely correct or complete.
Class - a set of objects that have the same properties
Object - a data structure with defined variables and methods
Variable - a defined data instance
Declaration - the initialization of a variable
Assignment - the process of declaring or changing a variable's value
Constructor - a specific method used when initializing a new object from a Class
Accessor - a method that leaves an object's variables unchanged
Mutator - a method that changes an object's variables
private - a method or variable accessible by the object only
public - a method or variable accessible through interfacing with the object
Instance Variable - the variables within each instance of an object
this - an undeclared variable reference to an object
Local Variable - the variables declared within the body of a method
final - used to define constants
Scanner: - a predefined class within Java, requires the import java.util.scanner;statement
- declaration: Scanner var = new Scanner(System.in);
- example method: int i = var.nextInt() //returns the next int input by user
- double d = var.nextDouble() //returns the next double input by user
Sentinel Value - a value that is intended to terminate a user input loop (i.e. "-1" or "done")
NaN - "Not A Number", i.e. an undefined result sometimes thrown at runtime
Double.MIN_VALUE - the smallest positive number a double can represent
-Double.MAX_VALUE - the largest (vector) negative number a double can represent
Reading From Files: - File declaration: File inputFile = new File("input.txt");
- Scanner declaration: Scanner in = new Scanner(inputFile);
ArrayLists: - declaration: ArrayList<TYPE> varName = new ArrayList<TYPE>();
- example method: varName.add(varPointingToTYPE);
- example method: varName.set(index,varPointingToTYPE);
- example method: TYPE foo = varName.get(index);
- example method: int size = varName.size();
- example method: TYPE foo = varName.remove(index);
- for loop on each object in ArrayList: for (TYPE foo : varName) {...}
Properties - instance variables that have get/set methods
Static Methods: - a method that is not called on any object
- Class definition:
public class Foo- call: Foo.addition(int1,int2); //requires Foo Class to be imported in file
{
public static int addition (int a, int b)
{
return a+b;
}
}
Static Variables: - a variable that is not called on any object, used best for constants
- Class definition:
public class Foo { public static final int ONE = 1; }- variable call: int a = Foo.ONE; //requires Foo Class be imported in file
Coupling: - the concept that one Class's compilation and execution is dependent upon another Class
- example: Class A is coupled to Class B if Class A instantiates an instance of Class B
Interface Type: - a type of structure that specifies behavior for any Class that implements it
- declaration: public interface Drawable { void draw(); }
- implementation:
public class Picture implements Drawable{ //Constructor...- use case: if Picture and Class Photo both implement Drawable, then
public void draw() {...} //MUST implement draw method from Drawable}
ArrayList<Drawable> elements = new ArrayList<Drawable>();
element.add(new Picture());
element.add(new Photo());
for (Drawable obj : elements) { obj.draw(); }
Polymorphism - the Object Oriented Programming concept that a single method call on a generic object variable can handle many different Object types (i.e. interfaces)
Encapsulation - the Object Oriented Programming concept that objects can inherit variables and methods from parent Classes
instanceof: - keyword to determine if an element is an instance of a given Class
- example: if (stringVar instanceof String) {..} else {...}
Inheritance: - a Class may extend the behavior of only one parent class
- Example:
public class MammalSuperclass - the parent of a Class (e.g. Mammal is Dog's superclass)
{
private String name;
public Mammal ()
{
name = "";
}
}
public class Dog extends Mammal
{
private int legs;
public Dog ()
{
super();
legs = 0;
}
}
Subclass - the child of a Class (e.g. Dog is Mammal's subclass)
Overloading - when two or more methods have the same name but different parameter types
Overriding - when a subclass has a different implementation of a method that is also in its superclass
No comments:
Post a Comment