This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final class and loading

 
P. Ingle
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a final class with all static methods and no instance varibles in it. I need this class in "Application Scope". Do I need to instatiate it some where( if so where) or JVM Loads it automatically. (When I say final class with all static methods, you can think it being very similar to Math class)

Thanks,
P Ingle
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the problem with static classes such as Math, there is no real object to put into "application scope." That's why Jakarta Commons BeanUtils went to a more bean-like approach with its classes like BeanUtils and PropertyUtils.
 
P. Ingle
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
being a newbie to J2EE and whole Jacarta Apachi project I have to ask - what would that approach be?

Thanks,
P Ingle
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The static methods delegate to an instance method...

 
P. Ingle
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting. How does it behave under Heavy Loads - If I had to use this pattern to implement Class that hands out database connactions or for DAOFactory in high traffic web app, would this be a bottleneck?

Thanks,
P. Ingle
---------------------------
Questions, Questions and more Questions.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it doesn't cause any performance bottlenecks, but it's also not necessary to load a class. The class will simply be loaded when needed, at least before the first static method is called.

The solution shown by James is interesting when you want to change the behaviour at runtime - it's basically a variation of the Strategy pattern, as far as I can tell.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic