Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Question on Bean Law

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In HF on page 350,it says bean should have public no arg constructor.We don't have to write one explicitly right? I mean if we don't provide one,by default public no arg constructor is included by JVM right?

Thanks
Veena
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
U can either provide one or leave it to the compiler to produce the default no arg constructor. But incase u have written a constructor which takes one argument then u have to write code to implement ur no arg constructor as well.Hope i am clear.
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

We don't have to write one explicitly right? I mean if we don't provide one,by default public no arg constructor is included by JVM right?



This is similar to every other class in Java. There would always be a default constructor with no arguments, unless you write one which takes any arguments. When we provide a constructor with arguments, there would not be any no-arg default constructor. The Bean Law says that it should have a no-arg constructor for it to work. So if you write any constructor with arguments, you need to provide a no-arg constructor also. I don't think your arg constructor will ever be called even if you provided one.

Thanks
Chandu
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted to make sure I dont have to write one(no arg constructor) explicitly.

Thanks
Veena
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats true....

Thanks
Chandu
 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember the J2EE classes are still J2SE fully compliant, which means Java rules apply to them. Don't get fooled by questions comparing J2EE classes to J2SE classes. Same rules apply.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic