Other Topics
Shortcuts in Eclipse
- List of shortcuts in Eclipse → CTRL + SHIFT + L
- To format code → CTRL + SHIFT + F
- Adding
System.out.println()
while writing code → Type sysout
followed by CTRL + SPACE
Enabling Automatic File Refresh in Eclipse
When a new file is created in Eclipse you might need to refresh the Eclipse project to see the new file.
This refresh process can take place automatically. To set auto-refresh, go to window → preferences → general →
workspace and check the "Refresh using native hooks or polling" check-box.
Managing Files and Projects
Deleting a Class
Now that you know how to create a project and a Java class, you might also want to know how to delete them.
To remove a class file from a project, right click on it in the Package Explorer and select “Delete.” A dialog
box asking you to confirm will appear. Selecting “Yes” will delete the Java file.
Deleting a Project
To delete a project, right-click on the project in the Package Explorer. Again, select “Delete” from the context
menu. To delete your project select the option “Also delete contents under…” and select “Yes.”
Exporting Projects
Before exporting a project, make sure you close any other projects you don't want to export. This will make
things a little bit simpler. You can export a copy of your project as a zip file as follows:
- Right-click on the project and select "Export...".
- Expand the "General" option, select "Archive File", and select "Next".
- Select what you need to export (if the whole project just check the project folder).
- Select the "Browse..." button and locate the folder where you want to place the zip file.
- Enter a zip file name in "File name:" and select "Save".
- Select "Finish".
- Always verify the zip file created has the correct files. You can go to a different workspace and import
the zip file to verify its contents.
Importing Projects
- You do not need to create any project before importing a project. Just go to the "Java" Perspective,
right-click on the Package Explorer and select "Import...".
- Expand the "General" option and select "Existing Projects into Workspace". Do not select "Archive File"
(yes, we know, is confusing).
- Select "Next >".
- Click on the "Select archive file:" option and using "Browse..." select the zip file that has the project
you want to import.
- Select "Finish".
Renaming Java Classes and Files
To change the name of a project, class, file, variable or method: highlight the item, right-click, and select
Refractor → Rename. You will then be prompted to enter a new name.
Searching a Java File
If you are editing a Java file and you want to locate a specific phrase somewhere in your code, you can use
Eclipse’s search tool. Eclipse has a more advanced searching mechanism than most Windows applications. Select
Search → Search. This will bring up the Search window, which has a series of tabs. These searching utilities
make it easy to quickly locate anything in your project, so experiment with the search tool — it can save you a
lot of time later.
Editing Errors/Warnings Options
Here are some suggested settings for errors/warnings in Eclipse. You will find this section in Eclipse by accessing
Window → Preferences → Java → Compiler → Errors/Warnings.
- Non-static access to static member → ERROR
- Method with a constructor name → ERROR
- Assignment has no effect → ERROR
- Possible accidental boolean assignment → ERROR
- Empty statement → ERROR
- Comparing identical values → ERROR
Installing Software Using Eclipse Marketplace
You can install plugins by accessing the Eclipse Marketplace under
the Help menu. Once in Marketplace, type the name of a plugin (e.g., ArbitraryLines)
and select the "Go" button. You will see a list of possible plugins. Selecting
"Install" will complete the installation process.
Adding 80-Characters Mark
- Alternative #1:
- Make sure you are in the Java perspective.
- Select Window (in a PC) and Eclipse (in a Mac), followed by Preferences → General → Editors → Text Editors.
- Select the checkbox "Show print margin".
- Type the number 80 into the box next to "Print margin column:".
- Alternative #2: You can use the
ArbitraryLines
plugin. The easiest installation approach is to use Eclipse's Marketplace as described above. After installing
the plugin, you can add the 80-character mark by selecting Window (in a PC) and Eclipse (in a Mac), followed by
Preferences→General → Editors → Text Editors → ArbitraryLines. You will see the "Enable ArbitraryLines" option at the top.
 
Bug:
There seems to be a bug in Eclipse where the mark is not set at the 80-character column. If you experience
this problem, try changing the editor text font. To change the Eclipse editor text font:
- Select Window (in a PC) and Eclipse (in a Mac), followed by Preferences → General → Editors → Text Editors.
- Select 'Colors and Fonts' in "See 'Colors and Fonts' to configure the font.
- Expand the "Basic" option by clicking on >.
- Select the " Aa Text Font " option.
- Change the font size to "11" (you will be using the font "Consolas", "Regular", "11").
Code Coverage for Eclipse
EclEmma is a free Java code coverage tool for Eclipse. For additional information visit
EclEmma. Notice that recent Eclipse versions already have a
code coverage feature. To obtain code coverage information in Eclipse select: Run → Coverage As → Java Application.