In this article, we will discuss how to generate getters & setters for all member variables of a class
- Often for any POJO, getter & setter are very important
- And also their case-convention need to be followed
- So that it can be used in JSP tags.
- Everyone has to write code on plain text file (file name with extension ending .java)
- With the release of IDE by various vendors helped developer in a long way to write/code only important business logics
- With IDE, generating getter/setter, constructor, renaming, refactoring, etc. becomes very easy
- With Eclipse IDE, writing/coding getter & setter is very easy within few shortcut keys and it has Menu to navigate through
- There are similar shortcut keys available in all other leading IDE like NetBeans, IntelliJ, etc.
Generate getter and setter in Eclipse IDE:
Step 1: create a POJO with 4 member variables
Step 2: generate setter/getter
Right-click on the Java file –> Select Source –> Generate Getter and Setters
Step 3: choose fields for which you want to generate getters and setter
- Additionally, we can specify Access Modifier for all getters/setters
- it can limited by un-checking fields whichever isn’t required
- allows to specify Insertion point after which generated setter/getter needs to be placed
Step 4: View Java file with all attributes and their getter/setter
Here, it is !!
Happy Coding !!
Happy Learning !!