File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes lazy initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "lazy initialization " Watch "lazy initialization " New topic

lazy initialization

basia fish

Joined: Aug 04, 2003
Posts: 17

how do i use lazy initialization
how would it change code like this

private int array[];

public void setArray(int arr[])
public int[] getArray)()
return array;

help really apprecaited
thanks a lot
Dipen Javia

Joined: Jun 12, 2004
Posts: 5
Hey barb,

I am sorry barb but i couldnt understand what you are trying to do with that code and I didnt understand the term "lazy initialization".

Dipen Javia.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Lazy instantiation/initialisation means you don't initialise a member until the first time that member is requested somewhere.

Typically you'd have something like

Typically it's used when the initialisation of the data is expensive and won't be required for every instance of the class. Using lazy instantiation in such cases yields a performance win for many users of the class either by using less CPU cycles and/or less memory.

I agree. Here's the link:
subject: lazy initialization
jQuery in Action, 3rd edition