On the windows platform, if you extracted the contents of the zip file to c:\, then you can start eclipse by using c:\eclipse\eclipse.exe
When eclipse starts up for the first time it prompts you for the location of the workspace folder. All your data will be stored in the workspace folder. You can accept the default or choose a new location.
If you select "Use this as the default and do not ask again", this dialog box will not come up again.
The major visible parts of an eclipse window are:
Editors (all appear in one editor area)
An eclipse perspective is the name given to an initial collection and arrangement of views and an editor area. The default perspective is called java. An eclipse window can have multiple perspectives open in it but only one perspective can be active at any point of time. A user can switch between open perspectives or open a new perspective. A perspective controls what appears in some menus and tool bars.
A perspective has only one editor area in which multiple editors can be open. The editor area is usually surrounded by multiple views. In general, editors are used to edit the project data and views are used to view the project metadata. For example the package explorer shows the java files in the project and the java editor is used to edit a java file.
The eclipse window can contain multiple editors and views but only one of them is active any given point of time. The title bar of the active editor or view looks different from all the others.
The UI elements on the menu bar and tool bar represent commands that can be triggered by an end user.
Using Multiple Windows
Multiple Eclipse Windows can be open at the same time. To open a new window, click on the Windows menu and select the New Window menu item.
Each window can have a different perspective open in them. For example you could open two Eclipse windows one in the Java perspective and the other in the Debug perspective. The window showing the Java perspective can be used for editing the java code and the window showing the debug perspective can be used for debugging the application being developed.
What is a Perspective?
An eclipse perspective is the name given to an initial collection and arrangement of views and an editor area. The default perspective is called java. An eclipse window can have multiple perspectives open in it but only one perspective is active at any point of time. A user can switch between open perspectives or open a new perspective. The active perspective controls what appears in some menus and tool bars.
Opening a Perspective
The Open Perspective dialog box shows all the available perspectives.
The same dialog can be brought up by clicking on the Open Perspective button ( ) on the tool bar
Switching Between Perspectives
The most commonly used perspectives for java development are the Java perspective and Debug perspective. Users can switch between open perspectives by clicking on the Perspective name on the toolbar
Closing a Perspective
To close a perspective, right click on the perspective name in toolbar and select the Close menu item.
Opening the New Java Project wizard
The New Java Project wizard can be used to create a new java project. There are many ways to open this wizard:
Using the New Java Project wizard
By clicking on the File menu and choosing New > Java Project
By right clicking anywhere in the Project Explorer and selecting New > Java Project
By clicking on the New button in the Tool bar and selecting Java Project
The New Java Project Wizard has two pages.
On the first page:
Enter the Project Name
Select the Java Runtime Environment (JRE) or leave it at the default
Select the Project Layout which determines whether there would be a separate folder for the sources code and class files. The recommended option is to create separate folders for sources and class files.
You can click on the Finish button to create the project or click on the Next button to change the java build settings.
On the second page you can change the Java Build Settings like setting the Project dependency (if there are multiple projects) and adding additional jar files to the build path.
Viewing the newly created project
The package explorer shows the newly created Java project. The icon that represents a Project is decorated with a "J" to show that it is a Java Project. The folder icon is decorated to show that it is a java source folder.
Opening the New Java Package wizard
You can use the New Java Package wizard to create a Java package. The Java Package wizard can be opened in different ways:
By clicking on the File menu and selecting New > Package
By right click in the package explorer and selecting New > Package
By clicking on the package icon which is in the tool bar( )
If you are creating a sub package, before opening the Java Package wizard select the parent packageso that name field can have a default value in it.
Using the New Java Package wizard
Once the Java Package wizard comes up:
Viewing the newly created package
Enter/confirm the source folder name
Enter the package name
Click on the Finish button
The package explorer will show the newly created package under the source folder
Setting the Java Build Path
The Java build path is used while compiling a Java project to discover dependent classes . It is made up of the following items:
Code in the source folders
Jars and classes folder associated with the project
Classes and libraries exported by projects referenced by this project
The java build path can be seen and modified by using the Java Build Path page of the Java Project properties dialog.
To bring up the Java Project properties dialog box, right click on a Java Project in the Package Explorer view and select the Properties menu item. On the left hand side tree select Java Build Path.
A common requirement seen while developing java applications is to add existing jars to the java build path. This can be accomplished using the Libraries tab. In the Libraries tab, just click on Add JARs if the jar is already in the Eclipse workspace or click on Add External JARs if the jar is elsewhere in the file system.
Running a Java Program
The quickest way to run a Java program is to using the Package Explorer view.
In the Package Explorer view:
Right click on the java class that contains the main method
Select Run As > Java Application
Why close a project?
An eclipse workspace can contain any number of projects. A project can be either in the open state or closed state.
How to close a project?
Take up build time especially when the Clean All Projects (Project > Clean all projects) with the Start a build immediately option is used
If a project is not under active development it can be closed.
To close a project, from the Project select the Close Project menu item.
Closed Project in Package Explorer
A closed project is visible in the Package Explorer view but its contents cannot be edited using the Eclipse user interface. Also, an open project cannot have dependency on a closed project.
The Package Explorer view uses a different icon to represent a closed project.
Debugging a Java Program
The quickest way to debug a Java program is to using the Package Explorer view.
In the Package Explorer view:
Right click on the java class that contains the main method
Select Debug As > Java Application
The same action can be performed using the Package Explorer by selecting the class that contains the main method and pressing Alt + Shift + D, J
Either actions mentioned above create a new Debug Configuration and use it to start the Java application.
If a Debug configuration has already been created you can use it to start the Java application by selecting Debug Configurations from the Run menu, clicking on the name of the debug configuration and then clicking on the Debug button.
The Debug menu item on the Run menu can be used to restart the java application that was previously started in the debug mode.
The shortcut key to launch the previously launched Java application in the debug mode is F11.
When a java program is started in the debug mode, users are prompted to switch to the debug perspective. The debug perspective offers additional views that can be used to troubleshoot an application.
The java editor allows users to place break points in the java code. To set a break point, in the editor area right click on the marker bar and select Toggle Breakpoint.
Breakpoints are shown on the marker bar. They are also visible in the Breakpoints View.
When the execution of code reaches a break point the JVM suspends the execution of the program. At this point, you can inspect the memory and execute the program in a controlled manner.
When the execution of a program is paused, the debug view can be used to inspect the call stack.
The variables view can be used to inspect the value of variables.
The run menu has menu items that allow you to Resume execution, step over a line of code, step into a function etc.
The picture given above shows the shortcut keys associated with actions such as Resume, Step Into and Step Over etc.
Refactoring using Eclipse
Renaming a class that is used widely throughout a project could take a lot of time but the Eclipse refactoring wizard makes the job easier by automatically detecting all dependencies on the class being renamed and modifying them also.
The refactor menu can be opened by:
Right clicking on a Java element in the Package Explorer view and selecting Refactor menu item
Right clicking on a Java element in the Java editor and selecting Refactor menu item
Selecting a Java element in either the Package Explorer view or Java Editor and pressing Shift + Alt + T
The refactor menu shows all the possible changes that are supported on the selected Java element. To rename a class select the Rename menu item.
Click on the Next button to see a preview of the changes (if available). Then click on Finish to get the wizard to do its work
You can navigate the Eclipse User Interface using only the keyboard by:
Using mnemonics associated with menus and menu items
Using mnemonics associated with controls in a dialog box or view or editor
Using accelerators associated with actions such as menu items and buttons on the toolbar
The Key Assist action which can be invoked by pressing Ctrl + Shift + L shows us all the accelerators or shortcut keys available in Eclipse.
The key combination assigned to an action can be changed using the Keys preference page. There are many commands or actions in Eclipse for which there are no shortcut keys. This preference page also allows you to assign shortcut keys by to these actions.
For example, to assign Alt + C as the shortcut key to trigger the command that brings up the New Class dialog box select New Class in the command list, navigate to the Bindings text box and then press Alt + C. The "when dropdown list" allows you to select a context in which the shortcut key is valid. Ensure that there are no conflicts for the selected key combination and click on the OK button
Now you can press Alt + C to bring up the New Class wizard.
Tips and Tricks
Tip #1 - Discovering Shortcut Keys
Press Ctrl + Shift + L to open a widget that shows all the shortcut keys.
Tip #2 - Content Assist
In the Java editor press Ctrl + Space to see a list of suggested completions. Typing one or more characters before pressing Ctrl + Space will shorten the list.
Tip #3 - Parameter Hint
When the cursor is in a method argument, press Ctrl + Shift + Space to see a list of parameter hints.
Tip #4 - Camel Case Support in Code Completion
Code completion supports camel case patterns. Entering NPE and pressing Ctrl + Space will propose NullPointerException and NoPermissionException
Tip #5 - Creating Getters and Setters
Click on Source > Generate Getter and Setter to open the wizard that allows you to generate getter and setter methods.
Tip #6 - Generating hashCode() and equals() methods
Click on Source > Generate hashCode() and equals() to generate this methods for a Java class
Tip #7 - Adding code around a block of code
Select a block of code and press Alt+Shift+Z to see a menu of items like if statement, for loop, try/catch etc that can enclose the selected block of code.
Tip #8 - Locating a matching bracket
Select an opening or closing bracket and press Ctrl+Shift+P to find its matching bracket.
Tip #9 - Smart Javadoc
Type '/**' and press Enter to automatically addes a Javadoc comment stub.
Tip #10 - Organizaing Imports
Press Ctrl+Shift+O to organize all the imports.
Tip #11 - Activating the Menu bar
Press F10 to activate the Menu bar
Tip #12 - Making a view/editor active
Press Ctrl+F7 to see a list of open views and editor area and switch to one of them.