Q. 1 Explain the following terms
I) Classes
II) Objects
III) Abstraction
IV) Inheritance
V) Polymorphism
Object
• Any entity that has state and behavior is known as an object. For example, a chair, pen, table,
keyboard, bike, etc. It can be physical or logical.
• An Object can be defined as an instance of a class. An object contains an address and takes up
some space in memory. Objects can communicate without knowing the details of each other's
data or code. The only necessary thing is the type of message accepted and the type of response
returned by the objects.
Example: A dog is an object because it has states like color, name, breed, etc. as well as behaviors
like wagging the tail, barking, eating, etc.
Class
• Collection of objects is called class. It is a logical entity.
• A class can also be defined as a blueprint from which you can create an individual object. Class
doesn't consume any space
• A class is a group of objects which have common properties. It is a template or blueprint from
which objects are created. It is a logical entity. It can't be physical.
A class in Java can contain:
o Fields
o Methods
o Constructors
o Blocks
o Nested class and interface
Java notes 1
, Unit I: Introduction to Object Oriented Programming
Inheritance
When one object acquires all the properties and behaviors of a parent object, it is known as
inheritance. It provides code reusability. It is used to achieve runtime polymorphism.
Polymorphism
• If one task is performed in different ways, it is known as polymorphism. For example: to convince
the customer differently, to draw something, for example, shape, triangle, rectangle, etc.
• In Java, we use method overloading and method overriding to achieve polymorphism.
• Another example can be to speak something; for example, a cat speaks meow, dog barks woof,
etc.
Abstraction
Hiding internal details and showing functionality is known as abstraction. For example phone call,
we don't know the internal processing.
Encapsulation
• Binding (or wrapping) code and data together into a single unit are known as encapsulation. For
example, a capsule, it is wrapped with different medicines.
• A java class is the example of encapsulation. Java bean is the fully encapsulated class because
all the data members are private here.
Q. 2 Explain JVM (java virtual machine) and importance of JVM in JRE.
• What is JVM?
JVM (Java Virtual Machine) is an abstract machine that enables your computer to run a Java
program.
When you run the Java program, Java compiler first compiles your Java code to bytecode. Then,
the JVM translates bytecode into native machine code (set of instructions that a computer's CPU
executes directly).
Java notes 2
, Unit I: Introduction to Object Oriented Programming
Java is a platform-independent language. It's because when you write Java code, it's ultimately
written for JVM but not your physical machine (computer). Since JVM executes the Java bytecode
which is platform-independent, Java is platform-independent.
• What is JRE?
JRE (Java Runtime Environment) is a software package that provides Java class libraries, Java
Virtual Machine (JVM), and other components that are required to run Java applications.
JRE is the superset of JVM.
If you need to run Java programs, but not develop them, JRE is what you need.
The components of JRE are as follows:
Deployment technologies, User interface toolkits, Integration libraries, Other base libraries,
Lang and util base libraries,Java Virtual Machine (JVM),
• What is JDK?
JDK (Java Development Kit) is a software development kit required to develop applications in Java.
When you download JDK, JRE is also downloaded with it.
In addition to JRE, JDK also contains a number of development tools (compilers, JavaDoc, Java
Debugger, etc).
• Relationship between JVM, JRE, and JDK.
Q. 3 Why JAVA is known as platform independent language? Explain.
What is a Platform, and What is a Platform-Independent Language?
Java notes 3