This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I compile my application, but when I run the application I get this message," C:\>javac Ch2Birthdate.java
C:\>java Ch2Birthdate Exception in thread "main" java.lang.UnsupportedClassVersionError: Ch2Birthdate (Unsupported major.minor version 49.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)
possible reasons - 1. u have 2 versions of jdk in ur path 2. You compiled using one version of jdk and try to run the program using some other version.
Joined: Jan 27, 2005
ram, thanks for the advice. I checked my path, and there was other things in there. So I cut everything out except C:\Program Files\Java\jdk1.5.0_01\bin. I tried to run the application again, and I got the same error.
Next, I checked my java runtime settings. The path for user is "C:\Program Files\Java\jre1.5.0-01\bin\javaw.exe", The path for the system is the exact same.
I also have oracle, and jre1.4 installed on my computer if this matters.
Perhaps try running both javac and java by specifying the full path to both to make absolutely sure you know which is running. Also, you can do "java -version" and "javac -version" (two dashes? I don't ermember).
On a side note, you should get into the habit of always specifying a package for every class. The first non-comment/blank line should beYou'll need to create a directory structure that matches it and put your source file into it. You still issue your compile/run commands from the directory that contains the root package.
Since you're doing this in the root of your C drive, let's use "test" as the package. Create c:\test and put Ch2Birthdate.java into it. Addto the top of the file. Then compile and run usingI don't think that's the issue here, but it's still a good practice. For one thing, you cannot import a class that's ni the default package.
Remove java.exe and javaw.exe from your windows installation directories. Not all JVM installers properly update those under all conditions, leading old versions to be used when trying to execute Java programs. But as there's no javac.exe there that one will get called from the directory you installed the JDK to.