• Post Reply Bookmark Topic Watch Topic
  • New Topic

why we use logger instance as a static in java(Priorty urgent)  RSS feed

 
Ashutosh kumar singh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why i use logger instance is static in java file. We can use without static also
then what is the reason. Can any body give me brief idea.

ex.

static Logger logger = Logger.getLogger(ABC.class);
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37256
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashutosh,
If it is static, there is only one copy for all instances of the class. This means "Logger.getLogger(ABC.class);" is executed less times. If it is doing something resource intensive like reading a file or using reflection, this saves time and makes your program faster.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!