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;
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.
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.
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)
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 ]
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.
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...........???
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.