Page 117 - ComputerScience_Class_11
P. 117
• Object is an instance of a class: As soon as an object is created in Java, it acquires memory in RAM, but this does
not happen while defining a class. Thus, objects are the physical existence of the class.
We know data types such as int, long, float, etc. are predefined classes in Java. Similarly, user-defined classes create
objects that contain all the properties and methods of those classes and also acquire memory.
Thus, we can say an object is an instance of a class.
• Class is a user-defined data type: A user-defined data type is a derived data type depending on some existing data types.
A Java program is made up of classes. And each class is made up of some attributes (data members) which are
predefined data types. And while creating an object of a class, we are basically defining a variable that has the size
of the total bytes of the predefined data types. Thus, we can say a class is a user-defined data type.
5.2.3 Difference between Class and Object
The differences between class and object are given in the table and also shown in the picture below:
Class Object
A class is a blueprint to create similar kinds of objects. An object is a unique entity.
No memory is occupied when a class is created. As soon as the object is created, memory is initialised.
Class is a user-defined data type. Object is a variable of the user-defined data type known as class.
Class is the logical representation of data. Object is the physical representation of data.
Class is created once in a program. Object can be created many times as and whenever required
just by utilising the name of the class.
Syntax for declaring a class: Syntax for instantiating an object for a class:
class <classname> <classname> <objectname> = new
{ } <constructor>;
ANIMAL (Class)
(Objects)
5.3 BASIC CONCEPT OF A VIRTUAL MACHINE
A Virtual Machine (VM) is a machine that uses software instead of a physical computer to execute programs. It creates
an environment similar to a physical computer for installing and running other software. The process of creating a
software-based version of a computer is known as virtualisation.
5.3.1 Java Virtual Machine (JVM)
A Java virtual machine converts Java bytecode to machine-dependent code so that it could be executed. It enables a
computer to run Java programs as well as programs written in other programming languages that are also compiled
to Java bytecode.
Features of JVM
Some features of JVM are as follows:
• It allows Java code to execute on any computers, mobiles, etc. Also, it can run on any operating system. It follows
the principle of “Write Once, Run Anywhere”.
• It manages and optimises the program so that memory usage can be minimised.
Objects 115

