Objects in Java
If you can describe your problem in terms of objects, then there is a solution.
The first object-oriented programming language is Simula-67 which introduces the keyword type of class in programming. Objects that share similar characteristics except for their state during program execution are grouped into a class.
Abstract datatypes (classes) work almost exactly like built-in datatypes. When you create a type of an abstract datatype, you are actually creating an object of that type. You can send messages to the object just as you would a built-in datatype.
Note, when you see a class, think type and vice versa.
From the illustration above, the type (class) is Light, the implementation of the methods ‘on()’, ‘off()’, ‘brighten()’ and ‘dim()’ are hidden from the interface. The object ‘lt’ was sent a message to put the light on, in programming parlance this is called “calling the method on()”.
Once a class is established you can make as many objects of that class as you like, you can send a message to an object by typing the name of the object followed by a period and the message (method) you want it to perform.
A message of a type is determined by the interface of the type, behind a message is a code at the back that details what and how the task is carried out, this is called the implementation.
Most times you would want to hide some parts of your program you don’t want end users to access, parts that are necessary for the internal operation of your data type but not part of the interface that the end users need in order to solve their particular problems.
Java uses 3 explicit keywords to set boundaries in a class or definition that follow the keywords:
Public: means the following element is available to everyone.
Private: means that no one except you can access that element, if you try to access a private type you get a compile time error.
Protected: This acts like private except an inheriting class would have access to protected members.
Java also has a “default” access, which comes into play if you don’t use one of the specifiers mentioned above. It’s important to note that this access is usually called package access because classes in the same package can access other members of other classes, however, outside of the package those members appear to be private.
I’ll stop here for now as a preliminary introduction to objects in Java, this is by no means all there is to objects but should serve as a good base for further studies.


