LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-01-2012, 03:53 PM   #1
PoleStar
Member
 
Registered: Jul 2010
Posts: 165

Rep: Reputation: 2
java compile/execute error


Hello,

I am having trouble with my first java program.


Code:
[me@horse javahello]$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (fedora-68.1.11.5.fc16-i386)
OpenJDK Server VM (build 20.0-b12, mixed mode)
[me@horse javahello]$


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

Compile and run:
Code:
[me@horse javahello]$ javac myfirstjavaprog.java 
[me@horse javahello]$ 
[me@horse javahello]$ 
[me@horse javahello]$ 
[me@horse javahello]$ 
[me@horse javahello]$ java myfirstjavaprog
Exception in thread "main" java.lang.UnsupportedClassVersionError: myfirstjavaprog : Unsupported major.minor version 51.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
	at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: myfirstjavaprog. Program will exit.
[me@horse javahello]$
 
Old 11-02-2012, 12:12 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Not sure. I just copied your source code and pasted it into my environment. It compiled and ran with no problems.

Code:
[sam@stealth java_compile]$ javac myfirstjavaprog.java
[sam@stealth java_compile]$ java myfirstjavaprog
Hello World!
[sam@stealth java_compile]$ java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)
Code:
class myfirstjavaprog
{
  public static void main(String args[])
  {
    System.out.println("Hello World!");
  }
}
That rules out the program itself. Do you have any special $JAVA_OPTS specified for the environment?
Code:
echo $JAVA_OPTS
#two different versions?
which java
which javac

Last edited by sag47; 11-02-2012 at 12:13 AM.
 
Old 11-02-2012, 09:48 AM   #3
PoleStar
Member
 
Registered: Jul 2010
Posts: 165

Original Poster
Rep: Reputation: 2
Searching on the net, it say some thing about using rule from one version and compiling or executing for an other version.

I think I carelessly tried to install jdk from sun(oracle) website, when I could not find command javac.

Code:
[me@horse ~]$ echo $JAVA_OPTS

[me@horse ~]$ env | grep -i java 


[me@horse ~]$ which java
/usr/bin/java

[me@horse ~]$ which javac
/usr/bin/javac

[me@horse ~]$ rpm -aq | egrep -i "jdk|jre|java" 
java-1.6.0-openjdk-1.6.0.0-68.1.11.5.fc16.i686
jdk-1.7.0_09-fcs.i586
tzdata-java-2012d-1.fc16.noarch
[me@horse ~]$

Thanks for your help.
 
Old 11-02-2012, 11:50 AM   #4
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Remove both of them and then install one of them.

Code:
$ java -version
$ javac -version
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Java Compile error exvor Programming 1 10-06-2011 09:03 PM
java ant compile error (can't find package) brgsousa Linux - Software 1 05-24-2010 09:46 AM
[Solved] HelloWorld.java compile error MrUmunhum Programming 2 02-28-2010 01:37 PM
How to compile and execute C++ and Java in Fedora 11 and Ubuntu 9.10? vskram21 Linux - General 8 11-19-2009 03:54 PM
Java compile error using Linux Enochs Linux - Software 4 08-04-2007 05:24 PM


All times are GMT -5. The time now is 12:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration