1. Encapsulation is a key concept in object-oriented programming that binds data and functions together in classes. It provides security by restricting access to variables and functions within a class.
2. In structured programming languages, global variables are accessible by all code, which can lead to issues when the code needs to be upgraded by a new coder. Java addresses this by enclosing variables and functions within classes, making them non-global and restricting access.
3. When a new object is created using the new keyword in Java, memory is allocated in RAM for the non-static elements of the class. A reference variable is assigned the address of this memory location, allowing access to the object's data.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
43 views
Java Core
1. Encapsulation is a key concept in object-oriented programming that binds data and functions together in classes. It provides security by restricting access to variables and functions within a class.
2. In structured programming languages, global variables are accessible by all code, which can lead to issues when the code needs to be upgraded by a new coder. Java addresses this by enclosing variables and functions within classes, making them non-global and restricting access.
3. When a new object is created using the new keyword in Java, memory is allocated in RAM for the non-static elements of the class. A reference variable is assigned the address of this memory location, allowing access to the object's data.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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