Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to compile and Run

 
Varuna Seneviratna
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Pie
Posts: 48943
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic