Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

what about static methods and static variables? are they stored in stack or heap memory?
- pk
This is very useful. Thanks for your great work. public static void main(String[] args) - what about args? It is stored in stack right?
- kanaga
On the public static void main(String[] args) - Does the memory for args[] allocated in heap space but the reference is allocated in Stack - Is my understanding correct?
- Shaik
Thanks a lot Pankaj. This article is very great! Can You write a article about Thread-Safe? Because I don’t know Why a global variable is not-thread-safe. I reseach very much about it. I use “new” operation but a global variable in that class, it’s not Thread-Safe. Thanks in advance!
- i_know_nothing
This is a very nice explanation of Stack and Heap Memory and their differences. I wish you could write a bit about instance variables and static variables. Well Done !
- Abhishek Thakur
Thank you for sharing this article. One point i have to raise here. regarding “int i = 1”. Not sure if this is because of “escape analysis” or something else like “interning”. But what i tested it goes to “Heap”. Following is my test: package immutable; public class Immutable_One { private int i = 2; public int get() { return i; } } package immutable; public class Immutable_Two { private int j = 2; public int get() { return j; } } package immutable; public class ImmutableTest { public static void main(String[] args) { Immutable_One immutable_One = new Immutable_One(); int i = immutable_One.get(); Immutable_Two immutable_Two = new Immutable_Two(); int j = immutable_Two.get(); if (i == j) { System.out.println("Equal"); } else { System.out.println("NOT Equal"); } } } The result comes “Equal”.
- Arfeen
If it were truly “pass by value” as in the case with c++ then it would be a copy/clone of the object. Calling the foo() method would not affect the blue balloon color value in the main method. But in the example it does because it is “referencing” the memory space in the heap and changing the value. Much like you would when “passing by reference”. However, I also see the point of how the value is used (as if a copy/clone were passed in) in the swap method. The manipulation of the balloon colors in the swap method does not affect the balloons variables in the main method. Its almost like its “pass by reference or value”. In either case the presentation was awesome as well as the write up. Thanks for your efforts.
- Alalonks