In this article, we will discuss how to generate getters & setters for all member variables of a class
1. Earlier era :
- 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)
2. IDE era :
- 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.
3. Generate getters/setters 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 !!
4. Useful Eclipse IDE shortcuts :
- Eclipse IDE – How to show line numbers ?
- Eclipse IDE – How to GO TO any line number directly ?
- Eclipse IDE – How to remove unused imports ?
- Eclipse IDE – How to clean project ?
- Eclipse IDE – How to build Java project automatically ?
- Eclipse IDE – How to comment and un-comment line & block ?
- Eclipse IDE – How to generate constructor using fields ?
- Eclipse IDE – How to generate getters and setters ?
- Eclipse IDE – How to search files ?
- Eclipse IDE – How to locate methods in Java file ?
- Eclipse IDE – How to open editor using CTRL + E ?
- Eclipse IDE – Java compiler compliance level issue
Related Articles:
- Apache Maven – Introduction
- Apache Maven – Install on Windows 7 OS
- Apache Maven – Settings.xml explanation
- Apache Maven – Proxy setting explanation
- Apache Maven – pom.xml explanation
- Apache Maven – Plugins explanation
- Apache Maven – Changing default Maven repository location in Windows 7 OS
- Apache Maven – Local, Central and Remote Repositories
- Apache Maven – Installing custom library into local repository
- Apache Maven – Transitive dependencies explanation
- Apache Maven – Exclusion of Transitive dependencies
- Apache Maven – Dependency Scopes
- Apache Maven – Skipping unit test using surefire plugin
- Apache Maven – Exclusions and Inclusions of unit test
- Apache Maven – offline execution
- Apache Maven – Co-ordinates explained
- Eclipse + Maven – Integration
- Eclipse + Maven – How to import Maven project with pom.xml ?
- Eclipse + Maven – Setting M2_REPO classpath variable in IDE
- Eclipse + Maven – M2_REPO is Non Modifiable
- Eclipse + Maven – Creating and exploring projects using archetypes
- Eclipse + Maven – Converting Web project to Maven project
- Eclipse + Maven – mvn eclipse:eclipse command
- Eclipse + Maven – Plugin execution not covered by lifecycle configuration
References:
- https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-source.htm
- https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-dialog-gettersetter.htm
Happy Coding !!
Happy Learning !!