Introduction to Java and OOPS
Java is one of the most popular and widely used programming languages in the world. It is used for enterprise applications, backend systems, Android apps, desktop applications, and large-scale web platforms. One of the biggest reasons behind Java’s popularity is its platform independence and strong support for Object-Oriented Programming, commonly called OOPS.
When students start learning Java, the first step is understanding what Java is, how Java programs run, and why OOPS is considered such an important concept in software development. This topic builds the base for everything that comes later in Core Java.
What is Java?
Java is a high-level, object-oriented, class-based programming language developed by Sun Microsystems and later maintained by Oracle. It was designed to be simple, secure, portable, and robust.
The most famous idea behind Java is:
Write Once, Run Anywhere (WORA)
This means a Java program can be written once and run on multiple platforms such as Windows, Linux, and macOS without changing the source code, as long as a Java Virtual Machine (JVM) is available on that system.
Why Java is Platform Independent
In many traditional programming languages, source code is compiled directly into machine code, and that machine code is tied to a specific operating system or processor architecture. Java works differently.
- The source code is written in a
.javafile - The Java compiler converts it into bytecode
- That bytecode is stored in a
.classfile - The JVM reads and executes the bytecode on any supported platform
Because the bytecode is not tied to a single operating system, Java programs are portable across platforms.
Java Program Execution Flow
To understand Java properly, it is important to know how a Java program is written, compiled, and executed.
Step 1: Write the Source Code
A Java program is written in a file with the .java extension.
Step 2: Compile the Program
The Java compiler javac converts the source code into bytecode.
After compilation, a new file is created:
Step 3: Run the Program
The bytecode is executed using the JVM.
This process makes Java both compiled and interpreted in nature. The code is first compiled into bytecode, and then the JVM interprets or executes that bytecode.
Important Java Components
JDK
JDK stands for Java Development Kit. It includes everything required to develop Java programs, such as the compiler, runtime, and development tools.
JRE
JRE stands for Java Runtime Environment. It provides the environment needed to run Java applications.
JVM
JVM stands for Java Virtual Machine. It is the engine that executes Java bytecode.
First Java Program
Let us look at the simplest Java program.
Output
Understanding the First Program
1. class Hello
This declares a class named Hello. In Java, every program is written inside a class.
2. public static void main(String[] args)
This is the main method, which acts as the entry point of the Java program. When the program runs, JVM first looks for this method.
- public means the method can be accessed from anywhere
- static means the method belongs to the class, not to an object
- void means the method does not return any value
- main is the predefined method name that JVM recognizes
- String[] args stores command-line arguments
3. System.out.println()
This statement prints the given text to the console.
What is OOPS?
OOPS stands for Object-Oriented Programming System. It is a programming approach in which programs are designed around objects rather than only functions and procedures.
In OOPS, real-world entities are modeled in code using:
- Classes
- Objects
- Properties
- Methods
This makes programs more organized, reusable, and easier to maintain.
Real-World Understanding of OOPS
Consider a real-world object like a Car.
- Properties: color, brand, model, speed
- Behaviors: start(), stop(), accelerate()
In Java, we represent such real-world things using classes and objects.
What is a Class?
A class is a blueprint, template, or design for creating objects. It defines what data an object will have and what actions it can perform.
In the above example:
colorandbrandare propertiesstart()is a behavior or method
What is an Object?
An object is a real instance of a class. When an object is created, memory is allocated, and it can use the variables and methods defined in the class.
Output
Understanding Class and Object with Simple Explanation
Think of a class as the design of a house and the object as the actual built house.
- A class does not occupy memory for actual data until an object is created
- An object is the actual usable entity
Why OOPS is Important in Programming
OOPS is important because real software projects are large and complex. Writing everything as simple instructions becomes difficult to manage. OOPS solves this problem by organizing code into meaningful units.
- Reusability: code can be reused through classes and inheritance
- Maintainability: changes become easier
- Scalability: large projects become manageable
- Real-world modeling: business objects can be represented clearly
Four Main Pillars of OOPS
The four pillars of object-oriented programming are:
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
1. Encapsulation
Encapsulation means wrapping data and methods together into a single unit and controlling direct access to data.
For example, in banking software, account balance should not be directly modified by anyone. Instead, it should be accessed through controlled methods.
Here, balance is private, so it cannot be accessed directly from outside the class. This improves security and control.
2. Inheritance
Inheritance allows one class to acquire the properties and methods of another class.
It supports code reuse and helps create logical class hierarchies.
In this example, Dog inherits the eat() method from Animal.
Output
3. Polymorphism
Polymorphism means one method or one interface can behave differently in different situations.
One common example is method overloading.
The method name add is the same, but the parameters are different. This is called compile-time polymorphism.
4. Abstraction
Abstraction means showing only the essential details and hiding the internal implementation.
For example, when you drive a car, you use the steering wheel, brake, and accelerator. You do not need to know the full internal engine mechanism while driving.
Here, the user only knows that start() exists. The internal implementation is hidden.
Difference Between Class and Object
| Class | Object |
|---|---|
| Blueprint or template | Instance of a class |
| Logical entity | Physical entity |
| No actual memory for instance data | Consumes memory when created |
| Defines properties and methods | Uses those properties and methods |
Java Features
- Simple: Java syntax is easier than many low-level languages
- Object-Oriented: Java uses class and object-based design
- Platform Independent: Java runs through JVM
- Secure: Java avoids unsafe memory operations
- Robust: Java includes exception handling and memory management
- Multithreaded: Java supports concurrent execution
- Portable: Java programs can run on different systems
Real-World Example: Student Class
Let us take another simple example to make the concept clearer.
Output
In this example, both s1 and s2 are different objects created from the same Student class.
Common Beginner Mistakes
- Thinking class and object are the same thing
- Forgetting that Java code always runs through JVM
- Assuming OOPS is only theory and not useful in real projects
- Trying to access private data members directly
Interview-Oriented Points
- Java is platform independent because of bytecode and JVM
- Java is both compiled and interpreted
- OOPS helps in modular, reusable, and maintainable design
- The four pillars of OOPS are encapsulation, inheritance, polymorphism, and abstraction
Conclusion
Java is a powerful language designed for portability, security, and maintainability. Understanding the basics of Java and OOPS is the first major step in becoming a strong Java developer.
Once you understand class, object, JVM, and the four pillars of OOPS, the remaining Core Java topics become much easier to understand because they are all built on this foundation.

