What is java, and why is it not considered
a pure object-oriented programming
language?
Java is a class-based object-oriented programming
language designed to simplicity and portability.
Its key feature is Write once and run anywhere
(WORA).
Compile Java code, it can run on any platform that
supports Java without recompiling this make java
a popular choice for enterprise application due to
its robustness security and ease of use.
However, Java is not a pure object-oriented
programming language, Because in Java not
everything is an object, basic elements like
numbers and letters Java treats them differently
instead of being objects, they are primitives like
int for numbers or char for letters. We can
manipulate them without wrapping them into an
object.
Another reason is the use of static keyword, Static
variable or method can be access without creating
an object of the class which breaks the object-
oriented principle that everything should be done
through object.
While Java offers wrapper classes like Integer and
Float to convert primitive into objects it still allows
direct operation on primitive whicj is why it is not
fully object-oriented programming language.
Explain key component involve in running
a Java program?
When you write a Java program, you first create a
Java source file for example Example.java this
source file needs to be compiled before it can run
and java uses a multi-step process firstly let’s talk
about compilation. The Java compiler (Part of JDK)
takes a .java source file and turns it into
bytecodes. This bytecode is stored in a .class file,
like in our case Example.class byte code is
platform independent meaning it can run on any
system.
Once a compilation is done let’s see the execution
now that byte code is ready it can be run and this
is where the JVM Comes in.
The three important components are:
JDK: Java Development Kit provides all the tools to
create Java applications including Java Compiler
that converts .java code to bytecodes.
JRE: Java Runtime Environment is needed to run
the compiled byte code which includes the JVM
and libraries.
JVM: Java Virtual Machine takes the Byte code
and it makes sure it consistently runs across
different platforms by loading it into memory and
linking it to libraries.
Why is Java a platform independent
language?
"Java is platform independent because of its
compilation and execution model. When I write
Java code, it's compiled by the javac compiler into
an intermediate form called bytecode, which is
not tied to any specific operating system. This
bytecode runs on the Java Virtual Machine (JVM),
and since each OS has its own version of the JVM,
the same Java program can run on Windows,
Linux, or Mac without modification. That’s why
Java follows the principle of ‘Write Once, Run
Anywhere’."
💡 Optional Follow-up (if asked to explain
technically):
"The key is that the bytecode is platform-
independent, but the JVM is platform-specific. So
as long as the system has the correct JVM
installed, the bytecode can be executed regardless
of the underlying hardware or OS."
What is the difference between an
abstract class and an interface?
"The main difference between an abstract class
and an interface in Java lies in their purpose and
usage.
An abstract class is used when we want to
provide a base class with some default
behavior, and it can have both abstract
methods (without body) and concrete
methods (with implementation).
An interface, on the other hand, is used to
define a contract that classes must follow.
Interfaces cannot have instance variables and
all methods were abstract by default until Java
8. Since Java 8+, interfaces can also include
default and static methods, and from Java 9,
even private methods.
Another major difference is that:
A class can extend only one abstract class
(because Java supports single inheritance),
But it can implement multiple interfaces,
which allows multiple inheritance of type."
🧩 Key Differences Table:
Feature Abstract Class Interface
Can extend Can implement
Inheritance
only one class multiple interfaces
Methods Can have Only abstract
abstract and methods (till Java 7),
Feature Abstract Class Interface
concrete default/static
methods methods (Java 8+)
Can have
Only public static
Variables instance
final constants
variables
Constructor Yes No
Methods can
Access have any Methods are public
Modifiers access by default
modifier
When classes When different
share classes need to
Use Case
common follow the same
behavior contract
Explain OOPS in detail.
OOPs stands for Object-Oriented Programming
System. It’s a programming paradigm based on
the concept of 'objects', which contain data and
behaviour. Java is a fully object-oriented language
that follows OOP principles to build modular,
reusable, and maintainable code. The four main
pillars of OOP are Encapsulation, Inheritance,
Polymorphism, and Abstraction.
1. Encapsulation
Wrapping data and methods into a single unit
(class) and restricting direct access.
Encapsulation provides objects with the ability to
hide their internal characteristics and behaviour.
It helps in data hiding and ensures security.
In Java, there are three access modifiers: public,
private and protected. Each modifier imposes
different access rights to other classes, either in
the same or in external packages.
Java Example: Using private variables with getter
and setter methods.
2. Inheritance
Inheritance provides an object with the ability to
acquire the fields and methods of another class,
called base class. One class (child) inherits
properties and behaviours from another class
(parent).
It promotes code reusability.
Java Example: class B extends A {}
3. Polymorphism
Polymorphism is a Greek word it means "many
forms."
Polymorphism is the ability of programming
languages to present the same interface for
differing underlying data types.
It increases flexibility and readability.
Types of Polymorphism in Java:
a. Compile-time Polymorphism (Static
Binding / Method Overloading)
Occurs during compile time.
Multiple methods with the same name but
different parameters.
b. Runtime Polymorphism (Dynamic Binding /
Method Overriding)
Happens at runtime using inheritance and
method overriding.
The call to an overridden method is resolved
at runtime based on the object type.
4. Abstraction
Abstraction is the process of hiding complex
implementation details and showing only the
necessary parts of an object.
It helps in reducing complexity and increases
security.
✅ Real-Life Example:
Think of a car:
You drive using the steering wheel, pedals,
and gear.
You don’t need to know how the engine
works, or how fuel gets converted to power.
That's abstraction — you interact with what you
need, and the complex logic is hidden.
🧩 In Java, abstraction is achieved using:
1.Abstract Classes
2.Interfaces
Differences between Abstraction and
Encapsulation
Abstraction and encapsulation are
complementary concepts. On the one hand,
abstraction focuses on the behaviour of an
object. On the other hand, encapsulation
focuses on the implementation of an object’s
behaviour. Encapsulation is usually achieved
by hiding information about the internal state
of an object and thus, can be seen as a
strategy used in order to provide abstraction.