SlideShare a Scribd company logo
Welcome
Disclaimer: This presentation is prepared by trainees of baabtra as
a part of mentoring program. This is not official document of
baabtra – Mentoring Partner
baabtra – Mentoring Partner is the mentoring division of baabte System Technologies Pvt. Ltd.
Stack and heap
         Ashwin Anand V
         ashwinanand99@gmail.com
Difference between instance
    variables and local variables

• Instance variables are declared inside a class but not
   inside a method:
class Student{
int num;       // num is instance variable
public void showData{}

• Local variables are declared inside a method
   including method arguments:
public void sum(int a){
int x = int a + 3;    // a , x are local variables
•
•   }
What goes inside when you
       declare a variable?
• When you declare a variable in a application, it
  allocates some chunk of memory in the RAM.
• This memory has three things: the name of the
  variable, the data type of the variable, and the value
  of the variable.
STACK

• The Stack section of memory contains methods,
  local variables and reference variables.
• All the information required to resume the execution
  of these functions is stored on the stack.
• Provides static memory allocation
HEAP
• The heap is simply the memory used by programs
  to store global variables.
• All global variables are stored in heap memory.
• When that function exits, the heap memory used
  by each local variable is freed.
• Dynamic memory allocation .
Example for stack and heap
public void Method()
 {
int i=4;   (stack memory)
 int y=2    (stack memory)
Class1 cls1= new class(); (heap memory)
}
Example cont….
Thank you
Stack&heap

More Related Content

PPTX
Abstrcation
PPT
Struct
PPTX
O op lecture 04
PDF
Lecture02 java
PDF
Object oriented principles
PPTX
Array sorting
PPTX
Java data types
PDF
Important Concepts for Machine Learning
Abstrcation
Struct
O op lecture 04
Lecture02 java
Object oriented principles
Array sorting
Java data types
Important Concepts for Machine Learning

What's hot (18)

PPTX
Unit 2 linked list
PPTX
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
PPT
Introduction to data structures and Algorithm
PPTX
Vectors
PPT
Abstract data types
PPT
Chapter 05
PPT
Chapter 03
PPT
Chapter 04
PPTX
oop Lecture 1
PPT
Unit4 C
PPTX
Structure in C
PPTX
Procedural vs. object oriented programming
PPTX
Programming Logic and Design: Working with Data
PPT
BASICS OF DATA STRUCTURE
PPTX
Intro to Programming: Modularity
PPTX
Java Tutorial Lab 3
Unit 2 linked list
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Introduction to data structures and Algorithm
Vectors
Abstract data types
Chapter 05
Chapter 03
Chapter 04
oop Lecture 1
Unit4 C
Structure in C
Procedural vs. object oriented programming
Programming Logic and Design: Working with Data
BASICS OF DATA STRUCTURE
Intro to Programming: Modularity
Java Tutorial Lab 3
Ad

Similar to Stack&heap (20)

PPTX
STORAGE CLASS.pptx
PPTX
static members in object oriented program.pptx
PPTX
static MEMBER IN OOPS PROGRAMING LANGUAGE.pptx
DOCX
Storage class
PPTX
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
PPTX
C MEMORY MODEL​.pptx
PPTX
C MEMORY MODEL​.pptx
PPTX
Storage classes
PDF
PPTX
[OOP - Lec 18] Static Data Member
PDF
lecture-18staticdatamember-160705095116.pdf
PPTX
class as the basis.pptx
PDF
Advanced C Programming Notes
PDF
Week 7 Java Programming Methods For I.T students.pdf
PPTX
PDF
C- language Lecture 6
PDF
Constructors and Method Overloading
STORAGE CLASS.pptx
static members in object oriented program.pptx
static MEMBER IN OOPS PROGRAMING LANGUAGE.pptx
Storage class
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
C MEMORY MODEL​.pptx
C MEMORY MODEL​.pptx
Storage classes
[OOP - Lec 18] Static Data Member
lecture-18staticdatamember-160705095116.pdf
class as the basis.pptx
Advanced C Programming Notes
Week 7 Java Programming Methods For I.T students.pdf
C- language Lecture 6
Constructors and Method Overloading
Ad

More from baabtra.com - No. 1 supplier of quality freshers (20)

PPTX
Agile methodology and scrum development
PDF
Acquiring new skills what you should know
PDF
Baabtra.com programming at school
PDF
99LMS for Enterprises - LMS that you will love
PPTX
Chapter 6 database normalisation
PPTX
Chapter 5 transactions and dcl statements
PPTX
Chapter 4 functions, views, indexing
PPTX
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
PPTX
Chapter 1 introduction to sql server
PPTX
Chapter 1 introduction to sql server
Agile methodology and scrum development
Acquiring new skills what you should know
Baabtra.com programming at school
99LMS for Enterprises - LMS that you will love
Chapter 6 database normalisation
Chapter 5 transactions and dcl statements
Chapter 4 functions, views, indexing
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 1 introduction to sql server
Chapter 1 introduction to sql server

Recently uploaded (20)

PPTX
Pharma ospi slides which help in ospi learning
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Basic Mud Logging Guide for educational purpose
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
master seminar digital applications in india
PPTX
Lesson notes of climatology university.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Complications of Minimal Access Surgery at WLH
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Computing-Curriculum for Schools in Ghana
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Insiders guide to clinical Medicine.pdf
Pharma ospi slides which help in ospi learning
102 student loan defaulters named and shamed – Is someone you know on the list?
Renaissance Architecture: A Journey from Faith to Humanism
PPH.pptx obstetrics and gynecology in nursing
Basic Mud Logging Guide for educational purpose
Microbial disease of the cardiovascular and lymphatic systems
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
master seminar digital applications in india
Lesson notes of climatology university.
Final Presentation General Medicine 03-08-2024.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Classroom Observation Tools for Teachers
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Complications of Minimal Access Surgery at WLH
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Computing-Curriculum for Schools in Ghana
Anesthesia in Laparoscopic Surgery in India
Insiders guide to clinical Medicine.pdf

Stack&heap

  • 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra – Mentoring Partner baabtra – Mentoring Partner is the mentoring division of baabte System Technologies Pvt. Ltd.
  • 3. Stack and heap Ashwin Anand V ashwinanand99@gmail.com
  • 4. Difference between instance variables and local variables • Instance variables are declared inside a class but not inside a method: class Student{ int num; // num is instance variable public void showData{} • Local variables are declared inside a method including method arguments: public void sum(int a){ int x = int a + 3; // a , x are local variables • • }
  • 5. What goes inside when you declare a variable? • When you declare a variable in a application, it allocates some chunk of memory in the RAM. • This memory has three things: the name of the variable, the data type of the variable, and the value of the variable.
  • 6. STACK • The Stack section of memory contains methods, local variables and reference variables. • All the information required to resume the execution of these functions is stored on the stack. • Provides static memory allocation
  • 7. HEAP • The heap is simply the memory used by programs to store global variables. • All global variables are stored in heap memory. • When that function exits, the heap memory used by each local variable is freed. • Dynamic memory allocation .
  • 8. Example for stack and heap public void Method() { int i=4; (stack memory) int y=2 (stack memory) Class1 cls1= new class(); (heap memory) }