#26 Stack And Heap in Java

  Рет қаралды 213,608

Telusko

Telusko

Жыл бұрын

Check out our courses:
Spring and Microservices Weekend Live Batch : bit.ly/spring-live-weekend
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : bit.ly/java-spring-cloud
Udemy Courses:
Java:- bit.ly/JavaUdemyTelusko
Spring:- bit.ly/SpringUdemyTelusko
Java For Programmers:- bit.ly/javaProgrammers
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusko.com/
In this lecture we are discussing:
1) Memory management in java and typed of categories to store data in memory.
2)What is stack ?
3)What is heap ?
4) where instance variable and local variable is allocated?
#1
In java we are managing our managing our memory using two data structure stack and heap.
two categories to store data in memory:
1) Stack data structure
2) heap data structure
#2
Stack is data structure which follow LIFO(Last in First Out) principle.
#3
heap is data structure which is used to store data in form of object and object is a collection of data and method.
#4
class Student{
int instVariable; //store in object and object created in heap
public static void main(String []args){
int localVariable=0; //local variable store in stack frame of method in stack area.
Student st=new Student(); //st is reference variable store address of new Student() object
}
public int add(int num1,int num2){
return num1+num2;
}
}
-- instance variable stored in object and object are in heap therefore we can say that instance variable created in heap.
-- method declaration and definition is present in object but actual implementation present in stack frame of stack.
-- local variable created in stack during call of method.
-- stack frame of called method is present in stack area.
-- st is reference variable created inside the current stack frame and it is reference variable store address of student object created in heap area.
-- new Student() create object in heap area and pointed by his reference variable.
Github repo : github.com/navinreddy20/Javac...
Java:- bit.ly/JavaUdemyTelusko
Spring:- bit.ly/SpringUdemyTelusko
More Learning :
Java :- bit.ly/3x6rr0N
Python :- bit.ly/3GRc7JX
Django :- bit.ly/3MmoJK6
JavaScript :- bit.ly/3tiAlHo
Node JS :- bit.ly/3GT4liq
Rest Api :-bit.ly/3MjhZwt
Servlet :- bit.ly/3Q7eA7k
Spring Framework :- bit.ly/3xi7buh
Design Patterns in Java :- bit.ly/3MocXiq
Docker :- bit.ly/3xjWzLA
Blockchain Tutorial :- bit.ly/3NSbOkc
Corda Tutorial:- bit.ly/3thbUKa
Hyperledger Fabric :- bit.ly/38RZCRB
NoSQL Tutorial :- bit.ly/3aJpRuc
Mysql Tutorial :- bit.ly/3thpr4L
Data Structures using Java :- bit.ly/3MuJa7S
Git Tutorial :- bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20
www.telusko.com

Пікірлер: 81
@spidermanhomecoming001
@spidermanhomecoming001 Жыл бұрын
I just love you sir! I was confused for so long about heap and stack. Now its clear! U are a great teacher.
@MsSWAGboss
@MsSWAGboss Жыл бұрын
Thank you for the video :) I just started going into interviews again and this helped me get back to speed on the topic cause I had forgotten so much stuff throughout the year as a junior dev
@ajiboladaniel9386
@ajiboladaniel9386 8 ай бұрын
The best Java teacher I've ever encountered in my life. You are awesome sir. The understanding of the concept is sooo seamless. It's like a miracle. Thanks soo much.
@thefriendlymartian7317
@thefriendlymartian7317 5 ай бұрын
The best explanation anyone could ever give. As soon as I have a question in my mind, you call out that point and explain as if I asked the question in person. Just shows how perfectly the flow of the content is.
@ferzandali1527
@ferzandali1527 3 ай бұрын
I agree with u 100%
@rushikeshbhujbal2480
@rushikeshbhujbal2480 Жыл бұрын
you are really great,this content is really helpfull and thanks for the notes that you are providing in description.
@chairma_prabhu
@chairma_prabhu 9 ай бұрын
Thank you Navin for providing quality content like this.
@zr0724
@zr0724 Жыл бұрын
wow , these tutorials are of next level for sure. thank you sir.
@piotr2951
@piotr2951 3 ай бұрын
No, we don't have multiple stacks (in a single thread), those are called frames. Those frames contain multiple data structures for storing local variables, operands, return addresses, constants.
@Shubham-si6hd
@Shubham-si6hd Жыл бұрын
You are a life saver! Thank You
@kapiljain359
@kapiljain359 9 ай бұрын
Really Nice explained. I am following Telusko since my collage time(2018). And now I am the Senior Software Developer in reputated Product company. Big Thanks Goes to Mr Naveen. Thank you Sir! I would like to request if you can make the playlist on AWS for Java Developers. It would be very helpful.
@moaazsuliman7584
@moaazsuliman7584 Жыл бұрын
From Egypt Thank You Very Much
@ramenmanna6150
@ramenmanna6150 Жыл бұрын
Great video sir 😊 understand concepts very well ! love you sir 🥳
@prakash1to7
@prakash1to7 Жыл бұрын
Great way of delivery Sir. Really motivating to learn. Keep on Rocking Sir :-)
@mehedishuvo6257
@mehedishuvo6257 3 ай бұрын
Well explained dear sir.Not only India but also all over the world students get benefited by your lecture,. This is a masterpiece that ever created by you.💜💜💜💜💜,,,,Love from Bangladesh dear sir.
@sahinyusifli9756
@sahinyusifli9756 Жыл бұрын
Thank you, it was so educative to me
@bahasahli4151
@bahasahli4151 5 ай бұрын
Simply awesome thank you 🌼
@rosaliademartino7265
@rosaliademartino7265 Жыл бұрын
nice and clear, thanks!
@vishnusunil7446
@vishnusunil7446 Жыл бұрын
Amazing video.. thank you.
@bharathsajan8926
@bharathsajan8926 2 ай бұрын
wonderfully explained thank you.
@hridikasaha9519
@hridikasaha9519 11 ай бұрын
Excellent explanation
@sn0wball13
@sn0wball13 6 ай бұрын
Thank you so much for this explanation!!!! :)
@srushtishah8674
@srushtishah8674 5 ай бұрын
When i asked my sir about instance variable he gave me such lame ans that I gave up on every being able to understanding it. Thanks!!
@jackfrost8969
@jackfrost8969 Жыл бұрын
excellent video. Keep it up.
@danurarya0823
@danurarya0823 Жыл бұрын
Thanks for this sir, i like when you are describing how things work using a sketch. maybe it's just me but reading documentation that just only have text explanation is really confusing and to imagining it was really hard.
@omkaromkar5215
@omkaromkar5215 10 ай бұрын
Same
@valoranthighlights6374
@valoranthighlights6374 Ай бұрын
great explanation . love it
@HocineFerradj
@HocineFerradj 9 күн бұрын
U are a great teacher
@Coding-Just
@Coding-Just Жыл бұрын
Navin sir it's totally clear thanks a lot and sir i have to join your Java backend course but Saturday is my college sir and it's 3rd year bca 7 to 12 time is not convenient sir
@nasamind
@nasamind 7 ай бұрын
Simply awesome
@marcos_silvestri
@marcos_silvestri Жыл бұрын
Splendid!
@princeiiolaguera921
@princeiiolaguera921 6 ай бұрын
Best course imo. Can you please create exercises so we can test our knowledge and skills so far? Thank you
@rajnishchoubey2246
@rajnishchoubey2246 10 ай бұрын
Sir with reference to memory allocation in java can u plzz specify which of the variables have static memory allocation and which one has dynamic allocation and why
@uchihasenpai5671
@uchihasenpai5671 Жыл бұрын
Shouldn't obj be created after DATA in the stack? I mean should not OBJ be above data?
@alexkuzmichev9051
@alexkuzmichev9051 Жыл бұрын
nicely explained! by the way, what program do you use to draw?
@anupam6045
@anupam6045 Ай бұрын
best explanation sirr
@MohdZaid-kv7yn
@MohdZaid-kv7yn 10 ай бұрын
Watching 2 hours before java developer interview
@Avineshutube
@Avineshutube Ай бұрын
excellent !!
@shyamchowdary5086
@shyamchowdary5086 7 ай бұрын
I have a doubt. When we write a local variable in Java. It automatically allocates memory or it allocates after compilation? Please someone address this.
@HarshPatel-so7gl
@HarshPatel-so7gl 6 ай бұрын
incredible
@adora6860
@adora6860 6 ай бұрын
maraming salamat tol
@FEJAYACHANDRANK
@FEJAYACHANDRANK Жыл бұрын
I have one doubt what if the class is static ... we cant create instance right at the case how is memory allocated
@afsirlaghari3738
@afsirlaghari3738 Жыл бұрын
Love you Naveen sir, from Pakistan.
@unemployedcse3514
@unemployedcse3514 2 ай бұрын
this channel gives trustworthy content where other's just do for content sake
@Trekshorts
@Trekshorts Күн бұрын
sir give us a quetion bank to practice this concepts, all quetions from basic to advance, so we can practice and implement the concepts or logic. your lectures are very easy to understand!! they are very helpful thank you!!!😃😃😃
@user-ql5pe3xc3p
@user-ql5pe3xc3p 5 ай бұрын
I became a diehard fan for you sir ❤ love you and love your teachings sir
@user-ql5pe3xc3p
@user-ql5pe3xc3p 5 ай бұрын
Thank You SIR ✨ This is my status today 🫴 ✨ Thank You SIR 💫
@-RimuruTempest
@-RimuruTempest Жыл бұрын
Hi, I have one doubt. What about the add method in stack? If we create two objects then the is there two add stack?
@YuvarajRoll
@YuvarajRoll 9 ай бұрын
Sir how to get input from users in java
@aaaeditzforever
@aaaeditzforever 8 ай бұрын
Super
@actandrepeat
@actandrepeat Жыл бұрын
Wow!
@srinivasmb-re8km
@srinivasmb-re8km Жыл бұрын
Where static variables are stored? static int in = 10;
@ashutoshraj8668
@ashutoshraj8668 9 ай бұрын
But sir methods of objects are stored in method area😢
@abhishekmb7690
@abhishekmb7690 Жыл бұрын
Where the memory will be allocated for static members and static methods sir
@HimakumarTellaboina
@HimakumarTellaboina Жыл бұрын
Stack Area
@abhiroy1993
@abhiroy1993 Жыл бұрын
Will the 'add' method stack be reused for the 2 different objects or will it create a new 'add' method stack for obj1?
@Krishna_script
@Krishna_script 10 ай бұрын
the new obj1 will reuse the add method which is there in the stack
@saumyojitdas4212
@saumyojitdas4212 9 ай бұрын
​@@Krishna_scriptpublic class Main { String s = "ABC"; public static void main(String[] args) { Main obj = new Main() ; System.out.println(obj.s); } } in this above code String object is created in heap and also of class. So 2 objects in heap. But isn't the string object Abc resides inside class object in the heap?that's why we are calling it obj.s
@ummersiddique
@ummersiddique 15 күн бұрын
Which device is he using for drawing?
@papo7936
@papo7936 10 ай бұрын
Could you replicate this video for python too?
@Ounknown098
@Ounknown098 Жыл бұрын
i am comming from pw skills to watch full memory alliocaion
@keinsent
@keinsent 3 ай бұрын
tqsmomg
@saumyojitdas4212
@saumyojitdas4212 9 ай бұрын
public class Main { String s = "ABC"; public static void main(String[] args) { Main obj = new Main() ; System.out.println(obj.s); } } in this above code String object is created in heap and also of class. So 2 objects in heap. But isn't the string object Abc resides inside class object in the heap?that's why we are calling it obj.s
@ganesang7217
@ganesang7217 5 ай бұрын
I understand clearly, it's not an object. It's a reference type.like Car c = new Car() c is reference type, correct or not
@partoon863
@partoon863 11 ай бұрын
If you guide us in Hindi we understand it more clearly
@jatinsharma3792
@jatinsharma3792 10 ай бұрын
You beauty !!
@rajattalreja9740
@rajattalreja9740 Жыл бұрын
One question - Exactly when is a stack created? When the method is created of when the method is called?
@sachinkhatri1077
@sachinkhatri1077 Жыл бұрын
I think stack memory allocated at run time. So it created when mehod is called. Thats why we get stackoverflow error at runtime instead of compile time.
@banujan.b2479
@banujan.b2479 5 ай бұрын
To be more specific the entire program has a stack. But when you call a method, each method creates a stack-frame in the stack.
@mohokhachai
@mohokhachai 10 ай бұрын
Scope
@mohokhachai
@mohokhachai 10 ай бұрын
Thier only one main entry function
@mohokhachai
@mohokhachai 10 ай бұрын
Thier values is null
@congdatt
@congdatt 4 ай бұрын
Stack: - Store local variables - Address of obj ( obj store in HEAP ) Heap: - Store obj. Have 2 sections: instance variables & .... (add(),....) Every method have own stack
@mohokhachai
@mohokhachai 10 ай бұрын
Entry point
@banujan.b2479
@banujan.b2479 5 ай бұрын
Each method has own stack or stack-frame? 🙄
@RamSingh-bi9tc
@RamSingh-bi9tc Ай бұрын
But damaging one phone affect the user heart
@ehteerk
@ehteerk 11 ай бұрын
An instance variable is a variable that is specific to a certain object. It is declared within the curly braces of the class but outside of any method. The value of an instance variable can be changed by any method in the class, but it is not accessible from outside the class
@muthukumarthangapandian8434
@muthukumarthangapandian8434 Жыл бұрын
both objects having same address only. if car1 =car2 class Car { String name; int cost; double mileage; } public class PassByReference { public static void main(String arg[]) { Car car1 =new Car(); System.out.println(car1.name); System.out.println(car1.cost); System.out.println(car1.mileage); car1.name="bmw"; car1.cost=1_00_0000; car1.mileage=17.5; System.out.println(car1.name); System.out.println(car1.cost); System.out.println(car1.mileage); Car car2=car1; System.out.println(car2.name); System.out.println(car2.cost); System.out.println(car2.mileage); car2.name="honda"; car2.cost=1_00_000; car2.mileage=18.5; System.out.println(car2.name); System.out.println(car2.cost); System.out.println(car2.mileage); System.out.println(car1.name); System.out.println(car1.cost); System.out.println(car1.mileage); System.out.println( car1.hashCode()); System.out.println( car2.hashCode()); System.out.println(car1); System.out.println(car2); } }
@navingautam8878
@navingautam8878 Жыл бұрын
same name haha
@ahmedyoussef7923
@ahmedyoussef7923 12 күн бұрын
It is wrong. we don't have multiple stacks in a single thread.
@khanhgiapham-mi4hg
@khanhgiapham-mi4hg Жыл бұрын
please speak English sir
#27 Need of an Array in Java
3:51
Telusko
Рет қаралды 95 М.
#52 Method Overriding in Java
7:57
Telusko
Рет қаралды 120 М.
New model rc bird unboxing and testing
00:10
Ruhul Shorts
Рет қаралды 23 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 126 МЛН
This is not my neighbor  Terrible neighbor! #funny #zoonomaly #memes
00:26
9. Java Memory Management and Garbage Collection in Depth
48:48
Concept && Coding - by Shrayansh
Рет қаралды 57 М.
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,4 МЛН
Every Developer Should Know This
15:38
ArjanCodes
Рет қаралды 23 М.
#23 JDK JRE JVM in Java
5:22
Telusko
Рет қаралды 214 М.
Stack vs Heap Memory - Simple Explanation
5:28
Alex Hyett
Рет қаралды 207 М.
#22 Class and Object Practical in Java
15:36
Telusko
Рет қаралды 206 М.
Stack vs Heap Memory - Java Memory Management (Pointers and dynamic memory)
30:55
Java Strings are Immutable - Here's What That Actually Means
7:06
Coding with John
Рет қаралды 608 М.
#29 Multi Dimensional Array in Java
13:08
Telusko
Рет қаралды 133 М.
ГОСЗАКУПОЧНЫЙ ПК за 10 тысяч рублей
36:28
Ремонтяш
Рет қаралды 537 М.
Easy Art with AR Drawing App - Step by step for Beginners
0:27
Melli Art School
Рет қаралды 15 МЛН
Kumanda İle Bilgisayarı Yönetmek #shorts
0:29
Osman Kabadayı
Рет қаралды 486 М.