Learning Java : Second step - Using IDE : No more command-line


Introduction

In the previous post, we discussed generally about running the the HelloWorldApp.java program from DOS command-line based on Sun Java tutorial.

If you have not command-line applications very often, You might have got problems in configuring the path or typing the file name and commands without spelling mistake.

In this post I will explain using a specialized application that can help to write, compile, run and manage java files as project. This kind of Microsoft Word-like application is called IDE (Integrated Development Environment), since it provides more functions than as editors.

For java development, Eclipse is the most popular open source IDE and I will explain about installing and setting up a simple project in it.

The task is to run the HelloWorldApp.java from the Eclipse IDE. Although you won't using any command-line tools, you have to understand that whenever you click on 'compile' or 'run' icons in Eclipse it invokes javac and java commands. Once again the here is the basic principle to convert your code to an application.
  1. Java code  should be compiled using the 'javac' command (without any error) into .class file
  2. the compiled code should be used to run the application using the 'java' command

The HelloWorldApp.class file generated from the 'javac' command is the executable file or byte-code file and can be run in any computer that has java SDK or JRE (Runtime Environment).

Note: Again, Java SDK(Software Development Kit)  is required when you want to develop java application (javac command is only present in SDK) and JRE is required if you just want to run java application (java command only will be there in JRE)

In addition to its popularity, Eclipse is also free and backed up by popular companies like IBM. All the java developers in my software development team use Eclipse for writing desktop applications and web applications.

Just by clicking one or two buttons You can compile, run and get the results in a panel within Eclipse. As explained before, Eclipse acts much more that just an editor; helps in compiling, error checking, highlighting syntax, managing files (class), etc..

Finally things to do....

1. Download, install and run Eclipse IDE
  • Visit the following web site (can be obtained by giving a 'eclipse download' in google search). 
    • http://www.eclipse.org/downloads/ 
    • Download ''Eclipse IDE for Java Developer"  - Windows 32 bit binary file
    • Install the downloaded file in your computer
    • After installation, now click on the eclipse icon and open eclipse.
Note: As explained in the previous post, Java comes in many flavors. Java Standard Edition is the one which contains all the required modules for developing simple desktop applications. Java EE (Enterprise Edition) is used for Web application development. We need only Java Standard Edition for our tasks.

2.  Configuration of Eclipse
  • Once you understand the basic panel layout and simple menu options then writing code is very easy in Eclipse 
  • First, understanding basic terminology
    • Workspace - Handles multiple projects
    • Project - Collection of Java files created for one application
    • Class file - Java file that represent a Class 
Note: I know I have not discussed in detail about the Class yet. For the HelloWorldApp.java , HelloWorldApp is Class name.
http://java.sun.com/docs/books/tutorial/getStarted/application/examples/HelloWorldApp.java

For the HelloWorldApp , we have only one java file

Things-to-do

The objectives are

  1. Create a new project (call it as 'MyFirstProject') in the Eclipse Workspace
  2. Create a new Class called 'HelloWorldApp' and cut and paste the HelloWorldApp.java file content into it and save the file.
  3. Run the code as  'Java application'  (in the Menu, "Run"->"Run" or from the run icon in the top toolbar)
  4. You should see "Hello world" printed in the one of the bottom panel ("Console" panel)
Notes:
  1. Eclipse does not come with Java, hence Eclipse should know where you have installed the Java SDK (or JDK) . Browse over the preferences
  2. When a new project is created a simple wizard will show up and tell where the files will be stored (src and compiled class files can be stored in separate directories).
  3. Read the instructions and select default options appropriately.
Reference
Simple tutorial about using eclipse (It is the official documentation site and it not required to visit the site unless you are completely stuck).

Screenshot of MyFirstProject in Eclipse (Version 3.4