Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
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
Marshal
Posts: 34973
379
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic