Just a basic into to Eclipse, aimed at people who are new to Java. Covers creating a new project, debugging, common shortcuts/navigation, git.
Workspace contains your settings, ex your keyboard shortcut preferences, list of your open projects. You can have multiple workspaces.
You can switch between Workspaces via File ->Switch Workspaces
A project is essentially an application, or a library to an application. Projects can be opened or closed. Content of closed projects don’t appear in searches.
Hello world Project
To run some basic java code:
- File -> New -> Java project
- Give the project some name -> finish.
- Right click on src -> New -> Class
- Give your Class some name, check “Public static void main(String  args)”
- Add “Hello World” print line:
- Right click on “SomeName.java” -> run as -> Java Application
- Output printed in Console:
- Next time you can run the file via run button:
- Or via “Ctrl+F11”
Set a breakpoint by double clicking on the line numbers in the margin, then click on the bug icon or right click and “Debug as” -> “Java appliaction”
For more info on debugging, head over to Vogella:
Eclipse has the notion of Perspectives. One is for Java development, one for debugging, (others could be C++ development, or task planning etc..). It’s basically a customisation of features and layout.
When you finish debugging, you can switch back to the java perspective:
Common keyboard shortcuts
- Ctrl+/ – comment code “//”
- Ctrl+shift+/ – comment code ‘/* … */’
- Ctrl+F11 – Run last run configuration
- Ctrl+Shift+L Keyboard reminder cue sheet. (Type to search)
- Ctrl+Shift+L, then Ctrl+Shift+L again, open keyboard preferences.
- Ctrl+O – Java quick method Outline:
Note: Regex and case search works. Ex “*Key” will find “getBackgroundColorKey()”, so will “gBFCK”.
- Ctrl+Shift+r – search for resource (navigate between your classes).
- Ctrl+Shift+f – automatically format the selected code. (Or all code if no block selected).
For more on shortcuts, head over to Vogella:
Source code navigation
Right click on a method/variable to bring up a context menu, from there select:
Open Declaration (F3)
This is one of the most used functions. It’s a universal “jump to where the method/variable/class/constant is defined”.
Open Call hierarchy
See where variable or method is called.
Tip: For variables, you can narrow down the Field Access so that it only shows where a field is read/written.
Quick outline (Ctrl+O)
The quick outline is a quick way to find a function in your class. It has regex support and case search. E.g “*size” will find any method with ‘size’ in it and “cSI” will find ‘computeSizeInPixels’.
Tip: Press Ctrl+O again and you will be shown methods that get inherited from parent classes.
Navigate to super/implementation (Ctrl+click)
Sometimes you may want to see which sub-classes overrides a method. You can hover over a method and press ctrl+click, then on “Open Implementation”.
You will be presented with a list of sub-implementations.
You can similarly navigate to parent classes.
Predict variable names, method names,
Start typing something, press: “Ctrl+space”
It can complete by case also, ex if you type “mOF” and press Ctrl+Space, it will expand to “myOtherFunction()”.
Typing “System.out.println();” is tedious. Instead you can type “syso” and then press ‘ctrl+space’. Eclipse can fill in the template code.
You can find more on templates in Eclipse Preferences.
99% of my git workflow happens inside Eclipse.
You will want to open three useful views:
Window -> Show view -> others
- Team -> History
- git -> Git Repositories
- git -> Git Staging
You can manage git repositories in the “Git Repositories” view:
You can add changed files in the “Git Staging View” via drag and drop, and fill in the commit message. You can view your changes by double clicking on the files:
In the “History” view, you can create new branches, cherry pick commits, checkout older versions. Compare current files to previous versions etc..
More on Eclipse
If you want to know more about the Eclipse interface, feel free to head over to Vogella’s in-depth Eclipse tutorial:
Also free free to leave comments with questions.