General Java Questions I
network monitors will share this interface, but they may have a class heirarchy that is
very different, for example, port monitors may all fork a thread that periodically
checks whereas our control panel interface just asks for the most recent answer;
hardware monitors may ask for their data in real time or over RPC and thus have no
need of inheriting from Thread.
Because they share the same Interface definition, the control panel application does
not need to know if they are polling monitors or real time monitors because, from the
control panel s point of view, it does not matter
  
...
P.S. by John
Also interfaces make our life (I mean programmers) much easier.
Imagine a big project ( a lot of programmers, many packages, thousands of files): it is
impossible all the time to be aware about particular implementation of some method
in specific class in another package!
Much easier to define interfaces between packages as some kind of bridges or gates
into another package and their functionality, with hidden (for us) implementation. We
just know interface and method names. It is enough to use those methods.
How it is implemented there does no matter... It is working!
Q: Is a static variables value likely to be garbage collected once objects of the
class are no longer pointing to it? Does it destroy itself at any point or must that be
done explicitly?
I have a class with a static variable I create two instances of this class.
In each instance I modify the static variable. Then I destroy the objects(point them to
null), then create another instance of the same class and reference the static
variable.
Answer: No   the static variables are effectively linked to the Class object 
rather than any instances; they will only be garbage collected when the 
Class is garbage collected. This will only happen if the ClassLoader 
which loaded the Class is garbage collected.
   
Jon Skeet
http://www.pobox.com/~skeet
 Q: I find such function, but in Class class. Is it possible to use it (or something like
this) in another class? Exactly I would like call: super.super.method1();
Answer: No, you can only access methods of your direct ancestor.
The only way to do this is by using reflection:
import java.lang.reflect.*;
Class superduper = this.getClass().
getSuperClass().
getSuperClass();
Method ssMethod = superduper.getMethod("method1",null);
ssMethod.invoke(this,null);
(I didn t check the exact syntax and parameters of the above code.)
However the necessity to skip a hierarchy shows that there is something wrong with
file:///F|/a_jsite/350_tips/general_java I.htm (31 of 33) [2001 07 08 11:24:51]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved