File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes static and non-static relationship question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static and non-static relationship question" Watch "static and non-static relationship question" New topic

static and non-static relationship question

Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
Hello Coders J
My program consist of several classes. I find it more readable,logic and useful to declare all the methods in all the classes �static� and get access by Class.member().
The problem showed up when I must use a java biuld-in method( as Component.remove ) within my static method , then I receive compile error.
The first alternative is to create the class instance inside the static my static method , the second is to use interface which declare its member as static final. The two ways doesn�t fit to my needs , do anyone know another way?
Thanks in advance
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
It is really hard to say without seeing any code, but if you pass a reference to the instance of the Component as a parameter to the static method and use it as a local variable you can act on it.
Many of the methods in the API are static and take in objects.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
i feel like an OOP's traitor I�ve been told that I violate the OOP design�s rules in Java�s OOP design whenever I use only static members instead of creating class instances. Can anyone tell about the deficiencies and advantages of using the both form static and OOP?
Shay Gage
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

I guess I don't understand why you want to declare everything static. You say it is more "readable, logic and useful", but I don't know what you mean.
You need to be careful if you are declaring everything static. static means you only have one copy and if you have different code all calling the same static method you can get confusing results.

Please ignore post, I have no idea what I am talking about.
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
If you are using all static code, it seems that you are only doing procedural programming and using classes as functions rather than using abstraction, polymorphism, inheritance, and encapsulation which are the cornerstones of OOP.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link:
subject: static and non-static relationship question
It's not a secret anymore!