?
Solved

Java Questions

Posted on 2000-05-14
4
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

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