Accepted answer

bring up the context menu (i.e. right click) in the source code window of the desired class. then select the source submenu; from that menu selecting generate getters and setters... will cause a wizard window to appear.

source -> generate getters and setters...

select the variables you wish to create getters and setters for and click ok.


  1. open the class file in eclipse
  2. double click on the class name or highlight it
  3. then navigate to source -> insert code
  4. click on getter and setter

it opens a popup to select the fields for which getter/setter methods to be generated. select the fields and click on "generate" button. enter image description hereenter image description here


use project lombok or better kotlin for your pojos.

(also, to add kotlin to your resume ;) )

this :

public class basevo {
    protected long id;

    public boolean equals(object obj) {
        if (obj == null || id == null)
            return false;

        if (obj instanceof basevo)
            return ((basevo) obj).getid().equals(id);

        return false; 

    public int hashcode() {
        return id == null ? null : id.hashcode();
    // getter setter here

public class subclass extends basevo {
    protected string name;
    protected string category;
    // getter setter here

would become this :

open class basevo(var id: long? = null) {

    override fun hashcode(): int {
        if (id != null)
            return id.hashcode()

        return super.hashcode()

    override fun equals(other: any?): boolean {
        if (id == null || other == null || other !is basevo)
            return false

        return id.hashcode() ==

class subclass(
        var name: string? = null,
        var category: string? = null
) : basevo()

or use kotlin's "data" classes. you end up writing even fewer lines of code.


right click on the property you want to generate the getter and setters for and choose

source -> generate getters and setters...


1) go to windows->preferences->general->keys

2) select the command "generate getters and setters"

3) in the binding, press the shortcut to like to use (like alt+shift+g)

4) click apply and you are good to go


eclipse > source > generate getters and setters


**in eclipse ide

for generating both setters and getters -> alt+shift+s+r then alt a then click on ok;

for generating only getters ->alt+shift+s+r then press g then click on ok button;

for generating only setters ->alt+shift+s+r then press l then click on ok button;**


there is an open source jar available know as lombok , you just add jar and then annotate your pojo with @getter & @setter it will create getters and setters automatically.

apart from this we can use other features like @tostring ,@equalsandhashcode and pretty other cool stuff which removes vanilla code from your application


press alt+shift+s+r... and then only select which all fields you have to generate getters or setters or both


  • for all variable alt+shift+s then r and for select all press alt+a

  • for single variable point cursor on the variable then press ctrl+1 and go for the second option from suggestions



i prefer to create the private field first

private string field;

eclipse will auto highlight the variable, by positioning cursor over your new variable, press ctrl + 1. it will then give you the menu to create getter and setter.

i press ctrl + 1 because it is a bit more intelligent about what i think you want next.


yes. right-click on code and you see a menu pop up; there "source", "generate getters and setters" and next to it you can see the shortcut, which is alt+shift+s and r on my system.

similarly you can navigate to other submenus in that main menu, by typing the appropriate shortcut you go straight the submenu instead of main context menu, and can then either pick from menu or type another letter to pick from the list.


on mac os it's alt+cmd+s then select "...getters and setters"



use generate getters and setters from the source menu or the context menu on a selected field or type, or a text selection in a type to open the dialog. the generate getters and setters dialog shows getters and setters for all fields of the selected type. the methods are grouped by the type's fields.

take a look at the help documentation for more information.


right click-> generate getters and setters does the job well but if you want to create a keyboard shortcut in eclipse in windows, you can follow the following steps:

  1. go to window > preferences
  2. go to general > keys
  3. list for "quick assist - create getter/setter for field"
  4. in the "binding" textfield below, hold the desired keys (in my case, i use alt + shift + g)
  5. hit apply and ok
  6. now in your java editor, select the field you want to create getter/setter methods for and press the shortcut you setup in step 4. hit ok in this window to create the methods.

hope this helps!


ways to generate getters & setters -

1) press alt+shift+s, then r
2) right click -> source -> generate getters & setters
3) go to source menu -> generate getters & setters
4) go to windows menu -> preferences -> general -> keys (write generate getters & setters on text field)
5) click on error bulb of the field -> create getters & setters ...
6) press ctrl+3 and write getters & setters on text field then select option generate getters & setters

if mac os press alt+cmd+s then select getters & setters


all the other answers are just focus on the ide level, these are not the most effective and elegant way to generate getters and setters. if you have tens of attributes, the relevant getters and setters methods will make your class code very verbose.

the best way i ever used to generate getters and setters automatically is using project lombok annotations in your java project, lombok.jar will generate getter and setter method when you compile java code.

you just focus on class attributes/variables naming and definition, lombok will do the rest. this is easy to maintain your code.

for example, if you want to add getter and setter method for age variable, you just add two lombok annotations:

@getter @setter 
public int age = 10;

this is equal to code like that:

private int age = 10;
public int getage() {
    return age;
public void setage(int age) {
    this.age = age;

you can find more details about lombok here: project lombok


right click -> source -> generate setters and getters

but to make it even more convenient, i always map this to alt+shift+g from windows -> preferences -> general -> keys


in eclipse juno, by default, alt+shift+s,r opens the getter/setter dialog box. note you have to press all 4 keys.

Related Query

More Query from same tag