You are on page 1of 7

Static Loading- RAM Execution may or may not(C )

Dynamic Loading- ram only when execution (Java)


Main Method- code and MAIN method deleted form RAM-
Issue with structured programming language:
Global variables- open access-unsecured
Actual issue-
Project written by one coder- upgradation required- new coder takes lot
of time to read and upgrade- new coder may mess the original code as
global variables are there
Solution-Encapsulation
Structured programming language: 20 global variables-only 5 used, but
15 unused are still available to everyone for change- no way to restrict
these variables
JAVA: THE VARAIBLES AND FUNCTIONS ARE ENCLOSED IN A BLOCK –
CLASS
VARIABLES INSIDE THE CLASS ARE NOT GLOBAL (instance variables)
Encapsulation is the process of binding data along with it corresponding
functionalities. It provides security to data present inside the program.
Backbone of OOPS- everything is encapsulated-nothing outside class
C++ not OOP AS MAIN METHOD declared outside class.
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("HELLO WORLD!");
}
}

X=x+1 gives error


Class name- HelloWorld Main method loaded to ram but
Only one method- main x still in hard drive-any
Rule- No method or function without return procedure to load it to RAM-
datatype Procedure to load content of
For main()- return type- void Hard disk to RAM dynamically
Public- at runtime- creating an object
Static- (this is the need for crating an
Stirng-another class object)
We save the file as HelloWorld.java
After execution (compiler) HelloWorld,class
file created(bytecode)
new keyword:
A a1= new A();- creation of object of class A
New operator transfers content of .class file from hard disk to RAM.
JVM encounters new keyword- understands it has to load all non static elements of .class file from
harddisk to RAM
Inside RAM- space allocated for non static elements- address of this memory location assigned to variable
a, where variable a is of type class A.
Object- the memory in the RAM which is reserved for non static elements of .class file.
Object-instance of class
a is known as handler or pointer of type A.
Strictly speaking a is reference of an object (pointing finger)
Garbage collector
JVM follows concept of dynamic loading- signature is loaded
If there are n classes in a .java file JVM creates n .class file
Cases-if there are 1>x>n main methods inside n classes
Main method loads-
Object created and address assigned to O1
Variable x1 ceated assigned value- 10
x1 value changed to 25
Another object of obj6 created- address assigned to O1 again
Previous address of O1 overwritten-it now point to new object
Obj6 O2=O1- object O2 created and O1 ‘s value assigned to it
We have two references O1 and O2 to same object
JVM workflow
Loading non static variables
Initialising uninitialized variables
with their default values
• Ways of creating object
1. Hello a=new Hello()
2. new Hello()
3. Hello a; (Page 38-40)
• Static Keyword

You might also like