• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Hi , Iam ananya new to java tech,

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"ananya java", please check your private messages for an important administrative matter.
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java compiler is complaining that it can't find the file named -- testpgm1.java.

Henry
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic