Could not compile java after installing JRE and JDK

Asked By 200 points N/A Posted on -
qa-featured

I have installed the JRE and JDK both on my pc (windows xp sp3) but when I try to compile with javac, it is not recognised! Please help, I have an assignment to complete!!

SHARE
Best Answer by bug_fix
Answered By 0 points N/A #87042

Could not compile java after installing JRE and JDK

qa-featured

I guess you did not set the class path and it wasn't auto set for you. Set the class path and it should work.

Answered By 200 points N/A #87043

Could not compile java after installing JRE and JDK

qa-featured

What is class path and how do I set it? Sorry but I am new to java and programming as well.

Answered By 0 points N/A #87044

Could not compile java after installing JRE and JDK

qa-featured

Class path variable tells the path for JVM for looking the class file for execution. Class path specify that where Java Virtual machine should look for files to be executed. This is needed at time we do java <classname>


The CLASS PATH variable can be set on Windows XP with the following steps.
Click the Start button in the lower left of the screen.
Select Control Panel from the pop-up menu.
Choose System from the submenu.
Click the Advanced tab.
Click the Environment Variables button near the bottom and you will see two lists of variables. Look in the System variables list for a variable named CLASS PATH. If you find it, click Edit. If you don't find it, click New and enter CLASS PATH in the Variable name field.

The Variable value field is a list of file paths of directories or jar files. The first thing in this list should be the current directory, which is represented in windows just as it is in Unix, as a single period. If there's more than one thing in this list, separate items with a semicolon. For example, my CLASS PATH variable starts with these three items (there are a couple more, but this should be enough to give you the idea). The only part you need is the first "dot".

 

 

 

 

 

 

 

Answered By 200 points N/A #87045

Could not compile java after installing JRE and JDK

qa-featured

Thanks it was great help. My hello world compiled.

Best Answer
Best Answer
Answered By 0 points N/A #87046

Could not compile java after installing JRE and JDK

qa-featured

Did that work?

Answered By 0 points N/A #87047

Could not compile java after installing JRE and JDK

qa-featured

Happy to help. I did not expect the problem to be solved this easy and I still think there are things you need to be careful with. First you create the java source file with .java extensions. (I am assuming you are not using an IDE this soon and hope you will not till you become an expert.) Then you compile it using your cmd, How?
Click window button–>run–>cmd
Go to working directory(the directory containing .java file)
Type javac example.java

You will notice ClassName.class files in your directory. Now you will have to run that file, HOW?
Type in the cmd, java ClassName

Your program, if code is ok, will run.

Answered By 10 points N/A #87048

Could not compile java after installing JRE and JDK

qa-featured

The class name should be the same with your file name. For example :

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

Your class here is MainClass and for you to successfully compile it., you should save you work with a name MainClass.java . That's what I've done when I encountered that kind of problem.

Related Questions