File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes static - old and new Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "static - old and new" Watch "static - old and new" New topic
Author

static - old and new

HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
There seems to be a shift in thought from "statics - proceed with extreme caution and only use if you have to " in the old exam to "statics - great stuff, use wherever possible".
Here I am only following gut-feel. Does anyone else have the same feeling ? Is there any current material/references on the use of statics ?

Or is it Singletons I am thinking about ?
regards
[ May 06, 2003: Message edited by: HS Thomas ]
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Can anyone help?
I am thinking of upgrading to the new exam.
There seems to be quite a big change from the old and new.
Th old exam I see as being good for teaching the fundamentals of OO design , a good foundation which will be with you through the rest of your career.
Are there any links/pointers to the objectives of the new exam?
Perhaps it helps with the transition to designing with a full J2EE specification ?
regards
[ May 07, 2003: Message edited by: HS Thomas ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

static, like anything in Java, needs to be used correctly. Meaning when is it good to use and when is it not.
If you have a Factory class that never really gets instantiated, but returns a Class when a person calls one method, then that method should be static. It is the best way to achieve those results.
Now if you have a class that you will have many instances of, then static might not be good to use in your methods.
Now in regards to variables inside classes. Sometimes you want a class that just has Constants, in this case they will be static final variables.
It is always an "it depends" answer.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Thanks, Mark.
I see the same cautionary approach still applies to statics.
If you have a Factory class that never really gets instantiated, but returns a Class when a person calls one method, then that method should be static. It is the best way to achieve those results.

By the above, I take it you mean an Abstract Factory class which I found useful in my first Design cut but removed for simplicity's sake on the good-will advice of this forum.
My first design cut also had lots of static classes which proved unnecessary once I bought into the Connection/LockManager design approach.
Would you still advice the same cautionary approach to the use of Singleton classes?
It is always an "it depends" answer.

Does this depend on whether your design is more database centric or network centric ? I was under the impression that indescretionary use of statics and Singletons could create a multi-threading nightmare and best avoided if one liked to keep it simple. But if you were King/Queen of the multi-threaded world I wouldn't like to spoil your party - more power to your elbow if its what the business wants.
( Sorry, after all the time I've spent on this forum I should be more useful, rather than asking all these questions. . But hey, it's the good bartending that keeps us coming back).
regards
[ May 07, 2003: Message edited by: HS Thomas ]
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Does anyone strongly agree/disagree with the above ?
Especially the bit about considering your design to be database centric or network centric as to how you use statics and Singletons?
regards
[ May 08, 2003: Message edited by: HS Thomas ]
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Or would it be more useful to think in terms of resources (including databases) that are made available over a network ?
How does the use of statics and Singletons affect how you handle multi-threading ? With the Connection/LockManager approach each connection has it's own instances of data and locks, only a few methods in data needed to be synchronised.

Help anyone ? Surely , this area must count towards some of those 400 points ?
I am just asking for a perspective/design approach other than the Connection-LockManager approach?
I am interested because I suspect that we'll come across these in real-life a lot shortly.
regards
[ May 08, 2003: Message edited by: HS Thomas ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

We could let Peter set you straight about the Singleton pattern and its overuse. In the assignment there isn't any classes that require them to be singleton.
As far as my example being an Abstract Factory, that isn't correct. In my example the classes that are returned are known, and there isn't any other type of implementation for that class.
Mark
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
As far as my example being an Abstract Factory, that isn't correct.

I guess the motivation was different in my case where I just wanted to name a resource without being specific what it was and where it lived.
The Abstract Factory did have a Factory Method to return the Concrete resource classes but I cannot remember how it was implemented - ie if it was a static method.
We could let Peter set you straight about the Singleton pattern and its overuse.

I guess Peter is spending his time on bigger things. Look forward to his continuing input from time to time.

Mark , any new info on what the objectives of the new exam are?
I did pick the following objective from Kathy and Bates book which seemed relevant to this thread.
Don't be a Procedural Programmer in an OO World
the symptoms which seem to be
Really Big Classes that have methods for everything. ( guess this objective is well known and understood ).
Lots of static methods -
"In fact all methods should be non-static unless you have a good reason to make them static. This is OO. We don't have global variables and functions. There's no start here and then continue linearly except when you branch.This is OO and that means objects all the way down."
Use Design Patterns
Simplicity is the first concern but if you need a Design Pattern make one. Singletons are used as an example (I suspect as it's the most easily understood and abused).
I guess this book is a good starting point for the new objectives. I couldn't find any other reference to changes in objectives for the new Exam (one would think that Sun would publish some new objectives). Any new light would be useful.
regards
[ May 14, 2003: Message edited by: HS Thomas ]
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Hi,
I found this reference which helped some way towards explaining the differences.
Cookie's and magic cookies ? Those old things have resurfaced ?

This link
I am wondering whether Sierra/Bates book is enough to pass the New Exam well or are there missing areas.
regards
[ May 16, 2003: Message edited by: HS Thomas ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static - old and new