Downloading and Installing Eclipse

Document Sample
Downloading and Installing Eclipse Powered By Docstoc
					                                  Downloading and Installing Eclipse

To use the Eclipse IDE for Java, you need to first download and install an appropriate Java Software
Development Kit (JDK). Then you can download and install Eclipse.

Install Java SDK

      Windows
        Goto

          Find Java SE Development Kit (JDK) 6 Update 10 or more recent and click Download.
           Select your platform (Windows or Windows x64) from the combo box, check that you agree
           to their license, and click Continue. Click the link to download the offline installation file.
           Save the file to your desktop and run it when it finished downloading.

      Mac/Linux

          The Java JDK should be preinstalled on your system.
          If it isn't
           ■ Mac: Install the XCode tools from your OS X disk
           ■ Linux: Use your Linux package manager (apt-get, yum, synaptic, etc) to download and
                install the JDK.

Download and install Eclipse IDE

      Windows or Mac

          Goto

          Find Eclipse Classic from the list.
          Click the download for your operating system at the right.
          Select a download site and download the file.

          Unzip the downloaded file. The new folder contains eclipse.exe (Win) or eclipse (Mac).
           ■ You can move the entire folder to the "Program Files" (Win) or "Applications" (Mac)
              directory or any other location that is convenient and create the appropriate shortcuts by
           ■ or leave the folder where it is.
           ■ Either way, run eclipse.exe or eclipse (Mac) to start Eclipse.

      Linux

          Use your system's package manager (apt-get, yum, synaptic, etc) to install Eclipse.
                               Using the Eclipse IDE and Debugger for Java

Starting the Exclipe IDE

      Double click the Eclipse executable
      "Workspace Launcher" appears the first time Eclipse is run.
        It sets the directory where Eclipse will create new projects. You can leave this as
           ~/workspace or browse to a directory you will remember more easily (e.g. ~/CECS_274/).
        You may also want to check "Use this as the default and do not ask again" to avoid
           repeating this step each time you launch Eclipse.
        You can undo this later in the menu Window > Preferences > Startup and Shutdown by
           checking "Prompt for workspace on startup".
      If you have used Eclipse before, it will open the last project you were working on in the
        If that is the case this time, right click on the project name in the left pane and select Close
           Project to follow along with this tutorial.

Creating a new project
    Select File > New
    Select Java Project and click Next.
    Name the project “Hello World” and click Finish.
        Eclipse will recommend the “Java perspective”.
           ■ Check “remember my decision” and click Yes.
           ■ Perspectives are Eclipse's way of showing the tools appropriate to your current task.
        If the Welcome Screen doesn't go away, just click the X on its tab.

      To create a new .java file,
        right click on the project name in the left pane and select New > Class.
        Fill in the Name field with “HelloWorldClass” and click Finish.
          ■ An editor will open in the right pane.
          ■ Edit the file in the editor so it looks like this:

               public class HelloWorldClass {
                        public static void main(String args[]){
                                 System.out.println("Hello, World!");
      To import existing .java files
        expand the project tree (left pane -- Package) by clicking on the triangle symbol next to the
           project name in order to reveal the src folder.
        Open a file browser window in your OS (explorer.exe, Finder, Nautilus, etc) and find the
           .java files you want to import.
        Drag them onto the src folder in Eclipse.
           ■ This will make COPIES in the src folder in the workspace for this project
           ■ ANY CHANGES made to these won't be reflected by the files at their original location.

Running your project
      Select Run > Run from the menu.
        If a dialog prompts you to save, check always save, then click continue.
        Below the editor pane, a Console tab will appear/take focus and display the output of your
           program. This is where input and output from your program will occur.
        If a message appeared saying you have errors, click cancel, correct the errors listed, and run

Debugging your project
    Edit HelloWorldClass to look like this, then run it:
        public class HelloWorldClass {
                 public static void main(String args[]){
                          foo("Hello, World!");
                 public static void foo(String s){
                          for(int i=0;i<=13;i++){
      Why did it crash?
      Right click in the left margin of the editor pane on the line foo(“Hello, World”); and select
       Toggle Breakpoint.
      Now select Run > Debug.
        This may prompt you to switch to the debugging perspective.
          ■ Check to remember your choice and continue.

          Your code will be shown in the lower left pane with the current line highlighted -- this will
           be the line you set the breakpoint on.
          The upper right pane Variables shows the current value of all the variables that are visible to
           the current line of the program.

      Press F5 to “step into” the function foo.
      Press F6 repeatedly to “step over” the print statement.
        You can see the output in the Console pane below
        When execution jumps to the scary Exception code, you have found the problem
        The debug view (upper left) should have the lines
          ■ String.charAt(int) line: 687
          ■ line: 7
          ■ HelloWorldClass.main(String[]) line: 3
        Click on in the debug view
          ■ This will show you the status of foo when the error occurred.
          ■ In the variables view (upper right) you can see i = 13
          ■ Once you've thought about it, you'll realize that “Hello, World!” is exactly 13 characters
               long, but since Strings are indexed starting from 0, i = 13 would be the 14th character.
          ■ Thus the problem is that the for loop goes one iteration too far resulting in the index
               being out of bounds.
                Click on String.charAt(int) line: 687 in the debug view
                Note that you could have guessed the problem based on the name of the exception
                   being thrown: StringIndexOutOfBoundsException
      To exit debugging, click the red square to terminate debugging, then select Window > Open
       Perspective > Java
   Change i<=13 to i<13 in the for loop and rerun the program to see that the problem is solved.
lem is solved.