Recent Tutorials and Articles
    Java program using Eclipse IDE
    Published on: 25th May 2018

    This article will demonstrate how to write java programs in Eclipse IDE along with listing some of the benefits that you get by this.

    As you may know that it's quite gruelling to write the java code in plain text editors as while writing, you never know whether you are using correct syntex, class names and import statements and you need to compile it manually after each change.

    Wouldn't it be nice to have your code compiled automatically and get help for writing the code i.e. importing the packages automatically, formatting the code and much more? This is where Eclipse IDE comes into picture.

    What is Eclipse?

    Eclipse is an open-source multi-language Integrated Development Environment (IDE). It can be used to develop applications in Java and, by means of various plug-ins, other programming languages including Ada, C, C++, COBOL, Fortran, Haskell, JavaScript, Perl, PHP, Python, R, Ruby (including Ruby on Rails framework), Scala, Clojure, Groovy, Scheme, and Erlang.

    If you haven't got Eclipse installed, you can find installation instructions here.

    Launching Eclipse
    • Start Eclipse by running eclipse.exe in the Eclipse installed directory.
    • Choose an appropriate directory for your workspace (i.e., where you would like to save your files).
    • If the Welcome screen shows up, close it by clicking the close button.
    Create a Java project

    For each Java application, you should create a project to keep all the source files, classes and relevant resources. However if you are just writing toy programs, you can work in same project. Following the steps to create a new Java project -

    • Choose File menu => New => Java project. If for some reason, you don't see Java Project option. Click on Other... and type in Java Project and you shall see Java Project option.
    • The New Java Project dialog pops up.
      • In the Project name field, enter SampleProject.
      • Click Finish.
    Write HelloWorld Java program
    • In the Package Explorer (left panel) => Right-click on SampleProject (or use the File menu) => New => Class.
    • The New Java Class dialog pops up.
      • In Name field, enter HelloWorld.
      • Check public static void main(String[] args) box.
      • Click Finish.
    • The source file opens on the editor panel. Enter the following code:
      public class HelloWorld {   
         public static void main(String[] args) {
            System.out.println("Hello, world!");
    Run the program
    • Since Eclipse compiles the Java statement as and when it is entered, there is no need to compile the code explicitly. Compiled (.class) files can be found in the bin folder.
    • To run the program, right-click anywhere on the source file (or from the Run menu) => Choose Run As => Java Application.
    • The output Hello, world! appears in the Console panel.
      Hello, world!

    Thank you for reading through the tutorial. In case of any feedback/questions/concerns, you can communicate same to us through your comments and we shall get back to you as soon as possible.

    Published on: 25th May 2018

    Comment Form is loading comments...