Solved

Java Questions

Posted on 2000-05-14
4
215 Views
Last Modified: 2010-04-01

1)if an object is created inside the static block of a class when it will be destroyed?
will it be destroyed when then are no more objects of class containing the static block?
please Explain.

2)How weak reference is used to determine when an object is no longer being referenced?

3)Does the List class Supports doubly linked list only or single linked list is also provided by it?

Thanks sridhar
0
Comment
Question by:kesavan_sridhar
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 50 total points
ID: 2809382
1) If an object is created inside the static block of a class when it will be destroyed? Will it be destroyed when then are no more objects of class containing the static block? Please Explain.

Answer: The static initialization block exists to allow "complex" initialization of static class members. According to the JVM spec, a class will be initialized immediately before an instance of the class is created, a static method is invoked, or a nonconstant static field is referenced or assigned. As with initialization, the lifetime of static members is directly related to the lifetime of the class itself. As long as the class is loaded, its static members will be accessible. The rules for class unloading, as of Java 2, are that a class may only be unloaded if its class loader is unreachable. The bootstrap class loader is always reachable; as a result, system classes may never be unloaded. In practice, this means that once a class is loaded, it is unlikely that it will ever be unloaded. This prevents problems that were prevalent in pre-jdk1.2 days with classes implementing the Singleton pattern being unloaded improperly. In short, assuming you don't release the object at some other time, an object created in a static initialization block will be effectively available for the lifetime of your application.

----------
2) How weak reference is used to determine when an object is no longer being referenced?

Answer: The traditional definition of unreachable object which is a candidate for garbage collection candidate an object to which there are no more active references. Reachable objects consist of those pointed to by class variables (both static and instance), objects pointed to by local variables in the currently active methods of all threads, and any other objects reachable from these referenced objects. This is the traditional definition. Weak, Soft, and Phantom references change the picture by introducing new kinds of references that permit more refined collaboration with the garbage collector. Weak references are a way of keeping a reference to an object but considering this reference as "second-class". When no standard references to the object exist, the garbage collector is welcome to reclaim it even if there are weak references. So all the old garbage collection rules still apply. A weak reference is just a way of saying, "I need a reference to this object because I'm doing something for another object (my client) that depends on this. When my client doesn't need this reference anymore, then neither do I. Furthermore, I don't want my client to have to tell me when that happens."

----------
3) Does the List class Supports doubly linked list only or single linked list is also provided by it?

Answer: List is an interface that defines the operations to be supported by an ordered collection (or sequence). There are several concrete implementations of List including the LinkedList class which IS a doubly-linked list. Its iterator, returned by LinkedList.listIterator is a ListIterator which extends Iterator to allow traversal of the list in either direction and modification of the list during traversal.

Best regards,
Jim Cakalic
0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2809603
Hi JIM:-

      For some reasons JOD ( one of Top 15 java experts )in EE is not participatig in
      this site from some time.

      You are filling that vacuum with Your excellent comments

      Both of Ur style is same in answering questions.

      I will appreciate it.

      Thanks

:)
0
 

Author Comment

by:kesavan_sridhar
ID: 2815644
Thank You Very much for Your answers,JIM

Bye sridhar
0
 

Author Comment

by:kesavan_sridhar
ID: 2815648
Thanks

Bye sridhar
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
recursion example 16 126
eclipse buid path vs tomcat lib path 10 23
CSV file parsing thru Java 13 28
eclipse console opening separately 2 19
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question