The perfect place for easy learning...

Java Programming

×

Topics List


Java Classes





Java is an object-oriented programming language, so everything in java program must be based on the object concept. In a java programming language, the class concept defines the skeleton of an object.

The java class is a template of an object. The class defines the blueprint of an object. Every class in java forms a new data type. Once a class got created, we can generate as many objects as we want. Every class defines the properties and behaviors of an object. All the objects of a class have the same properties and behaviors that were defined in the class.

Every class of java programming language has the following characteristics.

  • Identity - It is the name given to the class.
  • State - Represents data values that are associated with an object.
  • Behavior - Represents actions can be performed by an object.

Look at the following picture to understand the class and object concept.

class in java

Creating a Class

In java, we use the keyword class to create a class. A class in java contains properties as variables and behaviors as methods. Following is the syntax of class in the java.

Syntax
class <ClassName>{
    data members declaration;
    methods defination;
}

🔔 The ClassName must begin with an alphabet, and the Upper-case letter is preferred.

🔔 The ClassName must follow all naming rules.


Creating an Object

In java, an object is an instance of a class. When an object of a class is created, the class is said to be instantiated. All the objects that are created using a single class have the same properties and methods. But the value of properties is different for every object. Following is the syntax of class in the java.

Syntax
<ClassName> <objectName> = new <ClassName>( );

🔔 The objectName must begin with an alphabet, and a Lower-case letter is preferred.

🔔 The objectName must follow all naming rules.