Eclipse Perspectives and the Java Perspective

What is a perspective?

In Eclipse a perspective is a way to organize and view the files associated with your program.  There are different perspective available in Eclipse.  The one you want to use to write your programs is the "Java" perspective, which is Eclipse's default perspective.  Don't confuse the "Java" perspective with the "Java Browsing" perspective or the "Java Type Hierarchy" perspective, as each one represents a different perspective.  If you want to change to a particular perspective select WindowOpen Perspective and select the appropriate perspective.

Resetting a Perspective

You may notice that certain components of the various perspectives, for example the Console window, or the Package Explorer, can be closed via the X widget in their upper right corners. What happens if you accidently close the console, for example? How will you see what's going on? If that happens, you'll want to reset your perspective and get back any windows you may have accidentally closed. To do this, all you need to do is select Window Reset Perspective and click "OK" when prompted for confirmation. Your perspective will be restored to its original state with all of its windows intact.

Creating a Project

Now that you've got Eclipse up and running, it's time to create your first Java project. To do this, you'll want to go File New Project. After doing so, you'll see a window like this:

Make sure you select the Java Project folder.   After clicking "Next", and providing a project name you'll see a window like this one:

The project name is any name you choose and the only value you need to provide.  Your project will be created in the workspace associated with Eclipse. After pressing "Finish" you will see a window like this one:

Adding a New File to a Project

Now that you've created your project, you now want to create a new Java file and add it into your project. Your Java file (files with a .java extension) is a plaintext file in which you will write your code. Once you've created your project, you will see it listed in the "Package explorer" pane in the left of the screen. To create a new Java file, right click on your project and select New Class. You'll see the following window:

In the "Name: " section provide the name (e.g., HelloWorld) for the file you want to create. In addition, in the section "Which method stubs would you like to create?" select "public static void main(String[] args)".  Once you have completed your selection click on "Finish." This is the window you will see:


Double-Click on the tab where "" (or part of) appears.  You will see that a class HelloWorld with a main method has been created for you.  To return to the previous window just double-click on the tab again or select the menu option Window Reset Perspective.

Saving, compiling, and running Java code

Ready to write some code? Paste this line into your public static void main(String[] args) method, in between the { and the }:

The whole method should look like this:

In order to actually run this code, the code needs to be compiled, i.e., translated into a language the computer can understand. There are different approaches we can follow one of them is by saving the file.  In Eclipse saving a file compiles the file for us.  To save a file select FileSave. 

Now that your code has been compiled, you can run your program by selecting Run Run As Java Application. You will be able to see the output of your program by selecting the Console tab which you will find underneath the code pane.   

Quitting Eclipse

You can exit eclipse by using any of the following alternatives: