How to Compile a Java program in Eclipse

Step 1:

When you start eclipse, it asks your for the address of the workspace. Workspace is a folder where eclipse will store all your project files.
enter the address of the workspace

Step 2:

To start a new project go to New->JAVA project.
Start a new project

Step 3:
Enter the details of your project i.e your project name.

Enter your project name

Step 4:

Create a new class. To do this right click on your project name which is “MyProject” in this case and select New->Class.

Creating a new class

Step 5:

Enter the name of your class. Click finish.

Enter name of the class

Step 6: Compiling

To compile, just press the RUN button or the DEBUG button to the left of the run button.

Compile

The following two tabs change content below.

12 thoughts on “How to Compile a Java program in Eclipse

  1. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.

  2. Hey Lynne, we’re glad you found our website helpful and yes we are constantly adding new information everyday. However, if you have any program request or any other request you can always ask us via comments.

  3. When I run it as a java application it gives an error message saying the application does not contain a main type, and as an applet it says the selection does not contain an applet??

    • Hi Reem, try giving us more info with the error and maybe also with what you’re trying to do.

      The method above is quite general and should work similarly for almost all IDEs.

      Make sure your program does not have syntax or case errors.
      eg. make sure your main() function is ‘main’ and not ‘Main’

  4. Hi,

    I’m fairly new to Java and had some difficulties running the application.

    1. The projects im using are from another Java tool called Bluej
    2. I wanted to run these project in eclipse instead so I imported them
    3. The problem is that whenever I want to run the application, the console always remains blank. I declared the main method (public static main void etc..) but still cannot get the console to display anything.
    4. Iv used Eclipse both galileo & heliosis
    5. Iv also installed the latest java (7)

    The project works in Blue J with no problem but I would like to practice them in Eclipse instead.

    Many Thanks :)

    Rick

    edit: I just tried doing a simple system.out.println in eclipse (class created in eclipse)..it give me the same result as the project class :(

  5. Rick, does eclipse encounter any errors while compiling your program?
    Secondly, try running the program in command prompt if it works there.
    Also try creating a new fresh project in Eclipse just to check if anything is wrong with your eclipse.

    Hope it helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">