J2EEOnline J2EE 






Java TM Fundamentals I  «Prev 

Understanding objects and classes

In programming terms, an object is a self-contained component that contains properties and methods needed to make a certain type of data useful. The properties of an object are what it knows and its methods represent the services it can provide.
In addition to providing the functionality of the application, methods ensure that an objectís data is used appropriately by running checks for the specific type of data being used. They also allow for the actual implementation of tasks to be hidden and for particular operations to be standardized across different types of objects. You will learn more about these important capabilities in Object-oriented concepts: Encapsulation.
Objects are the fundamental building blocks of applications from an object-oriented perspective and provide a blueprint.


class to an object
class to an object

blueprint
blueprint

class outline object makeup
class outline object makeup


many objects of same kind
many objects of same kind

object instance of class
object instance of class

house specific instance of class
house specific instance of class

Objects in Java:

Let us now look deep into what are objects. If we consider the real-world we can find many objects around us, Cats, Dogs, Humans, etc. All these objects have a state and behavior. If we consider a cat, then its state is - name, breed, color, and the behavior is - purring, sleeping, running.
If you compare the software object with a real world object, they have very similar characteristics. Software objects also have a state and behavior. A software object's state is stored in fields and behavior is shown via methods. So in software development, methods operate on the internal state of an object and the object-to-object communication is done via methods.

Classes in Java:

A class is a blue print from which individual objects are created. A sample of a class is given below:
public class Cat{
  String breed;
  int age;
  String color;

  void purr(){
  }
  
  void hungry(){
  }
   
  void sleeping(){
  }
}