Class, Object, Field, & Value
Objects(red circle with 5 diameter) are created from classes(circle class). The class describes the kind of object; the objects represent individual instantiations of the class. When you are inspecting different objects, you will notice that objects of the same class are all having the same fields(diameter, xPosition, yPosition, etc) while the actual value of each field in each object may be different.
Methods & Parameters
We can communicate with objects by invoking methods on them. Objects usually do something if we invoke a method. (e.g moveRight(2) is a method) Methods can have parameters to provide additional information for a task. (e.g what inside the parenthesis is parameter, which is 2 in method moveRight(2))
Data Types
Parameters have types. The type defines what kinds of values a parameter can take.
1.5 Enter an unknown color.
The system will output black color when an unknown color is inputed.
1.6 Enter a parameter without quote.
“Error: cannot find symbol – variable green.” This kind of error is called Pitfall which is a common error of forgetting the double quotes when typing in a data value of type String.
Multiple instances
1.7 Change positions, sizes, and colors.
So interesting, isn’t it?
Multiple instances refer to the fact that many similar objects can be created from a single class. (e.g The green big circle and the yellow small circle are multiple instances of circle class.)
State
1.8 Inspect the object
1.9 Different ways to draw this
There are no orders of changing different shapes so the order of drawing varies. For the position these four people. I used moveLeft() and moveRight() methods, however, I can also use slowMoveHorizontal(int distance) methods.
Java Code
Show Terminal
To call a method on an object, we write the name of the object, followed by a dot, followed by the name of the method. The sentence ends with a parameter list (write an empty pair of parentheses if there are no parameters).
Show Code Pad
Object Interaction
The Picture class is written so that, when you create an instance, the instance creates two square objects, a triangle, and a circle; moves them around; and changes their color and size, until the canvas looks like the picture we see above.
Objects can create other objects, and they can call each other’s methods. In a normal Java program, you may well have hundreds or thousands of objects. The user of a program just starts the program (which typically creates a first object), and all other objects are created—directly or indirectly—by that object. There is a concept called Method calling which means objects can communicate by calling each other’s methods.
Source Code
Source code of a class determines the fields and methods of each of the objects within that class.
Key Concepts
private String name;
public void setSend(String newSend){
send=newSend;
}
public int getAverage(){
return int average1;
return int average2;
}
Book is a class. Its subject might be subject, pages, author, etc.
No. A class can have several different objects.
Works Cited
Barnes, David. “OBJECTS FIRST WITH JAVA A PRACTICAL INTRODUCTION USING BLUEJ (5TH EDITION).”Objects first with Java. Object first with Java, 16 December 2016.