In the olden days, not only did we have to walk a mile in the chilling winds of a snowstorm to get to school (hey our grandparents had it rougher; they had to do it to get to day care), we also had to make programs without buttons and scrollbars. Now, of course, we have object-oriented programming. This article will introduce you to the most important concepts as they relate to Java.
Simply put, when you change the state of an object, you ask it to perform a behavior. An object stores its states in a field (commonly referred to as variables, which will be discussed in further depth later) and demonstrates its behaviors through methods (known as functions, also covered later).
When you press the power button on your computer, it places it in the On state. Because we have changed the state of the computer (from Off to On), we have also initiated certain behaviors from the computer. In this case, the power comes on, the fans within the computer turn on, and the system bios, followed the hard drive, etc. all become active.
Note that an object can only have the states and behaviors you place upon it. I cannot press the on button of my computer and receive a bologna sandwich unless the programmer coded that in. (Note to self: add bologna sandwich dispenser to computer).
Benefits of Objects
Aside from being shiny and fun to look at, objects within a program offer several benefits.
Modularity: You can write the code for the object within the object itself, keeping it separate from other coding, while still being able to call upon it at any time.
Hiding Information: Planting your code within your object makes it less visible to the user.
Reuseability: Once created, an object can be copied and used again and again without having to go through the process of remaking it.
Debugging Made Simple: Objects make debugging easier in some instances. If you track the problem to a button within your application, you can simply remove the button and remake it, instead of having to delve into your main code.