Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Memory leaks and static variables

 
deepti bellubbi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have been reading up on coding practices that could cause memory leaks and one of them is using static variables or classes,
Since they will remain for lifetime of the application.

Question that comes to my mind is that:- usually when we define a constants file its mostly a class and all the strings are defined as :
public static final String ABC="Constant1";

Now another way of defining the same string as a constant would be to have an interface and within the interface you define

String ABC="Constant1";


Would using an interface to define constants rather than have a class with static definitions make any difference in concerns with memory saving?

Appreciate all your inputs




 
shivendra tripathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever you define a variable in interface by default it is public static and final. So I don't see any difference in both the cases.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic