Member-only story
Understanding Objects and Classes in Java
The goal of objects is to help extend our current capabilities to store and manipulate data. In simple programming examples, primitive types are often good enough, since we are working with single data points such as integers. The typical problems we encounter in day to day programming, however, are different. These problems will typically handle data that is more complex, with many related properties that need to be worked with. Objects and classes will provide us a way to define custom data types to be able to handle any data we encounter.
A class is the programming structure we use to define all the information the program needs to know about our object. A class can be seen as the area where we describe what kind of features the object has, and how we work with the object. It sets out the rules of how an object can be used and interacted with.
Traditionally, an object will have two components related to it.
1. Properties: Properties are things that can be used to describe the object
2. Methods: Methods are things that interact with the object
Let’s look at a simple example of an object definition to better understand this. Suppose that you own a book shop, and you want to create a program that works with book information. To determine the properties of a book, we need to think about the information that helps identify or describe the book. For example, a title could be a property of a book, as well as the author, publisher, and length…