In this article, we will discuss how to comment & un-comment lines and block of code in Eclipse IDE
At certain times, we want to try-out new things without deleting existing line of code which is already working. Also, it is required to comment & un-comment block of code consisting 3 or more lines of code.
To make this possible, Eclipse IDE provides easy shortcut keys and its respective actions from Menus
1. Shortcut commands in Eclipse IDE :
- CTRL + / –> to comment single line of code
- CTRL + / –> the same works to uncomment the same line of code, which is already commented
- CTRL + SHIFT + / –> to comment block of code consisting of 3 or more lines of code
- CTRL + SHIFT + \ –> to uncomment block of code, which is already commented
Let’s understand each one with simple example in Eclipse IDE:
1.1 To comment single line of code
- Move to the line where we are interested to comment
- Press CTRL + / together
Menu option in Eclipe IDE :
- press CTRL + / simultaneously
- Menu: Source Menu –> Toggle Comment
1.2 To un-comment single line of code
- Move to the line which is already commented
- Press CTRL + / together
Menu option in Eclipe IDE :
- press CTRL + / simultaneously
- Menu: Source Menu –> Toggle Comment
- Note: if line of code isn’t already commented, then it will comment the code instead of un-commenting
1.3 To comment block of code (3 or more lines of code)
- Select block of code which we are intended to comment
- Press CTRL + SHIFT + / together
Menu option in Eclipe IDE :
- press CTRL + SHIFT + / simultaneously
- Menu: Source Menu –> Add Block Comment
1.4 To uncomment block of code (3 or more lines of code)
- Select block of code which is already commented
- Press CTRL + SHIFT + \ together
Menu option in Eclipe IDE :
- press CTRL + SHIFT + \ simultaneously
- Menu: Source Menu –> Remove Block Comment
- Note: if block of code is already commented, then it will uncomment; otherwise, there won’t be any effects pressing 3 keys together
2. 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:
Happy Coding !!
Happy Learning !!