General Java Questions III
 Q: Why developers should not write programs that call  sun  packages?
Answer: Java Software supports into the future only classes in java.* packages, not
sun.* packages. In general, API in sun.* is subject to change at any time without
notice. 
A Java program that directly calls into sun.* packages is not guaranteed to work on
all Java compatible platforms. In fact, such a program is not guaranteed to work
even in future versions on the same platform. 
For these reasons, there is no documentation available for the sun.* classes.
Platform independence is one of the great advantages of developing in the Java
programming language. Furthermore, Sun and our licensees of Java technology are
committed to maintaining backward compatibility of the APIs for future versions of
the Java platform. (Except for code that relies on serious bugs that we later fix.) This
means that once your program is written, the class files will work in future releases. 
For more details, see the article Why Developers Should Not Write Programs That
Call  sun  Packages. 
http://java.sun.com/products/jdk/faq/faq sun packages.html
Q: Can garbage collector remove my singleton?
A usually singleton..
public class Single{
   private static Single single;
   private Single {}
   public static Single getInstance(){
      if(single==null){
         single = new Single();
      }
      return single;
  }
}
Well,, seems good ?
But classes are objects too...so do Java 2 v1.3 class garbagecollecting? Meaning my
singleton could dissapear if i dont keep a refrence to it (or the class itself)
somewhere ?
If classes is not garbagecollected, that s pretty stupid, I dont want classes taking up
memory when i perhaps never will use it again....
Answer: No. Classes can define objects. That is, only the dynamic part of the class
defines objects. The static part exists only in one place in memory and can not be
duplicated. You can call the getInstance() method from anywhere in your program. 
Java requires however that you tell where to find the method, in this case in the
Single class.
Therefore, you should use
Single.getInstance()
to get the instance. This is (though it looks much like it) not an execution of a method
on an object, but just a method call without object. Single is only used to find out
which getInstance() method should be used, and where it is.
file:///F|/a_jsite/350_tips/general_java III.htm (5 of 9) [2001 07 08 11:24:53]






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