?
Solved

Java Questions

Posted on 2000-05-14
4
Medium Priority
?
243 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 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