Problem running Simple Hello world program in Ubuntu
Problem running Simple Hello world program in Ubuntu...
I have installed JDK7... copied it to /usr/lib/jvm/ directory and changed the Java Alternative
And use javac command to compile the program and it created a hello.class file
it compiled without any error
below is the code
Code:
class hello{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
But when i try to run the prgram using this command
But i get this following errors
Code:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Hello : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Hello. Program will exit.
At last line it says Could not find the main class: Hello. Program will exit.
Please help me ,i'm new to Java
Re: Problem running Simple Hello world program in Ubuntu
Quote:
UnsupportedClassVersionError: Hello : Unsupported major.minor version 51.0
It look likes your Java Runtime version(6) is different to your JDK version(7).
What says "java -version" in your terminal? (6?)
You have to change it....
Re: Problem running Simple Hello world program in Ubuntu
Quote:
Originally Posted by
eRaaaa
It look likes your Java Runtime version(6) is different to your JDK version(7).
What says "java -version" in your terminal? (6?)
You have to change it....
After executing that command ,i got following text
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)
Im using JDK 7
Re: Problem running Simple Hello world program in Ubuntu
Yes, that was what I suspected ->
How do you changed the java alternative?
sudo update-alternatives --config java ?
Do you have selected the java 7 jre?
How To Install Oracle Java 7 (JDK) In Ubuntu ~ Web Upd8: Ubuntu / Linux blog
+ many other sites will give you an installation guide!
Re: Problem running Simple Hello world program in Ubuntu
Quote:
Originally Posted by
eRaaaa
Thanks a lot .....thank you very much....
i had to change the java alternative,it was set to /usr/lib/jvm/java-6-sun/jre/bin/java
changed it to /usr/lib/jvm/jdk1.7.0/bin/java
so now it works ...thank you :)