The Big Takeaway Of This Unit
Objects are instances of classes and we can write methods to manipulate these objects.
- Roughly 2 to 3 multiple-choice questions
Java is what is known as an object-orientated programming language, or OOP for short. What is this object-orientated programming, and why is it so important to Java? This is the first of three units emphasizing object-orientated programming (the others are Units 5 and 9, covering classes and inheritance respectively). This unit, we will be learning about objects, the cornerstone of object-orientated programming, and what they are. There are four principles of object-orientated programming: abstraction (partly covered in this unit, also in Unit 5), encapsulation (covered in Unit 5), inheritance, and polymorphism (both covered in Unit 9).
Building Computational Thinking
In this unit, you'll learn how to write your first methods (functions in other programming languages), which perform a specific class. You'll also learn how to use methods from the Math and String classes, which will allow us to work more with numbers and text. These will make the foundations of all future units. Finally, you'll learn about objects, which are reference types: combinations of other data types that allow us to represent actual items and situations.
Main Ideas for This Unit
- Making/Initializing Objects
2.1: Objects: Instances of Classes
Java is an object-orientated programming language, which means that most major programs in Java are about the manipulation of objects. What are objects? Objects are a reference type, which refers to how they are combinations of other primitive and reference data types. When you refer to them, you are not referring to the actual object itself, but where it is stored in data.
How do we know what combination of primitive and reference types each object has? This is due to the help of a class. A class is like a template that defines what an object is like and what the object can do. A class is basically the guidelines for a type of object, and an object is a particular instance of that class. We can think of a class as a blueprint for a house, and the object is a particular house. Different houses are different objects. The different houses may look different, but they have the same general features and functions. This is how classes and objects work.
However, an object is not a type of that class. For example, if the class is Fruit, Strawberry is not an object of Fruit, but it is only a subclass (we'll learn about this more in Unit 9). Objects of the Fruit class are specific items, so a specific strawberry or any other specific fruit are objects of the class. Meanwhile, Strawberry on its own is too broad since there are many individual strawberry objects that exist.