Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

Search: 

  Tutorial: Understanding Weak References

Some time ago I was interviewing candidates for a Senior Java Engineer position. Among the many questions I asked was "What can you tell me about weak references?" I wasn't expecting a detailed technical treatise on the subject.

Tutorial Details:

Weak References in Java
I would probably have been satisfied with "Umm... don't they have something to do with garbage collection?" I was instead surprised to find that out of twenty-odd engineers, all of whom had at least five years of Java experience and good qualifications, only two of them even knew that weak references existed, and only one of those two had actual useful knowledge about them. I even explained a bit about them, to see if I got an "Oh yeah" from anybody -- nope. I'm not sure why this knowledge is (evidently) uncommon, as weak references are a massively useful feature which have been around since Java 1.2 was released, over seven years ago.

Now, I'm not suggesting you need to be a weak reference expert to qualify as a decent Java engineer. But I humbly submit that you should at least know what they are -- otherwise how will you know when you should be using them? Since they seem to be a little-known feature, here is a brief overview of what weak references are, how to use them, and when to use them.

Strong references

First I need to start with a refresher on strong references. A strong reference is an ordinary Java reference, the kind you use every day. For example, the code:

StringBuffer buffer = new StringBuffer();

creates a new StringBuffer() and stores a strong reference to it in the variable buffer. Yes, yes, this is kiddie stuff, but bear with me. The important part about strong references -- the part that makes them "strong" -- is how they interact with the garbage collector. Specifically, if an object is reachable via a chain of strong references (strongly reachable), it is not eligible for garbage collection. As you don't want the garbage collector destroying objects you're working on, this is normally exactly what you want.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Understanding Weak References

View Tutorial:
Understanding Weak References

Related Tutorials:

Displaying 1 - 50 of about 437 Related Tutorials.

Preventing Expansion of Entity References
Preventing Expansion of Entity References, XML,XML Tutorials,Online XML... References           ... references while parsing an XML file in a DOM document. JAXP (JavaAPI for XML
 
==, .equals(), and compareTo()
. Comparing Object references with the == and != Operators The two operators that can be used with object references are comparing for equality
 
Understanding Struts Controller
Understanding Struts Controller Understanding Struts Controller                     
 
Java Compare String (== operator)
references are compared. If two String variables point to the same object then these two variables are called references for the same object. So... the references the two strings are pointing to rather than comparing the content
 
Java Notes: Downcasting
Java Notes: Downcasting Java Notes: Downcasting Collections of Objects - The Dark Side There are a lot of things to like about Java Collections, but there are some weak
 
Understanding Data Source
Understanding Data Source Understanding Data Source                        
 
Understanding Connection Object
JDBC Connection, Understanding Connection Object Understanding Connection Object                  
 
Understanding Common SQL statements
Understanding Common SQL statements Understanding Common SQL statements                     
 
Understanding Hibernate element
Understanding Hibernate <generator> element Understanding Hibernate <generator> element               
 
Understanding Hibernate element
Understanding Hibernate <generator> element Understanding Hibernate <generator> element               
 
Understanding Struts Action Class
Understanding Struts Action Class              ...;} }     Understanding Action Class Here
 
Understanding the JDBC Architecture
Understanding the JDBC Architecture Understanding the JDBC Architecture                     
 
Understanding Various MySQL Executable Files
Understanding Various MySQL Executable Files Understanding Various MySQL Executable Files                  
 
Understanding Hibernate O/R Mapping
Understanding Hibernate O/R Mapping Understanding Hibernate O/R Mapping                     
 
Understanding Hello World Java Program
Hello World Program Java,Hello World First Program,Hello World Java,Online Hello World Java Program Understanding Hello World Java Program          
 
Understanding Hello World Java Program
Hello World Program Java,Hello World First Program,Hello World Java,Online Hello World Java Program Understanding Hello World Java Program          
 
Understanding public static void main function
Understanding public static void main function Understanding public static void main function                 
 
Java Notes: Table of Contents
Java Programming Notes Java Notes: Table of Contents Java Notes. These Java programming notes are written to fill in missing or weak topics in textbooks that I've taught from. Many pages are useful
 
Java String Examples
) This section describes how two string references are compared. If two String variables point to the same object then these two variables are called references
 
Java String Examples
) This section describes how two string references are compared. If two String variables point to the same object then these two variables are called references
 
Java Swing
as a widget toolkit for Java and is a part of JFC and are replacement for weak
 
WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS
WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS WEBSERVICE USING APACHE AXIS  TUTORIAL-2   UNDERSTANDING APACHE AXIS   (part-3) (published in DeveloperIQ
 
WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS (part-2)
WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS WEBSERVICE USING APACHE AXIS   TUTORIAL-2  UNDERSTANDING APACHE AXIS (part-2) published in DeveloperIQ..April,2004) 
 
WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS
WEBSERVICE USING APACHE AXIS TUTORIAL-4 UNDERSTANDING APACHE AXIS WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS (part-4)(published in DeveloperIQ..April,2004) (www.developeriq.com
 
WEBSERVICE USING APACHE AXIS -TUTORIAL-2 UNDERSTANDING APACHE AXIS
WEBSERVICES USING APACHE AXIS - TUTORIAL-2 AXIS FOR EJB-WEBSERVICE (part-1) WEBSERVICE USING APACHE AXIS -TUTORIAL-2  UNDERSTANDING APACHE AXIS (part-1)(published in DeveloperIQ..April,2004
 
Java Data Structures
their emphasis is on understanding how data structures are build using only pointers/references and arrays. It's an excellent exercise and is necessary..., and was a form of weak-typing, which allowed run-time type mismatches that should be caught
 
Web Programmer
Description : Client interaction, understanding requirements, coding &
 
JDBC Prepared Statement Update
that help you in understanding JDBC Prepared Statement Update. The code include
 
JDBC Insert Null
; In this Tutorial we want to describe you a code that help in understanding JDBC
 
JavaScript array unique
in understanding array unique. The program uses JavaScript as  scripting language
 
Jdbc connection
we want to describe you a code that helps you in understanding a Jdbc Connection
 
JDBC Drive For Mysql
; In this Tutorial we want to describe you a code that help you in understanding JDBC
 
Get Month Name Example
in understanding a how to get a 'Get Month Name Example'.For this we have
 
JavaScript array methods
you in understanding 'JavaScript array method'. For this we are using
 
JavaScript array of arrays
that help you in understanding JavaScript array of arrays. For this we are using
 
Get Usage Memory Example
in understanding Get Usage Memory. The class Memory Usage include the main method
 
JDBC Connectivity Code In Java
in understanding JDBC Connectivity Code in Java. The code include a class JDBC
 
JDBC Get Int
; In this tutorial we want to describe you a code that help in understanding JDBC Get Int
 
Collections Overview
. WeakHashMap<K, V> // Special usage - Keys are weak references... be accessed in order of creation. WeakHashMapHash table using weak references
 
Getting a absolute path
in understanding Java programming in the most simplest way. Here after reading
 
Write a program for calculating area and perimeter of a rectangle
will be helpful in understanding Java programming in the most simplest way. Here after
 
Java Get Last Line of File
that helps you in understanding Get Last Line of File in Java . For this we have
 
Get Tomorrow Date
; in understanding Get Tomorrow Date. For this we have a class name
 
Get Local Host Name
in understanding a code how to 'Get Local Host Name'. For this we have a class name
 
JavaScript array of numbers
that helps you in understanding 'Java Script array of numbers'. For this we use 
 
JavaScript Array get key
you in understanding JavaScript Array get key. For this we implement JavaScript
 
JavaScript array size
you in understanding JavaScript array Size. The code shows you a HTML Page 
 
JDBC Insert Preparedstatement
you a code that helps you in understanding JDBC Insert Prepared Statement
 
JDBC Insert Preparedstatement
you a code that helps you in understanding JDBC Insert Prepared Statement
 
JavaScript array map
in understanding JavaScript array map. For this we are using a JavaScript language
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.