First of all if you have already java then uninstall that java and download Java Sdk from Sun Microsystem :
For download: jdk (Java Development Kit)
Then choose your appropriate Operation System and download and Install the *.EXE program

This is one of the tough point for beginner to install java Beginner.

Some of the steps to maintain Path of Java compiler are given as follows:

STEP 1: Right click on My Computer and Go properties.

STEP 2: Dialogue Box Appears (given in fig 1.1) Go to Advance Tab > Environment Variables..

Fig 1.1

Fig 1.1 A Dialogue Box of Advance Tab

STEP 3: Now in New Dialogue box (given in fig.1.2 ) You can click on New Tab for creating new variable

Fig 1.2 Environment Variables Dialogue Box

Fig 1.2 Environment Variables Dialogue Box

STEP 4: New Small Dialogue Box appears and there you need to type the variable name as PATH and for Value you need to paste the \bin directory of Java development kit (jdk 1.x.xx). shown in fig 1.3.

fig 1.3 New User Variable

fig 1.3 New User Variable

STEP 5: Now click on Ok and run Command .

STEP 6: In command you need to type javac which output like in fig 1.4

1.4 javac in command

fig. 1.4 javac in command

STEP 7: If your output gives like fig.1.4 then you are able to compile your java source code by following ways


Also I need to tell dat the we can set CLASSPATH at ENVIRONMENT VARIABLES via DOS for compiling java file;

Here are some steps for windows:

> Go to Command Prompt

> type : set JAVA_HOME=directory(path)_of_your_jdk (as on fig 1.5)

fig 1.5

fig 1.5

>now type : set CLASSPATH=%JAVA_HOME%\bin.(as on fig 1.6)

fig 1.6

fig 1.6

>Also you need to set CLASSPATH of your JAVA LIB(library).

>Type : set CLASSPATH=%JAVA_HOME%\lib (for library of java)

Testing either the compiler path , library is correct or not.

>Type : echo %JAVA_HOME% (displays the path of Java installed)

>Type : echo %CLASSPATH% (displays the path of your java lib, java compiler as well)

If every thing goes alright then compile java file through following ways via Command at DOS:

For eg: To compile HelloWorld.java
Type : javac HelloWorld.java
Type : java HelloWorld

Outputs:
________________
HelloWorld!!!
________________

That almost Finished in Windows Java Compile !

If any problem occurs then comment me or just mail me!