A class in Java is a blueprint that defines fields and methods; an object is a live instance of that class created with the new keyword. Every Java program is built from classes and objects. A class holds no data by itself — the object holds real values at runtime.
A class in Java is a user-defined data type that defines the properties and behaviours a particular type of object will have. You write the class once, then create as many objects from it as you need, each with its own data. Understanding class and object in Java is the single most important concept in object-oriented programming, and every Java program you’ll ever write depends on it.
- A class is a template. It defines fields (data) and methods (behaviour) but holds no values by itself.
- An object is a real instance of that class, created at runtime with the
newkeyword, and it holds actual values. - Every class in Java automatically inherits from
java.lang.Object, the root of the entire Java class hierarchy. - A concrete class is any class that provides full implementations of all its methods and can be instantiated directly.
- Strong class design is the foundation for writing secure, maintainable code in roles from backend development to ethical hacking.
What a Class Is
A class in Java is a user-defined data type. Think of it the way an architect thinks of a blueprint: the blueprint describes every room, wall and window, but it isn’t a house you can walk into. The class describes every field and method, but it isn’t an object you can run code against.
The class definition in Java starts with the class keyword, followed by the class name (always capitalised by convention), and then a pair of curly braces containing fields and methods. According to the Oracle Java documentation, a class is “a blueprint from which individual objects are created.” That one-sentence definition is worth memorising before any interview. Oracle also reports that Java runs on over 3 billion devices worldwide, which explains why class and object design skills are in constant demand across industries.
What Goes Inside a Class
A class typically contains three things: fields (also called instance variables), constructors and methods. Fields store the state. Constructors initialise that state when an object is created. Methods define what the object can do.
For example, a BankAccount class might have a field called balance, a constructor that sets the opening balance, and methods like deposit() and withdraw(). That structure maps directly to real banking software used by companies like HDFC or ICICI. Before you start writing Java, it helps to have the right environment set up — our guide on software development tools to learn first covers IDEs like IntelliJ IDEA and VS Code that make Java development far less painful.
What Is a Concrete Class
A concrete class is a class that fully implements all its methods and can be instantiated with new. It’s the opposite of an abstract class or interface, which leave some methods without a body. Most of the classes you’ll write as a beginner are concrete classes. If you’re curious how concrete classes relate to interfaces and abstract classes, those are separate topics with their own dedicated pages.
If you’re studying for a BTech or BCA exam, note that interviewers almost always ask you to distinguish a concrete class from an abstract one. The short answer: if you can write new ClassName() and it compiles, it’s concrete.
What an Object Is
An object in Java is a specific instance of a class. Using the blueprint analogy: if the class is the blueprint, the object is the actual house built from it. You can build ten houses from one blueprint, and each house has its own address, colour and furniture. In Java, each object has its own copy of the fields defined in the class.
The object in Java definition from Oracle is clear: an object has state (fields), behaviour (methods) and identity (a unique reference in memory). When you write BankAccount acc1 = new BankAccount(5000);, Java allocates memory for a new object, runs the constructor and hands you a reference called acc1.
Object Syntax in Java
The syntax of object in Java follows a simple pattern:
| Part | Example | What it does |
|---|---|---|
| Class name (type) | BankAccount |
Declares the type of the variable |
| Variable name | acc1 |
The reference that points to the object |
new keyword |
new |
Triggers memory allocation on the heap |
| Constructor call | BankAccount(5000) |
Initialises the object’s fields |
One practical mistake beginners make constantly: they declare a variable but forget new, leaving it as null. When they then call a method on it, Java throws a NullPointerException. If you want to understand that error in depth, our guide on Java exceptions and common runtime errors covers it with worked examples.
The java.lang.Object Class
java.lang.Object is the root class of every class in Java. If you don’t explicitly extend any class, Java silently inserts extends Object for you. That means every object you create already has methods like toString(), equals(), hashCode() and getClass() available without you writing a single line.
This is why the phrase “object class in java” or “java lang object” appears so often in documentation. It’s not just theory: when you override equals() in your own class to compare two student objects by roll number instead of memory address, you’re working directly with the behaviour inherited from java.lang.Object.
Class Syntax and Example Program
Here’s a complete, working class and object program in Java you can type, compile and run today. It models a Student, which is a scenario every Indian CS student will recognise from university record systems. The example is written for Java 17 LTS, which is the current long-term support release widely used in Indian engineering colleges and industry.
Java Class Syntax
The java class syntax looks like this in practice:
// Class definition
public class Student {
// Fields (state)
String name;
int rollNumber;
double cgpa;
// Constructor
public Student(String name, int rollNumber, double cgpa) {
this.name = name;
this.rollNumber = rollNumber;
this.cgpa = cgpa;
}
// Method (behaviour)
public void displayInfo() {
System.out.println("Name: " + name);
System.out.println("Roll No: " + rollNumber);
System.out.println("CGPA: " + cgpa);
}
// Main method - entry point
public static void main(String[] args) {
// Creating objects
Student s1 = new Student("Priya Sharma", 101, 8.7);
Student s2 = new Student("Arjun Mehta", 102, 9.1);
// Calling methods on objects
s1.displayInfo();
s2.displayInfo();
}
}
Notice that s1 and s2 are two separate objects built from the same Student class. They share the same structure (fields and methods) but hold completely different data. That’s the entire point of class and object in Java with example form.
How to Create an Object in Java
Save the file as Student.java, open a terminal and run javac Student.java to compile, then java Student to execute. If you’re new to compiling programs from the command line, the process is very similar to what our article on how to write, compile and run a C program walks through for C, and the command-line logic transfers directly.
Java Class Methods in Detail
A java class method defines behaviour. Instance methods (like displayInfo() above) operate on a specific object’s data. Static methods belong to the class itself, not to any object, so you call them with the class name: Student.someStaticMethod(). Mixing up instance and static context is one of the most common compile errors beginners hit.
According to the Stack Overflow Developer Survey 2024, Java remains one of the top five most-used programming languages globally, with around 30% of professional developers working with it regularly. That’s not a reason to learn it for hype — it’s a reason to learn it because the job market demands it. The TIOBE Index (April 2025) consistently places Java in the top four languages, behind Python and C but ahead of most others. Closer to home, NASSCOM’s 2024 India Tech Talent Report identifies Java as one of the three most-requested backend skills in Indian IT hiring, appearing in over 60% of software developer job postings on major Indian job portals.
Class vs Object and the Object Class
The difference between class and object in Java confuses beginners more than almost any other concept. Here’s the clearest way to think about it: a class exists in your source code; an object exists in memory at runtime. You write classes; Java creates objects.
Class vs Object: Side-by-Side Comparison
| Aspect | Class | Object |
|---|---|---|
| Definition | Blueprint / template | Instance of a class |
| Exists in | Source code (.java file) | Heap memory at runtime |
| Created with | class keyword |
new keyword |
| Holds data? | No (defines structure only) | Yes (actual field values) |
| How many? | Defined once | As many as needed |
| Memory allocated? | No (at compile time) | Yes (at runtime, on the heap) |
One insight that separates people who truly understand OOP from those who just memorise it: a class is passive. It does nothing on its own. The moment you call new, Java brings the class to life as an object, allocates heap memory and runs the constructor. Everything active in a Java program happens through objects.
Can a Java Class Exist Without an Object?
Yes. A class can exist in your source code and compile successfully without any object ever being created from it. Static utility classes, for example, are designed to be used without instantiation. However, for most real-world programs, a class without objects is just unused code. The class defines the possibility; the object makes it real.
Why This Matters Beyond Academics
If you’re aiming for a role as a full stack developer or software developer, you’ll design classes daily, whether it’s a User class in a Spring Boot API or a Product class in an e-commerce backend. Getting the class-object relationship wrong leads to poorly structured code that’s hard to test and maintain.
For students pursuing BSc Computer Science or an MCA who are thinking about jobs and salary after MCA, object-oriented design skills are explicitly tested in campus placements at TCS, Infosys, Wipro and product companies. The class-object distinction appears in nearly every Java interview, from fresher to senior level.
And if you want to take your programming skills into cybersecurity, the CEH v13 AI online course at 3.0 University builds directly on programming fundamentals like the ones you’re learning here.
Frequently Asked Questions
What is a class in Java?
A class in Java is a blueprint that defines the structure and behaviour of objects. It contains fields (variables) that store data and methods that define actions. You write a class once using the class keyword, and from it you can create as many objects as your program needs, each holding its own values.
What is an object in Java?
An object in Java is a specific instance of a class, created at runtime using the new keyword. It holds actual data in its fields and can call the methods defined in its class. Every object has three characteristics: state (field values), behaviour (methods) and identity (a unique memory reference).
What is the difference between class and object in Java?
A class is a compile-time template that defines structure; an object is a runtime entity that holds real data. You can create multiple objects from one class, each with different field values. Simply put: the class is the blueprint, the object is the house built from that blueprint.
What is the Object class in Java?
java.lang.Object is the root class of every Java class. All classes automatically inherit from it, even if you don’t write extends Object explicitly. It provides core methods like toString(), equals() and hashCode() that every object in Java has access to by default.
What is a concrete class in Java?
A concrete class is a class that provides complete implementations for all its methods and can be directly instantiated using new. It’s the opposite of an abstract class, which may leave some methods without a body. Most classes you write as a beginner are concrete classes.
How many objects can be created from one class in Java?
There is no fixed limit set by the Java language itself. You can create as many objects from a single class as your system’s available heap memory allows. In practice, large-scale Java applications running on enterprise servers routinely manage millions of objects from a single class definition at runtime.
You now have everything you need to write, understand and explain class and object in Java with confidence. The blueprint-and-house mental model works at every level, from your first university practical to a senior developer interview. Here are three things to do this week:
- Write your own class from scratch, something personal like a
Book,MovieorCourseclass, add at least three fields and two methods, then create three objects and print their data. - Override the
toString()method in your class so that printing an object gives readable output instead of a memory address. This teaches you howjava.lang.Objectworks in practice. - Explore 3.0 University’s online certification courses to see how strong programming fundamentals feed into ethical hacking, secure coding and AI development. If cybersecurity interests you, the CEH v13 AI online course is a practical next step that builds directly on the Java and OOP skills you’re developing now.
Last updated: May 2025. Reviewed by the 3University editorial team.