• 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Difference

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any one tell me the difference between initializer and a constructor
uma
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
contructors can be used to initialize variables. there is no "thing" such as an Initializer in Java
 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there is no such thing called Initializer. But Java does initialization in certain cases i.e. statics, instance(if not initialised) and reference(set to null) and Arrays and Strings too.
char initialised to '\u0000'
byte to 0
short to 0
int to 0
float to 0.0f
double to 0.0d
object refence to null
boolian to false
I think Arrays and Strings are also set to null when it is declared.
Anybody please clarify.
Thanks
[This message has been edited by V Srinivasan (edited February 13, 2001).]
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Initializers are similar to Constructors in functionality.
They are mainly used in Anonymous classes, where we don't have the luxury of Constructors.
 
uma sakthi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply..
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Uma
Initializers are used in initialization of objects and classes. They can also be used to define constants in interfaces. The initializers come in the following flavours:
- static and Instance variable initializer expressions
- static initializer blocks
- instance initializer blocks.
During creation of an object, constructor from the super class is invoked, then instance initializers are invoked in the order in which they are specified.
You can refer to page 265 - for detailed explanation from Khalid A.Mughal's book in case you have this book.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
Both initialzer and constructor are used to initialize objects. Initializer gets called before the constructor within the same class. For annonymous class, we must use initializer since constructor is not available (since the annonymous class doesn't have a name).
LHS
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic