1/14
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Data Fields
Used to store data, usually within an object.
Defines state of the object
Declared within class body with an ACCESS modifier, a data type, and name
Variables declared WITHIN a class but NOT A METHOD
Define the characteristics of an object created from the class.
Ex) public class Bug {
private int myX;
private int myY; //myX and myY store values and give characteristics of Bug object
}
Constructors
A special type of data field that initializes new objects of a class. Sets initial values of data fields.
Ex)public Bug() {
myX = 0;
myY = 0;
}
public Bug(int x, int y) { // accepts arguments for int x and int y, defined above
myX = x;
myY = y;
}
Buffer
A temporary storage area for drawing the image (off-screen) which is then “pasted” onto the screen at the end.
Eliminates images that flicker in animation, where there are lots of drawing commands.
Instance Variables
Variables belonging to a specific object or INSTANCE of a class. Makes copies so each object has it’s own copy. Declared in the class but not a part of the methods, constructors, or blocks.
Represent the state or attribute of an object. They define the characteristics of an object.
Ex) Class car { //class name
String color //instance variable
int speed; }
Final
Means it is marked CONSTANT. It cannot be changed unless it is deleted.
What are fields in Java?
Fields are variables created and used by a class. They represent data or attributes associated with the class.
Declared within a class but outside of methods.
Ex) private field, public field
What does a void method do?
It does not return a value but takes action.
Instance Method
Where the individual objects own the method. No static keyword is found, and there may be multiple unique copies owned by each object.
Class (static) Method
Add powers to the class, not to the objects. Remain with the class and do not get duplicated in each object. There is exactly one copy of a static method which is owned by the class.
Boolean
Returns a True or False value.
Integer
Returns an integer value. (Including 0)
Double
Returns a decimal value.
Modifier Methods
Change data in an object’s fields. AKA “setter” methods, usually begin with “set”.
Ex)
smidge.setColor(Color.YELLOW); // tells Smidge to set it’s color to YELLOW
smidge.setThickness(10); // tells Smidge to set it’s thickness to 10
Accessor Methods
Retrieve values of private fields outside the class without direct manipulation of the data inside. Controls and asks “who can access this class?”.
Get data from the object’s fields. AKA “getter” methods, usually begin with “get”.
ALWAYS return a VALUE (periodt)
Ex)
getColor()
getImage()
getX() // or getY() in Bug’s case