• 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

Compilation errors on assert key word

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys, till now i was working on 1.2.2 version and today to test few assert examples, i D/L 1.4.2.
Wrote the below program but it is giving errors while i try to compile. Compiler errors are
]


D:\JAVACE~1\ASSERT~1>javac test145.java
test145.java:7: warning: as of release 1.4, assert is a keyword, and may not be
used as an identifier
assert true;
^
test145.java:7: not a statement
assert true;
^
test145.java:7: ';' expected
assert true;
^
2 errors
1 warning



When i check the java version it is showing 1.4.2 only. PLEASE HELP


D:\JAVACE~1\ASSERT~1>java -version
java version "1.4.2_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)
Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)
[/QUOTE

 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shekhar,
Please checkout pages 260 & 261 in K&B book. It helps.
From text...
Remember, assertions are diabled by default in 1.4, both at compile time and run time.
Hope this helps.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try compiling and running your class with the -ea or -enableassertions parameter. Compiler sees this like

HTH,
B.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sekhar
When you run your program on sdk 1.4 or above, u have a possibility to use assertion, but you should diasable them, 'cause by default they are not!
in compilation you should tape
> javac -source 1.4 Example.java
and for running
> java -ea Example.class
hope u understood me!
 
Sekhar Kadiyala
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, Thanks fethi. I wass home today and read the K&B for this. It also says the same. So tomorrow i am gonna try that.
I can't wait any more. Its just 3 more days!!!
 
I love a good mentalist. And so does this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic