Programming Tutorials

Interview Question: What is lazy loading?

By: Ash in Interview Tutorials on 2008-08-13  

Question:What is lazy loading?

Answer:

Lazy loading means not creating an object until the first time it is accessed. Lazy loading typically looks like this:

import java.util.Vector;

public class Example {
    private Vector data = null;

    public Vector getData() {
        if (this.data == null) {
            this.data = new Vector();
            // Load data into vector ...
        }
        return this.data;
    }
}

This technique is most useful when you have large hierarchies of objects (such as a product catalog). You can lazy-load subordinate objects as you navigate down the hierarchy, and thereby only create objects when you need them.

 

 

 

 





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Interview )

What is transient variable?

What is the difference between interface and abstract class?

What are the call back methods in Session bean?

What is the difference between Session Bean and Entity Bean?

Interview Question: Do ActionForms have to be true JavaBeans?

Question: What is a Hidden Comment in JSP?

Interview Question: What is difference between EJB 1.1 and EJB 2.0?

Question: What is an Expression tag in JSP?

Interview Question: Is there a particularly good IDE to use with Struts ?

Interview Question: What is lazy loading?

Interview Question: What is EJB container?

Interview Question: What is the difference between sessioncontext and entitycontext?

What is difference between Java Bean and Enterprise Java Bean?

What is Collection API?

What is similarities/difference between an Abstract class and Interface?

Latest Articles (in Interview)