Ratna Dinakar has posted 2 posts at DZone. View Full User Profile

Java Bean Code Generation In Eclipse

  • submit to reddit

Where would we be without JavaBeans? We use them in all our basic Java applications. We have Struts Form Beans, Hibernate and Spring POJO's and the list goes on. We are all used to writing setters and getters in for our Java Bean's manually. With thanks to Eclipse and other plugins, this effort is now very very easy.

This tip is for the beginners (seniors, this is my first quick tip post) to generate setters and getters in a Java Bean class.

  • First declare all the variables you need in the class.


  • Next, right click any where on the source file. Select Source and then Generate Getters and Setters. This can be done alternatively by pressing Alt+Shift+S.


  • Now select the variables for which you want to generate the getters and setters and you're done. As you can see there are multiple options in the window.


  • Finally, the source code is..

Happy Coding! 
Until Next Time... RD
s1.PNG5.95 KB
s2.PNG31.37 KB
s3.png16.39 KB
s4.PNG19.96 KB
Your rating: None Average: 1.5 (8 votes)
Published at DZone with permission of its author, Ratna Dinakar Tumuluri.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Niel Eyde replied on Tue, 2008/03/25 - 3:05pm

I noticed you tagged this post as "eclipse code generation".  Have you looked at an open source project called Skyway Builder.  It strongly leverages Eclipse and existing Eclipse-based technologies (i.e. EMF, GMF, WTP) to build web application and services using a modeling and a lot of code generation. The project (currently in beta 1) introduces a meta-data model that let's you build entire applications (based on the Spring Framework and Spring MVC) without writing code.  It generates your beans, event handlers, services, spring configuration files, and hibernate config files.  Of course if you still want to code part of your solution...no problem. You can easily blend your custom code or existing java libraries with the models.

Ratna Dinakar T... replied on Tue, 2008/03/25 - 9:45pm

Hi Niel,

     I have specified it clearly that its for beginners, also not only for web-application's we require beans even for normal java apps too. Any way thanks for info regarding Skyway  Builder which i was unaware of :) . Have fun !

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.