My idea in the Java memory management is not fully clear.
We know that methods will load in stack and objects in heap.
eg.
method() {
ExampleClass ec=new ExampleClass();
}
Now when the method will load in stack, what will happen to the object? will it be automatically excluded from the method and will load in the heap ?
No.
What will be loaded in the stack is the reference to the object. Same if you pass the method as a parameter.
The fact that Java does not have pointers like C or C++ does not mean that they are not there. It is just that (apart from primitives) they are everywhere.