Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hi , Iam ananya new to java tech,

 
ananya sa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote simple java pgm with just one sysout., when i try to run it,,, iam getting problem like
javac: file not found: testpgm1.java
Usage: javac <options> <source files>
use -help for a list of possible options

I put java path in my environment variables like this:
C:\Program Files\Java\jdk1.6.0\bin;C:\Program Files\Java\jre1.6.0\bin.

can anybody please help out on this

thanks,

Ananaya.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64606
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"ananya java", please check your private messages for an important administrative matter.
 
Henry Wong
author
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java compiler is complaining that it can't find the file named -- testpgm1.java.

Henry
 
Muhammed Patel
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ananya ,

Firstly on your path does not need to have both the C:\Program Files\Java\jdk1.6.0\bin and C:\Program Files\Java\jre1.6.0\bin. the C:\Program Files\Java\jdk1.6.0\bin is fine.
Also you should set C:\Program Files\Java\jdk1.6.0 to a new environment variable called JAVA_HOME and then in your Path environment variable you can add the following to the text : %JAVA_HOME%\bin .

That will just sort out your java paths.

Now with the problem that you are having!

1. Have you changed directory to the right directory. So if testpgm1.java is in c:\javafiles have you changed directory to it.
2. Make sure that you have the correct file name or you could also make sure that the name of the file is the same as the class it contains.


Here is a simple class. try saving it as Blah.java putting it in your C:\ and then compiling and running it with the following commands



C:\>javac Blah.java

C:\>java Blah
BLAH

Hope this helps.

And good luck.
 
ananya sa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks,

It works now, i given the wrong path while compiling. that's the problem.





Muhammed Patel wrote:Hi ananya ,

Firstly on your path does not need to have both the C:\Program Files\Java\jdk1.6.0\bin and C:\Program Files\Java\jre1.6.0\bin. the C:\Program Files\Java\jdk1.6.0\bin is fine.
Also you should set C:\Program Files\Java\jdk1.6.0 to a new environment variable called JAVA_HOME and then in your Path environment variable you can add the following to the text : %JAVA_HOME%\bin .

That will just sort out your java paths.

Now with the problem that you are having!

1. Have you changed directory to the right directory. So if testpgm1.java is in c:\javafiles have you changed directory to it.
2. Make sure that you have the correct file name or you could also make sure that the name of the file is the same as the class it contains.


Here is a simple class. try saving it as Blah.java putting it in your C:\ and then compiling and running it with the following commands



C:\>javac Blah.java

C:\>java Blah
BLAH

Hope this helps.

And good luck.
 
ananya sa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi , it compiled properly, but trying to run, it is saying :
C:\Documents and Settings\sri\Desktop>java testpgm1
Exception in thread "main" java.lang.UnsupportedClassVersionError: testpgm1 (Uns
upported major.minor version 50.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

As you said i just kept C:\Program Files\Java\jre1.6.0\bin; in CLASS_PATH of environmntal variables .

What needs to do now?
 
Henry Wong
author
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What needs to do now?


This is caused when you compile your program with one version of Java, but then run it with an earlier version of Java.

Basically, Java is backward compatible. It is not forward compatible. So, you need to run your program with a version that is at least the same or later than your compiler.


I am guessing that you have an older version of Java already installed (but no compiler already installed). So, when you compiled, it uses the compiler you installed, but when you run it, it uses the older previously installed JVM.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic