Eclipse IDE gives warning "The import XXX is never used"
whenever it detect unused import in
Java source file and shows a yellow underline. Though unused import in Java
file does not create any harm, its unnecessary increase length and size of
Java source file and if you have too many unused imports in your Java source
file, those yellow underline and Eclipse warning affect readability and working.
In our last post on Eclipse, we have seen dome Java
debugging tips on Eclipse and in this post we will see Eclipse shortcut to
remove all unused imports in Eclipse. There are many option to tackle with this
problem e.g. you can collapse import section of code in Eclipse or you can
altogether remove all unused imports from Java file. Since Eclipse is favorite
IDE of many Java programmer, who love to do things fast in shortcuts, I will
also shared Eclipse shortcut to remove unused imports from Java program in this
article. This is one of many Eclipse shortcuts which we have discussed in our
post Top
30 Eclipse keyboard shortcut for Java programmer. Let's see How to remove all unused imports from Java
file in Eclipse IDE.
How to remove all unused imports from Java file in Eclipse
Here are couple of ways to remove all unused imports from Java in Eclipse IDE :
Do you want a bonus Eclipse tips ? If yes then here you go, you can save all keystrokes required to remove all unused imports from Java source file by using Eclipse save actions, which are actions Eclipse automatically perform when you save Java file. Just check option of Organized imports in save action under Window-->Preferences->Java-->Editor-->Save Actions. This saves heap lot of time while working in Eclipse and one of the reason I love Eclipse IDE for Java programming. You can also configure formatting and few other action which will be taken by Eclipse automatically whenever you save you file.
One more advantage of using Organize import or shortcut ctrl + shift +O is that it imports all packages which is required by code, So it not only save time while removing import statement but also help to import required packages in Java. It means if you copy paste some code and see lots of red line as error due to non imported packages, just use this Eclipse shortcut or save your source file if you have configured Eclipse save action to organize import.
That's all on Eclipse shortcut of removing all unused import statement from Java source file in Eclipse IDE. Its always good to learn more about IDE on which you are working e.g. Netbeans or Eclipse to improve productivity.
How to remote debug Java application in Eclipse
Top 10 Java debugging tips in Eclipse IDE
How to use Eclipse to override equals and hashcode method in Java
Netbeans shortcut to view Java doc
Top 20 design pattern and software design interview questions for Java programmer
10 OOPS and SOLID design principles Java programmer should know
No comments:
Post a Comment