• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

constructor and init.

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have two doubts in mind about constructors and init() method-
1)Since all th initialization is normally done in the init()
method then what is the advantage of having a parameterless
constructor? Normally I do no have any constructor in my applets.
Infact I was under the impression that u cannot have constructors
in the applet untill I saw an applet with the constructor.
There certain variable were declared in init() and others in
a constructor.Wonder Why? .
2)Since the applet works perfectly fine with the constructor I am convinced that one can have a constructor in the applet.This leads to another question which one is called first init() or
constructor.If init() is called first then when is the constructor called?Rather which is the place/rank of the constructor in the life cycle of an applet.
init()=>start()=>paint()=>stop()=>destroy()
Where is constructor?
Please....... clarify.
Thanx in advance.
Best Regards,
Kavita.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I don't know about the usage of presence or absence of constructor, but i may be of help in second question.
The constructor is called before the init. since init etc. would be called only after the applet object is available to the browser and the constructor is called at the time of instantiation of the applet. Once the object is created, the init etc (the sequence ) starts.
hope it clarifies
raghav..
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, constructor is called first followed by init method. In applets it is preffered to put the "initial" code in init() method rather than in constructor. The reason is, applet generally not gauranteed for full environment until its init method is executed. Take for example, loading big images, which may not properly load and available for applet if they are loaded in constructor instead of init method.
Also, execution of init is faster than constructor. Hope, it clears your question.

Originally posted by Kavita Ghia:
Hi,
I have two doubts in mind about constructors and init() method-
1)Since all th initialization is normally done in the init()
method then what is the advantage of having a parameterless
constructor? Normally I do no have any constructor in my applets.
Infact I was under the impression that u cannot have constructors
in the applet untill I saw an applet with the constructor.
There certain variable were declared in init() and others in
a constructor.Wonder Why? .
2)Since the applet works perfectly fine with the constructor I am convinced that one can have a constructor in the applet.This leads to another question which one is called first init() or
constructor.If init() is called first then when is the constructor called?Rather which is the place/rank of the constructor in the life cycle of an applet.
init()=>start()=>paint()=>stop()=>destroy()
Where is constructor?
Please....... clarify.
Thanx in advance.
Best Regards,
Kavita.


 
Kavita Ghia
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rao,
My question was what is the advantage of having the initialization code in the constructor rather than the applet.Bcoz i have been using only init() for initialization and NOT the CONSTRUCTOR.
Reagrds,
Kavita.
 
Kavita Ghia
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends,
I am really keen to know in what way constructors are advantageous to use then the init() method.And if they are not advantageous then why do people use it.Anyone out there please
reply as can't think of its usefullness.Maybe somewhere i am
overlooking certain point.
Regards,
Kavita.
 
Rao Kuna
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is defenetly preferable to use init method than constructor in Applets. Constructor also works but it is not reliable in some cases and for details, you better go to "sun online tutorial --> subject "Applets".
Thanks
Rao

Originally posted by Kavita Ghia:
Hello friends,
I am really keen to know in what way constructors are advantageous to use then the init() method.And if they are not advantageous then why do people use it.Anyone out there please
reply as can't think of its usefullness.Maybe somewhere i am
overlooking certain point.
Regards,
Kavita.


 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic