Objects & Classes
In the last section we made sparing use of any object other than the predefined data type
String used in the
main() method parameter list. The main emphasis of the Beginning Java6
section of the site was an introduction to the basic building blocks required to write a java program. Most of the exercises involved running the
main() method, to highlight features of the language such as
conditional and looping statements. Hopefully performing these tasks has become second nature through the various coding, tests and quizzes we did in that section.
But Java is so much more than this and at its very core is the concept of classes that define the state and behaviour of objects. From the Java perspective, the class forms the basis of the object-oriented programming paradigm. A well designed class should define a logical entity that fits a particular requirement within the application as a whole. For example a customer class may hold customer information but the history of Greece and the colour of cheese is irrelevant, unconnected and should not be included within the customer class. We will go into more details of this when we cover OO concepts, for now lets think of a class as a template for an object. The class holds data relevant to the object in question and code that processes that data. We place the code for processing the data into methods. The data and methods of a class, more commonly known as members, are what make up the building blocks of an object. With the members defined we have the blueprint to create (instantiate), interrogate and modify the state of an object. Of course this blueprint is an abstraction and no instances of an object exist until we actually instantiate them within a class.
We will cover the concepts paragraphed above as we work our way through the lessons in this section, but we will we start it by looking at a predefined data type, the
Array object. Investigation of this class will
give us an insight into using objects and classes before we start to create our own.
In this lesson we start our investigation of objects and classes by looking at arrays and how to use them. In Java the predefined data type
Array object is used for array manipulation. Investigation of this
object will give us an insight into using classes before we start to create our own.
This lesson looks at class structure and the syntax required for class construction.
Java comes with two types of variables to choose from, primitives and reference. In this lesson we look at reference variables and how to use them in Java. We discussed primitive variables in the Beginning Java6 section in the Primitive Variables lesson.
We have used methods throughout the lessons so far, so its time for a thorough investigation of what we can do with these members.
This lesson is about instance variables, how to use them and their scope.
Up until now we haven't really worried about our data and how we protect it from the outside world. That is all about to change as we look at encapsulation.
We have used the static keyword throughout the lessons so far, in this lesson we investigate what static means and how to apply it to our class members.
In this lesson we go through enumerations which are also known as enumerated types or enums and were introduced in Java6.