Fundamental Classes – Object, Class, System, Runtime
Java provides many built-in classes, but some classes are so fundamental that they form the base of the entire language and runtime environment. Among these, the most important are Object, Class, System, and Runtime.
These classes are part of the java.lang package, which is automatically imported in every Java program. They are deeply connected with object creation, class metadata, input-output, memory management, process execution, and JVM interaction.
Object is the root class of Java, Class represents metadata about classes, System provides system-level utility features, and Runtime allows interaction with the JVM runtime environment.
Why These Classes Are Called Fundamental
These classes are called fundamental because they support the core behavior of Java itself.
Objectis the parent of almost every Java classClassprovides runtime information about classes and objectsSystemgives access to standard input, output, properties, and utility methodsRuntimegives access to memory information, external process execution, and JVM-related operations
1. Object Class
The Object class is the root class of the Java class hierarchy. Every class in Java directly or indirectly inherits from Object.
That means every object in Java automatically gets access to the methods of the Object class.
Simple Understanding
If you create any class:
It is automatically treated like:
Common Methods of Object Class
Some important methods of the Object class are:
toString()equals()hashCode()getClass()clone()finalize()wait()notify()notifyAll()
toString() Method
The toString() method returns a string representation of an object.
Example Without Overriding
Output may look like:
This default representation is not very readable.
Example With Overriding
equals() Method
The equals() method is used to compare objects logically.
By default, it checks reference equality, but it can be overridden for content comparison.
Example
Here:
==compares referencesequals()compares content
hashCode() Method
The hashCode() method returns an integer hash value representing the object. It is heavily used in collections such as HashMap and HashSet.
If two objects are equal according to equals(), then they should return the same hash code.
getClass() Method
The getClass() method returns the runtime class information of an object.
Example
This method connects Object class to reflection and runtime type inspection.
wait(), notify(), notifyAll()
These methods are used in multithreading for inter-thread communication.
wait()→ current thread waitsnotify()→ wakes up one waiting threadnotifyAll()→ wakes up all waiting threads
These methods are defined in Object because every object can act as a monitor/lock.
2. Class Class
The Class class represents metadata about a Java class at runtime. In simple words, it stores information about classes such as:
- class name
- methods
- fields
- constructors
- modifiers
- annotations
Every loaded class in Java has a corresponding Class object.
How to Get Class Object
There are mainly three common ways:
1. Using class literal
2. Using getClass()
3. Using Class.forName()
Example of Class Class Usage
This prints the class name at runtime.
Common Methods of Class Class
getName()getSimpleName()getDeclaredMethods()getDeclaredFields()getDeclaredConstructors()getSuperclass()getInterfaces()
Example of getSimpleName()
Example of getSuperclass()
Since every class extends Object, this usually prints:
Why Class Class is Important
The Class class is the foundation of reflection. It allows Java to inspect types dynamically at runtime.
Many frameworks such as Spring, Hibernate, and JUnit use this internally.
3. System Class
The System class provides access to system-level features such as standard input, standard output, environment information, current time, array copying, and JVM interaction.
It belongs to java.lang and is automatically available.
Common Members of System Class
System.outSystem.inSystem.errcurrentTimeMillis()arraycopy()getProperty()gc()exit()
System.out
System.out is the standard output stream used to print output to the console.
System.in
System.in is the standard input stream used for keyboard input.
System.err
System.err is the standard error output stream. It is often used for error messages.
currentTimeMillis()
This method returns the current time in milliseconds since January 1, 1970 UTC.
It is useful for measuring execution time.
Example
arraycopy()
The arraycopy() method copies elements from one array to another.
getProperty()
This method is used to get system properties such as Java version, operating system name, or user directory.
gc()
The gc() method requests garbage collection.
It does not guarantee immediate garbage collection, but it requests JVM to perform it.
exit()
The exit() method stops the current Java program.
Here, 0 usually means normal termination.
Why System Class is Important
The System class is used almost daily in Java programming because it provides basic I/O, timing, environment information, and runtime interaction.
4. Runtime Class
The Runtime class represents the runtime environment of the Java application. It allows the program to interact with the JVM itself.
Using the Runtime class, we can:
- get memory information
- request garbage collection
- execute external programs
- check available processors
Getting Runtime Object
The Runtime class cannot be instantiated directly using new. It uses the singleton-style access method:
Common Methods of Runtime Class
totalMemory()freeMemory()availableProcessors()gc()exec()
totalMemory() and freeMemory()
These methods provide information about JVM memory.
This is useful for understanding memory behavior of applications.
availableProcessors()
This method returns the number of processors available to the JVM.
gc() in Runtime Class
This method is similar to System.gc() and requests garbage collection.
exec() Method
The exec() method can be used to run external system commands or applications.
Example
This may open Notepad on Windows.
On Linux or macOS, the command would differ depending on the installed application.
System Class vs Runtime Class
| Point | System Class | Runtime Class |
|---|---|---|
| Purpose | General system-level utilities | Interaction with JVM runtime environment |
| Examples | out, in, err, currentTimeMillis() | memory info, gc(), exec() |
| Object creation | Static utility class style usage | Accessed through getRuntime() |
Relationship Between Object, Class, System, and Runtime
These classes work together in the Java language and runtime environment:
Objectgives base behavior to all Java classesClassprovides runtime metadataSystemgives standard utility and environment accessRuntimeprovides deeper JVM runtime interaction
Practical Example Using Multiple Fundamental Classes
This shows how all these classes are useful in real Java code.
Common Mistakes
- Confusing
Objectclass with object instance - Thinking
Classclass is same as normal user-defined class - Overusing
System.gc()expecting guaranteed collection - Using
exec()carelessly without understanding platform dependency - Not understanding difference between
Systemutilities andRuntimeJVM interaction
Best Practices
- Override
toString()for meaningful object printing - Use
equals()andhashCode()carefully in object comparison - Use
Classinformation when reflection or dynamic logic is required - Use
Systemfor standard utility operations - Use
Runtimecarefully for memory or process-related operations
Interview-Oriented Points
Objectis the parent of almost every Java classtoString(),equals(), andhashCode()come fromObjectClassrepresents runtime metadata of a classSystemprovides I/O, system properties, and utility methodsRuntimeprovides JVM-related operations such as memory info and process executionSystem.gc()andRuntime.getRuntime().gc()both request garbage collectiongetClass()returns the runtime type of an object
Conclusion
The classes Object, Class, System, and Runtime are among the most essential built-in classes in Java. They support object behavior, runtime metadata, system-level utilities, and JVM interaction.
A strong understanding of these classes gives deeper insight into how Java works internally and how Java programs interact with both the language and the runtime environment.
Object is the base class of Java, Class provides runtime class information, System offers core utilities, and Runtime lets Java programs interact with the JVM environment.

