How to program in Java ?

Step by step instructions of how to program in java

  • Download and install the latest Java SE Development Kit (JDK) based on your system requirements from here.
  • Once you installed Java Developed Kit on your machine, you will need to set environment variables path to point to correct installation directories. Steps for setting up path for Windows, assuming that installed path of java on your computer is "c:\Program Files\java\jdk directory"
    • Right-click on 'My Computer' and select 'Properties'.
    • Go to Advanced tab and click on Environmental variables.
    • In the list of user variables create a variable "PATH" or update "PATH" variable if exists with the value "c:\Program Files\java\jdk\bin".
    • if any value already exists with the PATH variable just add the new value to the existing value by differentiating it with ";" eg. C:\WINDOWS\SYSTEM32; c:\Program Files\java\jdk\bin;

    • To check whether the PATH variable is set, type command "java -version" in command prompt, details of installed java will be displayed.
    Setting up path for Linux, UNIX, Solaris, FreeBSD
    • Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation, if you have trouble doing this.
    • For eg. if you use bash as your shell, then you would add the following line to the end of your '.bashrc: export PATH = /path/to/java:$PATH'.

Now you can create a java program and save it as

To compile a java program,go to command prompt , point to the folder where the java program file (.java) exists eg. cd Folder_Name and compile it using the command

A class file(.class) with the same name will be generated in the program folder if no error occurs.

To run the java program type

java Filename
in command prompt after class file is generated successfully.

To write your Java programs, you can use a text editor. Below are popular text editors, you can consider any one ,

  • Notepad
  • NetBeans Download here.
  • Eclipse Download here.

What is JDK, JRE and JVM ?