Java Class 1675204752
Java Class 1675204752
#javatheeasyway
Learning java made easy.
/chauhansumitdev
Must Know
What you write
.java .java
java compiler
.class
.class file contains the Now there are two files with
byte code of the compiled .java file different formats.
which gets executed by the JVM(java
Virtual Machine).
JVM??
Java Virtual Machine is a virtual machine that provides runtime
environment for java programs i.e makes a system run java
programs (byte code).
/chauhansumitdev
What is a Class?
..is probably a class.
A java class is a template from which objects can be created. In simple words
it is an object factory.
Example:
/chauhansumitdev
Another Example:
Let's consider another example,
a stamp is just a one piece
material capable of producing any
stamp designs according to the
pattern inserted.
So,
The stamp acts as a java class and
the different patterns that can be
generated from the single device
are all objects.
A class in java does not exists or has no practical significance as being a template for
objects, what actually gets allocated in the memory are the objects it creates.
/chauhansumitdev
Syntax Of Class In Java:
class classname{
//instance variables
instance variables are those variables
which are declared just below
the class name.
//methods More at the bottom of the page
}
more on methods on upcoming posts :)
The methods and the instance variables are called the members of the class.
/chauhansumitdev
Practical Application
Let's Code A Class:
Make a Cylinder Class taking its radius and height as instance variables.
double radius;
height
double height;
new keyword dynamically allocates memory at runtime of the program to create object i.e when the code gets
executed, the required memory is allocated during the execution of the program. Therefore dynamic allocation
allows the object to take as much space as required so that the memory management can be taken care of.
/chauhansumitdev
Creating object for Cylinder class: radius = 10
radius = 5 radius = 7
radius = 3
B C
D
/chauhansumitdev
Up Next:
Methods In Java
Working more on the Cylinder class
using methods.
/chauhansumitdev
Happy Learning
/chauhansumitdev