Forums Register Login

Assertion Doubt.

+Pie Number of slices to send: Send
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;
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
But how can I compile it.
+Pie Number of slices to send: Send
Change your code.
"assert" is a reserved keyword.
Use something else for your variable name.
[ April 23, 2008: Message edited by: Ben Souther ]
+Pie Number of slices to send: Send
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.


+Pie Number of slices to send: Send
My vote is that Ivan is correct!
+Pie Number of slices to send: Send
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..
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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???
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
what is your full PATH varible???
try to remove wrong version through add/remove programs...
Hope that helps
+Pie Number of slices to send: Send
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...........???
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
My path variable is:-C:\Program Files\Java\jdk1.6.0_03\bin
+Pie Number of slices to send: Send
what is your classpath friend?
+Pie Number of slices to send: Send
did you check both your system variables and your user variables?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
well that leaves me without suggestions...
i really can't understand where from you got that java1.3...
+Pie Number of slices to send: Send
Thanks to all !!!
+Pie Number of slices to send: Send
no problem
but now I'm really interested if you managed to solve The Mistery ?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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;
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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********************
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1547 times.
Similar Threads
doubt in assert...
Question w.r.t Assertions
Program with assert does not compile
Assertions
K&B "assert " explanation
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:39:20.