In some articles and tutorials about static like this and this, it is said that using static is good for memory management, since static variable gets memory only once in class area at the time of class loading.
But my friend told me static methods are kept in stack and because managing heap is easier than stack and garbage collector works only on heap and as long as the application is running stack wouldn't get cleaned, try to use static methods less as much as you can.
NOTE:
I've read same questions in stackoverflow about stack memory but I didn't get much of it, because they are some how complicated and professional using "PermGen space" and other words I don't know.
I want someone simply explain if my friend advance is correct or not?
And I know it depends, imagine that I can design both with static or without static methods. memory management talking which one would be the better way?
The answer is: asking this question means that you spend your time and energy in the wrong place.
The key role to get to Java applications that perform well: come up with an elegant OOP design that implements your requirements in a straight forward way.
You have to understand that "Java performance magic" happens almost completely at run time by the workings of the Just-in-Time compiler. And the JIT is best at those commonly used patterns that we regard "best practices" in Java.
Trying to come up with "special" ideas like "lets use static all over the place" might even result in worse performance in the end - because your "special" code prevents the JIT from doing its job in the best way.
So: trust the JIT respectively the GC. And make sure that these tools can work in an "optimal" way by doing ... what everybody else is doing!
Don't let such thoughts of premature optimization ruin your OOP design. And even if your application would fall into that rare category that requires intensive low level optimization - then there is only one way for you: to study the workings of GC and JIT in depth.
In other words: such problems aren't real problems. Meaning:
And then - when you run into a "real" issue: then you have to profile your application to understand the root cause of the problem. Again: you do not allow for such premature (uneducated) optimization thoughts to affect your design in a negative way.
And as the comment implies that I wasn't clear enough: when you have a real memory problem, then you absolutely have to understand terms like "perm generation". Because then you have to understand in detail how the GC works. Seriously: believe the people here telling you that the static keyword doesn't play any significant role in creating "memory efficient" applications.