Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Hello World" execution error

 
Mike Angelastro
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm just getting started with Java. I'm trying to run a "Hello" program. The code is:

class Hello {
public static void main(String[] args) {
System.out.println("Hello World!") ;
}
}

It compiles OK but when I run it with "java Hello", I get the following error-

Exception in thread "main" java.lang.UnsupportedClassVersionError: Hello <Unsupported major.minor version 49.0> at java.lang.ClassLoader.defineClass0<Native Method>
etc .....

Did I miss something in my java setup?

Thanks,

Mike
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,

Welcome to JavaRanch!

You've got multiple versions of Java installed, and the one you're using to compile the program is newer than the one you're using to run it; specifically, the compiler is JDK 1.5, and the runtime is JDK 1.4 or earlier.

Often when you install the Java plug-in for your Web browser, it will stick a copy of java.exe into your WINDOWS folder or someplace else early on your PATH. You have a number of options: uninstalling the plugin and installing a newer version is one; changing your PATH to put the JDK/bin directory first is another.
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're running on windows, you might want to use something like this "setjava.bat" script:


You could put it in your project directory, or in a global "utilities" directory.

You could use it as follows:

'Hope that helps .. PSM
[ December 04, 2005: Message edited by: Paul Santa Maria ]
 
Mike Angelastro
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Paul and Ernest!

With the help of both of you, I was able to figure it out. I had installed an Oracle demo on my machine and it had references to Java in the path. I moved them to the end of the path, after which my simple little app worked fine.

Thanks a bunch,

Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic