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
Solved

Java Questions

Posted on 2000-05-14
4
220 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java SE 8u111  Lot of stuff broke 11 88
arguments to jar 5 33
ejb entity bean example issue 2 16
swing controls 2 15
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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:
This video teaches viewers about errors in exception handling.

790 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