Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Bean Law

 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • 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
 
georgy jacob
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • 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.
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • 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: 442
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thats true....

Thanks
Chandu
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic