We help IT Professionals succeed at work.

I cannot compile my java file

Billy Ma
Billy Ma asked
on
213 Views
Last Modified: 2013-11-23
I have installed the new java program jdk1.6.0_07, however, I cannot run my java file, but it can compile, I typed the full path there just in case any problems. Anyone can tell me why I cannot run my java file?
My java file test.java only contains

it should run fine, but the fact is not.....
public class Test{
 
	public static void main(String [] args){
		System.out.println("test");
		
	}
	
}

Open in new window

problems.JPG
Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
java -classpath . Test

Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Billy MaVice President

Author

Commented:
How can I completely remove my java program in my pc? including all files, registry....
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
delete Test.java and Test.class

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
to remove the jdk, just uninstall it using control panel
but the jdk is not the cause of your problem, its simply a classpath issue

Billy MaVice President

Author

Commented:
if I delete my CLASSPATH variable, then my C:\My Software\mysql-connector-java-5.1.6\mysql-connector-java-5.1.6-bin.jar will not works
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
you don't have to clear the classpath, its just if its not present then the current directory is searched by default.

other option with your jar is to put it in the jre/jdk ext folder

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Billy MaVice President

Author

Commented:
Thank you so much!
Billy MaVice President

Author

Commented:
thanks a lot!
I guess the problem is with your naming convention. You have given

public class Test{  & named your .java file as test.java.  

If there is a public class in a file, the name of the file must match the name
of the public class. For example, a class declared as public class Dog { }
must be in a source code file named Dog.java.




Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.