Sunday, 15 July 2012

Requisites to run a Java Program

To compile and run a java program , we need the following


2.Install the jdk and Jre by running the set up.

2. An IDE(We use eclipse here. Please download Eclipse IDE for Java EE Developers from http://www.eclipse.org/downloads/)

Setting Environment Variables:

We  should set the environment variables in order to successfully execute our java program.

In Windows Operating system,

1.Right click Computer ->Properties ->Advanced Systems settings->Advanced ->Environmental Variables

2.Click on New. 

  •  Variable name should be PATH 
            Should point to the path of bin folder of the jdk folder installed. 

        Click on OK to save this.

  •  Add another environment variable by clicking on new . Variable name :CLASSPATH 
              
This should point to the lib folder of the JRE installed. Click on OK to save this.



  • Add another variable JAVA_HOME. This should point to the JRE Folder installed.
                  
                                       


      Click on OK to save this.


  •       Download the eclipse zip folder  and extract the same to a folder. Run the eclipse.exe file.
  •       Create a new folder and use the same as workspace.
  •       To create a new java project. Click on File -> New -> Java Project
  •       Enter the name of the project, click on OK to continue.
  •       Once the project has been created, right click on the same to create a new Java class. New-> class.(Eg. Hello)
Sample code to test the setup:

public class Hello {
public static void main(String[] args) {
System.out.println("hello");
}

}

Right click on the code as shown below and and Run the code by clicking on Run as ->Java Application



This will print hello in the console.

Thanks for your time...


No comments:

Post a Comment

Got to say something?...Leave your comments here