Home » Desktop Java » IDE » Eclipse » Eclipse IDE Tips and Tricks

About Mohammad Meraj Zia

Mohammad Meraj Zia

I did my Engineering in Information Technology from IET, Lucknow, India. Currently doing MSc in Information Technology from Derby University. I have worked in Java/J2EE domain for the last 10 years. Have good understanding of Payment and Finance domains.

Eclipse IDE Tips and Tricks

1. Introduction

Eclipse is one of the most common Integrated Development Environment (IDE) used by Java developers. An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development.

Before the invention of IDE java develops used to write java code in their favorite text editors (e.g. Notepad), then they used to compile this and run it. Any compile time error was only presented once user compiles the code. With the help of modern days IDE we get to know these common mistakes beforehand.

Want to master Eclipse IDE?

Subscribe to our newsletter and download Eclipse IDE Handbook right now!

In order to help you master Eclipse, we have compiled a kick-ass guide with all the basic features of the popular IDE! Besides studying them online you may download the eBook in PDF format!

 

2. How To

In this section we will see how to do some of the common tasks which you need to do while doing your development in Eclipse.

2.1 How to change the file Encoding

Let say you are developing something which involves Internationalization (I18n). Internationalization (sometimes shortened to “I18N , meaning “I – eighteen letters -N”) is the process of planning and implementing products and services so that they can easily be adapted to specific local languages and cultures, a process called localization. To do this you will need to create properties files for all the languages you are supporting.

Some of the language characters will not appear correctly if you are using the default encoding of Eclipse. You will need to change the file encoding to let say ‘UTF-8’. To do that right click on the file and go to Properties => Resource. At the bottom you will find the option to change the text file encoding.

Figure 1. File Encoding

You can change this setting for every file in the workspace. For that go to Window => Preferences => General => Workspace and change the ‘Text file encoding’.

Figure 2. Default File Encoding

2.2 Suggest completions

In the Java editor press Ctrl + Space to see a list of suggested completions. Typing one or more characters before clicking Ctrl + Space will shorten the list.

Figure 3. Suggest Completion

Code completion supports camel case patterns. Entering NPE and clicking Ctrl + Space will propose NullPointerException and NoPermissionException.

2.3 Parameter Hint

When the cursor is in a method argument, press Ctrl + Shift + Space to see a list of parameter hints.

Figure 4. Parameter Suggestions

2.4 How to make a View/Editor active

Let’s say you want to see the list of issues in the project. For this you need to go to the Problems editor. To do that press <CTRL> + F7. Eclipse will display the list of open views and editor area. You can use the Up and Down arrow key to browse to the view/are which you want to go to, in this case Problems.

2.5 Organize Import

Let’s say you come up with a class with lots of unused import statements. Instead of removing them manually one by one you can press <CTRL> + <SHIFT> + O. This will not only remove all the unused import statements but will also sort them in the defined order.

2.5.1 How to change the import statements sort order

Go to Window => Preferences => Java => Code Style => Organize Imports. Here you can define the sorting order of the import statements. A package or type name prefix (e.g. ‘org.eclipse’) is a valid entry. An import is always added to the most specific group.

Figure 5. Organize Import

2.6 How to generate Getters / Setters

Let’s say you want to create a new POJO (Plain Old Java Object) class with lots of properties. Instead of writing getters setters for all the properties you can ask Eclipse to generate getters and setters for you. Right click on the class and go to Source => Generate Getters Setters… Eclipse willl open a pop-up window where you can choose the properties for which you want to generate getters / setters. You can choose to just generate the getters or just the setters. You have the option to provide the access modifier and to provide default method comments. The format of the getters/setters may be configured on the Code Templates preference page.

Figure 6. Generate Getters Setters

2.7 How to generate hashCode() and equals() method

Let’s say you want to override hashCode() and equals() method. Instead of writing it manually we can ask Eclipse to generate it. Right click on the class and go to Source => Generate hashCode() and equals()… 

Figure 7. Generate hashCode and equals

2.8 How to find references of used classes and methods

This is a very quick and useful way to find out where a class or method is used throughout the workspace/project. Select class/method > right click and go to  References => Workspace (Ctrl+Shift+G) || Project.

2.9 How to add Bookmarks

The Workbench allows the bookmarking of individual files or locations within a file. This section will demonstrate how to set several bookmarks and how to view them using the Bookmarks view. From the menu bar, select Window => Show View => Bookmarks. The Bookmarks view appears in the Workbench. Position the mouse on the left side of the editor where the line numbers appear. Right click and select Add Bookmark

Figure 8. Add Bookmark

When the Add Bookmark dialog opens type in a description for this bookmark. Notice that a new bookmark appears in the marker bar. The new bookmark also appears in the Bookmarks view. Now close all the open files and double click on the newly created bookmark in the Bookmarks editor. Eclipse will open the file which has that bookmark attached.

2.10 How to determine the shortcut for something

Let’s say you want to know the shortcut for some task which you perform in Eclipse. You can press <CTRL> + <SHIFT> + L. Eclipse will display all the shortcuts available.

3. Conclusion

In this article we saw various shortcuts which will help us in developing a project using Eclipse IDE. We also saw various nice features which can be used to make development easier. This is by no means an exhaustive list of feature/short cuts provided by Eclipse. There are number if other features available but this article only list the most commonly used ones.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz