Saturday 12 September 2015

Setting up and running Java on windows.

Java, First steps!


I know there are plenty or pages to set up java in windows but let us do a step by step set up and run a sample java program in windows environment.

Let us break down the whole process into the following steps.

1. Downloading Java and installation.
2. Setting Java in windows environment variable.
3. Writing your first java program.
4. Compiling and running the program.

Downloading Java and installation.

You can download Java from Oracle website. You may click here to download and install.
Download Java.
You can download Java 8 which is the latest edition of Java at the time of writing. But the steps are for Java 7 in this tutorial.
You might be wondering should I get a 32 bit or a 64 bit version. You can go through this article to choose the Java needed for you. 32 bit or 64 bit Java?

Setting Java in windows environment variable.

 Click on windows start menu and start typing "environment variables" in search and then click on "Edit the system environment variables" and click on "Environment variables" button.

 

Under system variables click on Add new to add a new variable. JAVA_HOME as variable name and installation path as variable value click OK and then search for the "path" variable and click on "edit" and add %JAVA_HOME%\bin and click OK.



To see if Java is configured properly open command line and check the java and javac version using the following and it should show the versions.

java -version

C:\>java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mo
de)

javac -version

C:\>javac -version
javac 1.7.0_25


Writing your first java program.

Do the following to write your first program. You can use IDE like Eclipse,intellij or just notepad or any other favorite text editor.
 
package com.karthik.learnjava;

/**
 * <p>
 * Simple program to learn java
 * </p>
 * 
 * @author Karthik
 * @version 1.0
 */
public class FirstProgram {

 /**
  * <p>
  * Main method
  * </p>
  * 
  * @param args
  */
 public static void main(String[] args) {
  System.out.println("Hello, this is my first java program!");
 }
}


Compiling and running the program.

I have the program written in this package
com.karthik.learnjava under src folder. 

The following needs to be done to compile and run the program.

C:\Karthik\KarthikArunWebSite\JavaProject\src>javac com\karthik\learnjava\FirstProgram.java
C:\Karthik\KarthikArunWebSite\JavaProject\src>java com.karthik.learnjava.FirstProgram
Hello, this is my first java program!


Please post your comments or suggestions if any in the comments section.
 
http://karthikarun.in

No comments:

Post a Comment