I installed the J2SE 6.o version. Now I’m having a problem getting it to work right.
> C:\java\jdk1.6.0_25\bin
This is the path of the bin file, and I put this in the Path tab. In the environment settings.
What are the next steps that I have to take to run .java files from the command prompt?
Do I have to put something in the class-path tab too?
Let me elaborate my problem:
If I run and compile the below mentioned file called Shirt.java it works fine.
public class Shirt{
public int ShirtID=0;
public String description="-description required-";
public char colorCode='U';
public double price=0.0;
public int quantityInStock=0;
public void displayShirtInformation(){
System.out.println("ShirtId:"+ShirtID);
System.out.println("ShirtDescription"+description);
System.out.println("Color Code:"+colorCode);
System.out.println("Shirt Price"+price);
System.out.println("Quantity In Stock"+quantityInStock);
}
}
But if I run another file that calls the previous file, then problems crop up.
The file that calls the previous file is as follows.
public class ShirtTest {
public static void main (String args[]) {
Shirt myShirt = new Shirt();
myShirt.displayShirtInformation();
}
}
When I try to execute the second file, there are a few errors that crop up and no compilation takes place. I believe it has something to do with some problem with the environment variable Path declaration.
It is better to make sure that you do not have a CLASSPATH environment variable set. If it is not set, Java will by default look in the current directory for class files. As long as your Java source files are in the same directory (and not in a package) you should be able to compile and run them with simple commands:
If this complains with a
NoClassDefFoundError, then try specifying the classpath on the command line using the-cpoption:(note that
.means “the current directory”).See the Getting Started tutorial, which also has a section on common problems and their solutions.
When you get an error, please always copy & paste the exact error message, instead of just saying “I get some errors”. The more specific information you give, the easier it is to understand what the exact problem it is and the better we can help you.