• Post Reply Bookmark Topic Watch Topic
  • New Topic

error in my first java program  RSS feed

 
akshay naidu
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone,
i am new in in this forum and new to java.

this is my first java program,i am using eclipse IDE-----

package day1.example;

public class MyFirstJava {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("hi");
}

}


when i saved it,it shows no error.when i run it then a pop-up says "could not find the main class.the program will exit"
and in the console it says---

java.lang.UnsupportedClassVersionError: day1/example/MyFirstJava : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(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$000(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)
Exception in thread "main"

please help me with my first java program
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason is that you probably have compiled your Java program with a higher JDK version and trying to run it with a lower JDK version!
 
akshay naidu
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what should i do then
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
Please don't ask the same question twice. I shall try merging this discussion with your other question, which is also in a more appropriate location.
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
akshay naidu
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone,
i am new in in this forum and new to java.

this is my first java program,i am using eclipse IDE-----

package day1.example;

public class MyFirstJava {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("hi");
}

}


when i saved it,it shows no error.when i run it then a pop-up says "could not find the main class.the program will exit"
and in the console it says---

java.lang.UnsupportedClassVersionError: day1/example/MyFirstJava : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(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$000(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)
Exception in thread "main"

please help me with my first java program
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That error means you are using a newer version of javac than of java. Start by showing us the results of the following three instructions at the command line/terminal:-
  • 1: java -version
  • 2: javac -version
  • 3: (Windows) echo %PATH%
  • 3: (Not Windows) echo $PATH
  •  
    Campbell Ritchie
    Marshal
    Posts: 56541
    172
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Also stop using Eclipse at this stage; there may be options and configurations set in Eclipse which are causing problems.
     
    akshay naidu
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    1.

    C:\Users\akashy>java -version
    java version "1.7.0-ea"
    Java(TM) SE Runtime Environment (build 1.7.0-ea-b20)
    Java HotSpot(TM) Client VM (build 11.0-b06, mixed mode, sharing)

    2.

    java -version is
    javac 1.7.0-ea
     
    akshay naidu
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    3.

    C:\Users\akashy>echo %PATH%
    C:\Program Files (x86)\Java\jdk1.7.0\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPow
    erShell\v1.0\;C:\Program Files\ibm\gsk8\lib64;C:\Program Files (x86)\ibm\gsk8\lib

     
    Campbell Ritchie
    Marshal
    Posts: 56541
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Don't know. Your version 51 should match Java7 which you appear to be using already. You can find the major versions here: look at the squares with 6 and 7 to their left.

    Did somebody else compile that class for you? Have you ever had such problems before? Your installation is out of date (I think ea means early access, so it is getting on for four years old). If you have a decent internet connection I suggest you uninstall that Java® and install the latest version at present 7u75/75. And update your PATH to read
    "C:\Program Files (x86)\Java\jdk1.7.0_75\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\ibm\gsk8\lib64;C:\Program Files (x86)\ibm\gsk8\lib"

    At least I think it would be _75; you can check that when you install it because it will ask for the location to install to which will be Program Files...jdk1.7.0_75 or similar.

    Edit: add age of ea Java7: text underlined.
     
    akshay naidu
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks campbell,
    i'll see to it
     
    Campbell Ritchie
    Marshal
    Posts: 56541
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You're welcome Did you have any success with it?
     
    akshay naidu
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    yes
    it worked fine in command prompt

    the problem was in path,i tried moose greetings program after correcting path and its working.

    but there's a problem in next program,
    please can you tell whats wrong with this one

    public class MyFirstClass{
    public static void main(String[] args){
    System.out.println(“hello World”);
    int x = 10;
    int y = 20;
    int c = x + y;
    System.out.println(c );
    }
    }

    cause when m running it,it says

    C:\Users\akashy\java\src>javac MyFirstClass.java
    MyFirstClass.java:3: illegal character: \8220
    System.out.println(ôhello Worldö);
    ^
    MyFirstClass.java:3: ';' expected
    System.out.println(ôhello Worldö);
    ^
    MyFirstClass.java:3: illegal character: \8221
    System.out.println(ôhello Worldö);
    ^
    MyFirstClass.java:3: not a statement
    System.out.println(ôhello Worldö);
    ^
    4 errors

    now whats wrong with this one
     
    akshay naidu
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    i am learning java with certification point of view,please tell me according to you
    which exam should i go for, 803 or 808?
     
    Thanigai arasu Ruthirakotti
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    but there's a problem in next program,
    please can you tell whats wrong with this one

    public class MyFirstClass{
    public static void main(String[] args){
    System.out.println(“hello World”);
    int x = 10;
    int y = 20;
    int c = x + y;
    System.out.println(c );
    }
    }

    cause when m running it,it says

    C:\Users\akashy\java\src>javac MyFirstClass.java
    MyFirstClass.java:3: illegal character: \8220
    System.out.println(ôhello Worldö);
    ^
    MyFirstClass.java:3: ';' expected
    System.out.println(ôhello Worldö);
    ^
    MyFirstClass.java:3: illegal character: \8221
    System.out.println(ôhello Worldö);
    ^
    MyFirstClass.java:3: not a statement
    System.out.println(ôhello Worldö);
    ^
    4 errors

    now whats wrong with this one


    <Thanigai arasu>
    I hope you might copy pasted this code, the quotes "" you have used in this program will have the different ascii value. so the java compiler treat this as a ill-legal character. As a beginner, avoid copy paste.

    </Thanigai arasu>
     
    akshay naidu
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    yeipee
    thanks Thanigai arasu Ruthirakotti
    i typed the program and now it runs fine.
     
    Campbell Ritchie
    Marshal
    Posts: 56541
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    And welcome to the Ranch Thanigai arasu Ruthirakotti
     
    akshay naidu
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hello campbell
    can you please tell me which is better to learn n understand java (easily )
    oracle's java se tutorial or head first java 2nd edition(k&b)
    thank you
     
    Campbell Ritchie
    Marshal
    Posts: 56541
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I personally would try Head First (HFJ) and dip into the Java Tutorials when there is something I don't understand in HFJ. Remember that HFJ is now quite old so there are many second‑hand copies available for a good price.
     
    akshay naidu
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    the only problem i see in HFJ is that its for java5 verison.
     
    Campbell Ritchie
    Marshal
    Posts: 56541
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Why do you think that is a problem? You can always learn the newer features afterwards.
     
    akshay naidu
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    ok.
    i just successfully executed BeerSong program from HFJ.
    java is really interesting. and this forum and you guys are making it even more interesting.
    thanks again
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!