Java Class, Objects & Identifiers

Java class & identifiers are a crucial part and concept of java. Today we are going to discuss them one by one. Enjoy and stay focused!

Java being an object-oriented programming language supports the following fundamental concepts:

  • Object
  • Class
  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation

Any entity/real-world entity one can think of which has a state and behaviour can be termed as an object. Objects possess a state (value), behaviour (functionality) and Identity. In other words, objects are an instance of a class.

For Ex: Computer is a real-world entity and hence can be termed as an object. Computers can be small, big and can come in any desired colour and different prices. This is called the state of the object, computer. Again, a computer can be used to play video games, learn different subjects, watch movies. This hence is said to be the functions or behaviour of a computer.

java class & identifiers

Java Class

  • A class is a collection of similar types of object.
  • A class is a logical container which never allocated any memory.
  • A class is a blueprint of objects. That is, it is a template from which other objects are created.
  • It is not physical.
  • "Class" is a keyword/reserved keyword in java which is used to design a user-defined class in java. It is a predefined Class present in the package java.lang.
  • A class can be user-defined and predefined (80,000 are present).

For Ex: Here in the below example, Student is a class which is of type public (access specifier) and name, roll, joined, age are its variables.

public class Student {
int roll;
String name;
int age;
Student joined;
}

A class is a collection of 4 types of members in java:

  1. Data member or Variable.
  2. Method member or function.
  3. Block.
  4. Constructor.

Naming convention of Member/Class

Rule: For each word 1st letter is capital.

For Ex:   BufferReader, Class, InputStreamReader

public class Student {
	int roll;	//variable
	
	public Student() {
		//constructor
	}

	void show(){}	//method
	static {}	//block

}



Naming convention of predefined Methods

Rule: Except 1st word, each word's 1st letter should be capital/uppercase.

For Ex:  indexOf(), lastIndexOf()

Naming convention of predefined Constant

Rule: Each letter should be capital.

For Ex: SIZE, MAX_VALUE

Naming convention of predefined Package

Rule: Each letter should be lowercase followed by the package. And the package is separated by a dot(.).

For Ex: java.lang, java.io

Identifiers

Identifiers are the names which are used to represent any variable, class, reference, package, method.

Rules for naming an Identifiers/ Naming conventions

  • No spaces are allowed.
  • All alphabets both uppercase and lowercase are allowed.
  • No special characters are allowed except $(dollar) and _(underscore).
  • Digits are allowed but the name cannot start with a digit.
  • The name should not be a reserved keyword.

Did you know?

There were 50 reserved keywords in Java and in the latest version 48 of them are present(goto, const keywords are deprecated). "Enum" is the recent keyword introduced in Java