aspose file tools*
The moose likes Beginning Java and the fly likes Final class and loading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Final class and loading" Watch "Final class and loading" New topic
Author

Final class and loading

P. Ingle
Ranch Hand

Joined: Apr 25, 2005
Posts: 45
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


Thanks,<br />P.Ingle
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
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.


James Carman, President<br />Carman Consulting, Inc.
P. Ingle
Ranch Hand

Joined: Apr 25, 2005
Posts: 45
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

Joined: Feb 20, 2001
Posts: 580
The static methods delegate to an instance method...

P. Ingle
Ranch Hand

Joined: Apr 25, 2005
Posts: 45
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

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Final class and loading