J2EEOnline J2EE 






Java TM Fundamentals I  «Prev  Next»
Lesson 1

Introduction to Object Oriented Programming in Java

Java is an OOP language, which means that Java programs are developed as groups of interrelated objects. This module introduces you to object-oriented programming (OOP) and the role it plays in Java.
OOP concepts such as objects, classes, inheritance, and methods will be discussed. The coverage of each concept is followed up by example Java code.
The OOP skills you will learn in this module provide a background that is necessary when it comes to developing effective Java programs.

Module learning objectives

After completing the module, you will have the skills and knowledge necessary to:
  1. Understand the relationship between classes and objects
  2. Create simple class definitions
  3. Add behavior to classes using methods

What Is an Object?

Objects are key to understanding object-oriented technology. Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle.
Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.
Take a minute right now to observe the real-world objects that are in your immediate area. For each object that you see, ask yourself two questions:
  1. "What possible states can this object be in?" and
  2. "What possible behavior can this object perform?".
Make sure to write down your observations. As you do, you will notice that real-world objects vary in complexity; your desktop lamp may have only two possible states (on and off) and two possible behaviors (turn on, turn off), but your desktop radio might have additional states (on, off, current volume, current station) and behavior (turn on, turn off, increase volume, decrease volume, seek, scan, and tune). You may also notice that some objects, in turn, will also contain other objects. These real-world observations all translate into the world of object-oriented programming.