Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in Effective Java

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
I could not understand some parts(i.e Bold Text) of the Effective Java of item 71 it says,

Lazy initialization is the act of delaying the initialization of a field until its
value is needed. If the value is never needed, the field is never initialized. This
technique is applicable to both static and instance fields. While lazy initialization
is primarily an optimization, it can also be used to break harmful circularities in
class and instance initialization



Thanks & Regards,
Surya.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
suppose this is your class(DTO)



if user enter the value for usdf ,then only you plan to create a object for UserDefinedField[using Factory method getUserDefinedField()] and want to set the value. otherwise(if user ignore the UserDefinedField ) there is no need for creating an Object for usdf.

Getting my explaination ?
 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure, but I think circularity in class initialization would occur if initialization of one class(say A) depends on initialization of other(say B) and at the same time initialization of the other class(B) depends on initialization of the first class(A). The dependency graph will have a loop. Typically, class initialization is the process of loading the class in memory and then initializing the static variables of the class to their values.


 
Marshal
Posts: 79532
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
seetharaman venkatasamy, shouldn't there be a != null test somewhere in that method. Otherwise you will return a different value every time the method is called.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's the *particularly* lazy-initialization approach.
 
Campbell Ritchie
Marshal
Posts: 79532
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:It's the *particularly* lazy-initialization approach.

Touche
 
Campbell Ritchie
Marshal
Posts: 79532
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
surya.raaj prakash, have you checked the Bloch05 reference given in Effective Java?
 
surya.raaj prakash
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Campbell Ritchie,
Thanks For Your Reply,

Campbell Ritchie wrote:surya.raaj prakash, have you checked the Bloch05 reference given in Effective Java?


Yes,I have checked. you mean Java Puzzlers By Joshua Bloch, Neal Gafter Right?
And This is an excellent Books,again thank you cambell...for given the great reference
 
please buy my thing and then I'll have more money:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic