This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to compile and Run" Watch "How to compile and Run" New topic
Author

How to compile and Run

Varuna Seneviratna
Ranch Hand

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

<program>
public class HelloWorld{

public static void main(String[]args){

System.out.println("Hello!");
}

}
</program>
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 java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown 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
Sheriff

Joined: Oct 13, 2005
Posts: 38025
    
  22
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: 3344

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]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to compile and Run
 
Similar Threads
Do I need to reinstall Java?
Problems with axis and tomcat4.0
Runtime Problem
unable to connect to sql server 2000 thru weblogic
java app launch on console