File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How to compile and Run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to compile and Run" Watch "How to compile and Run" New topic

How to compile and Run

Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 169
I tried to compile and run this program

public class HelloWorld{

public static void main(String[]args){


This compiles, But when I try to run the program from the command prompt I get the following errors.
Exception in thread "main" java.lang.UnsupportedClassVersionError: HelloWorld (U
nsupported major.minor version 50.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at Source)
at Source)
at$100(Unknown Source)
at$ Source)
at Method)
at Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

What can be the reason

Varuna Seneviratna
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46424
Try entering "javac -version" and "java -version" and see what you get.

That sort of error usually means you are compiling the code with a newer version of the compiler than of the JVM. In which case you might get 1.5.0 for javac and 1.4.2 for java. The API details here are a bit laconic.

You can sort out the javac with a command to compile with compatibility to older versions of the JVM, but that will restrict you to using older functionality. Look here (Windows) or here (version 1.5 for Solaris) for details of the -source and -target options.

If it were me, I'd try going here and downloading a new JDK.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3381

Yes, you may please try out the options suggested by CR.

Varuna, could you please make use of the "Code" Tags when posting the java code so that it gives a good and clear look and makes the code uncluttered?

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
I agree. Here's the link:
subject: How to compile and Run
It's not a secret anymore!