Generate getters and setters in Eclipse IDE

Still busy writing setters and getters method manually? Actually, Eclipse IDE is able to help you generate the setters and getters method automatically, and this feature is bundle with Eclipse IDE long time ago, surprisingly, many Java developers are not aware of it?

See following steps to show you how.

1. Java Pojo

A simple User.java, with 4 fields, but no getters and setters method.

Java pojo

2. Generate It

Right click on the file, select “Source” –> “Generate Getters and Setters…

getters and setters in eclipse ide

Choose which field you want to generate, and click on “OK” button.

getters and setters in eclipse ide

3. Done

All selected getters and setters methods will be generated automatically.

getters and setters in eclipse ide

So, don’t create those methods manually, it waste time, use IDE.

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

26 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Serhat
13 years ago

Another way:
go over the field then press CTRL + 1, and select “Create getter and setter…”. Done!

ganesh.sg1
7 years ago
Reply to  Serhat

suppose if we added a new field in table and how can i retrieve a value of newly added column

Mike Clark Russ
8 years ago
Reply to  Serhat

Not Working bruh!!!

mrtampan
7 years ago

Thank You mamang mkyong ..

blah
9 years ago

U know what real waste of time?
ECLIPSE

Mike Clark Russ
8 years ago

Thanks a ton!

Namo Bhakth
10 years ago

Hi mk, nice article, I have a question, is it a plugin which provides getters and setters feature in eclipse??

amster
10 years ago

thanks man 😉

andrew
12 years ago

wow, that was so simple and straight to the point. thanks!

Michael Diman
13 years ago

Use Lombok
and use @Data as annotation

venkat
13 years ago

tanq

clement
13 years ago

There’s an error in part 2, second screenshot. It is “field” and not “filed” in the phrase “which filed you want to generate”.

Alex
13 years ago

I mean using java programming language.

Alex
13 years ago

Sir how can i write HTML tags in between a html table

for example

line 1 : html table tags

line 2 : data to be written

line 3 : html table tags

Chris
13 years ago

Hi Mk Yong, I wonder why you don’t user NetBeans IDE to do this all stuff with java.
WebServices, JSF 2.0, Hibernate is more more more simply with NetBeans

felix
13 years ago

are there some shortcut key to do this in batch?
alt + shift + s can open the first window
but how can I do the next without mouse?

Sukru
13 years ago
Reply to  felix

Alt + Shift + S and then press R

x
13 years ago
Reply to  felix

ctrl+shift+g

Roger Keays
13 years ago
Reply to  felix

With Lombok you don’t even need to generate getters and setters. A couple of class-level annotations and you’re done!

Michael Diman
13 years ago
Reply to  mkyong

Use Lombok
and use @Data as annotation

Mike Clark Russ
8 years ago
Reply to  Michael Diman

Okk man!

josemm
13 years ago

Or using lombok 😛

Mike
13 years ago
Reply to  josemm

+1

Rose Stuart
7 years ago
Reply to  Mike

Well, the information is correct. I found the post to be useful, however, I am writing for the people who are facing an issue with their Samsung printer. Click this reference samsung printer error code u1-2320 and get the idea about how to resolve it in just one click.