• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assertion Doubt.

 
Ranch Hand
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ashok Pradhan
Ranch Hand
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But how can I compile it.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change your code.
"assert" is a reserved keyword.
Use something else for your variable name.
[ April 23, 2008: Message edited by: Ben Souther ]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My vote is that Ivan is correct!
 
Ashok Pradhan
Ranch Hand
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ivan Ivanic
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is your full PATH varible???
try to remove wrong version through add/remove programs...
Hope that helps
 
samith pinnaduwa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My path variable is:-C:\Program Files\Java\jdk1.6.0_03\bin
 
samith pinnaduwa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is your classpath friend?
 
Ivan Ivanic
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did you check both your system variables and your user variables?
 
Ashok Pradhan
Ranch Hand
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well that leaves me without suggestions...
i really can't understand where from you got that java1.3...
 
Ashok Pradhan
Ranch Hand
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all !!!
 
Ivan Ivanic
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no problem
but now I'm really interested if you managed to solve The Mistery ?
 
Ranch Hand
Posts: 265
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ashok Pradhan
Ranch Hand
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 265
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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********************
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic