| Author |
Assertion Doubt.
|
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Posts: 180
|
|
When i compile this follwing program, I get compilation FAILS.With warning. But it should compile and execute,but didn't happen.() javac -source 1.3 AssertTest.java AssertTest.java:7: warning: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier (use -source 1.4 or higher to use 'assert' as a keyword) int assert=12;
|
 |
Nabila Mohammad
Ranch Hand
Joined: Nov 05, 2007
Posts: 661
|
|
You are assigning 12 to assert which is of int type. That means you are using it as an identifier- And that's what your error says. Asser as identifier was only used prior to java 1.4. In java 5 , it is used as a keyword and not as an identifier. For it to run, you have to either run it in a version prior Java 1.4 platform specifying at compile time java - source 1.3 myAssert.java or simply use the assert as a keyword and not as an identifier. Hope that was helpul.
|
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
|
 |
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Posts: 180
|
|
|
But how can I compile it.
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
Change your code. "assert" is a reserved keyword. Use something else for your variable name. [ April 23, 2008: Message edited by: Ben Souther ]
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Ivan Ivanic
Ranch Hand
Joined: Oct 31, 2007
Posts: 100
|
|
you did compiled it, it said warning, not compilation failed... modify your class as given below, and then compile it as you did with option -source 1.3, and then execute it normaly with java AssertTest and voila you will see: this is value of assert : 12.
|
<a href="http://faq.javaranch.com/java/UseRealWords" target="_blank" rel="nofollow">Use Real Words</a> <a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">!!!Use Code Tags!!!</a> <a href="http://faq.javaranch.com/java/SayThanks" target="_blank" rel="nofollow">Say Thanks</a><br />scjp6
|
 |
Bert Bates
author
Sheriff
Joined: Oct 14, 2002
Posts: 8717
|
|
|
My vote is that Ivan is correct!
|
Eliminate fossil fuel subsidies. (If you're not on the edge, you're taking up too much room.)
|
 |
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Posts: 180
|
|
I know it is a keyword,but before JDK 1.3 can I use it as an identifier.As Ivan said I compiled with option:- javac -source 1.3 AssertTest.java Then i get following warnings:- ******* F:\>javac -source 1.3 AssertTest.java AssertTest.java:6: warning: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier (use -source 1.4 or higher to use 'assert' as a keyword) int assert=12; ^ AssertTest.java:7: warning: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier (use -source 1.4 or higher to use 'assert' as a keyword) System.out.println("this is value of assert : " + assert); ^ 2 warnings ************* I am using Wni XP,JDK 1.6 BUT WHEN I EXCECUTE IT THEN I GET:- F:\>java AssertTest Exception in thread "main" java.lang.UnsupportedClassVersionError: AssertTest (U nsupported major.minor version 48.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) Then what can I do...... Thanks to all and waiting for suggestions..
|
 |
Ivan Ivanic
Ranch Hand
Joined: Oct 31, 2007
Posts: 100
|
|
heh, beats me... are you using some IDE or working directly in command prompt? i'm working in Ubuntu, Java 6, and things work as I described... [ April 24, 2008: Message edited by: Ivan Ivanic ]
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12956
|
|
Exception in thread "main" java.lang.UnsupportedClassVersionError: AssertTest (Unsupported major.minor version 48.0) Are you sure that you are running this on Java 6? What information do you get if you run this: java -version
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
samith pinnaduwa
Greenhorn
Joined: Apr 22, 2008
Posts: 6
|
|
|
even i have to say is there are no probs with d code.warning will occur when v do like that.doesnt matter it must b ru without errors.
|
SCJP 1.5
SCWCD 1.5
|
 |
Ivan Ivanic
Ranch Hand
Joined: Oct 31, 2007
Posts: 100
|
|
Originally posted by samith pinnaduwa: even i have to say is there are no probs with d code.warning will occur when v do like that.doesnt matter it must b ru without errors.
what are you trying to say???
|
 |
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Posts: 180
|
|
Yes i am running in JDK 1.6.When I run java -version then i get : C:\Documents and Settings\Ashok>java -version java version "1.3.1_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01) Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode) ******* But i have installed JDK 1.6 and it is in C:\Program Files\C:\Program Files\Java\jdk1.6.0_03\ and in System Variable my path setting is path-C:\Program Files\Java\jdk1.6.0_03\bin I think there is some problem in my computer ,because when i try in another PC that have JDK 1.6 that works fine. I have Oracle 9i installed in my PC so is that cause the problem ?is that I am running all my program in JDK 1.3.How can i run my program in JDK 1.6 Thanks to all
|
 |
Ivan Ivanic
Ranch Hand
Joined: Oct 31, 2007
Posts: 100
|
|
what is your full PATH varible??? try to remove wrong version through add/remove programs... Hope that helps
|
 |
samith pinnaduwa
Greenhorn
Joined: Apr 22, 2008
Posts: 6
|
|
|
i was try to say is when we use assert as a variable name and using javac -source 1.3 we always get the warnings.did you understand Ivan...........???
|
 |
Ivan Ivanic
Ranch Hand
Joined: Oct 31, 2007
Posts: 100
|
|
Originally posted by samith pinnaduwa: i was try to say is when we use assert as a variable name and using javac -source 1.3 we always get the warnings.did you understand Ivan...........???
Yes. You are right.
|
 |
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Posts: 180
|
|
|
My path variable is:-C:\Program Files\Java\jdk1.6.0_03\bin
|
 |
samith pinnaduwa
Greenhorn
Joined: Apr 22, 2008
Posts: 6
|
|
|
what is your classpath friend?
|
 |
Ivan Ivanic
Ranch Hand
Joined: Oct 31, 2007
Posts: 100
|
|
|
did you check both your system variables and your user variables?
|
 |
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Posts: 180
|
|
I have only set path for only for System Variables is that classpath is required for compiling java files. path :: C:\Program Files\Java\jdk1.6.0_03\bin
|
 |
Ivan Ivanic
Ranch Hand
Joined: Oct 31, 2007
Posts: 100
|
|
well that leaves me without suggestions... i really can't understand where from you got that java1.3...
|
 |
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Posts: 180
|
|
|
Thanks to all !!!
|
 |
Ivan Ivanic
Ranch Hand
Joined: Oct 31, 2007
Posts: 100
|
|
no problem but now I'm really interested if you managed to solve The Mistery ?
|
 |
Stevi Deter
Ranch Hand
Joined: Mar 22, 2008
Posts: 265
|
|
Ashok, Is the java 1.6 directory really the only element in your path? What do you get when you open a cmd window and type path? I suspect that when you installed Oracle, it put its path to the JRE in your System Environment Path, and if I remember correctly, Oracle 9 used Java 1.3.
|
There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
|
 |
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Posts: 180
|
|
Hi, friends when i type path in cmd window I get follwing things: C:\Documents and Settings\Ashok>path PATH=D:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\ Oracle\jre\1.1.8\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\ jakarta-tomcat-5.0.25\common\lib\servlet-api.jar;C:\Program Files\Java\jdk1.6.0_ 03\bin;C:\Program Files\QuickTime\QTSystem\;C:\MSSQL7\BINN;C:\TC\BIN;E:\Ashok\vl c-0.8.4a\vlc.exe ***** And there is C:\Program Files\Oracle\jre\1.3.1\bin;
|
 |
Stevi Deter
Ranch Hand
Joined: Mar 22, 2008
Posts: 265
|
|
You can remove the following entries from your PATH; Oracle will run fine with the newest JDK. C:\Program Files\Oracle\jre\1.3.1\bin C:\Program Files\Oracle\jre\1.1.8\bin
|
 |
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Posts: 180
|
|
thanks Stevi & All NOW IT WORKS FINE... I have removed these two entries from path: C:\Program Files\Oracle\jre\1.3.1\bin C:\Program Files\Oracle\jre\1.1.8\bin and now I am in JDK 1.6 ********************XXXXXX********************
|
 |
 |
|
|
subject: Assertion Doubt.
|
|
|