• 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

"assert" keyword?!!!

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Some mock exams say "assert" is a keyword, Is it true.
thanks
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that is true.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's true for JDK 1.4. It's not true for earlier JDKs. So it really depends what exam you're taking, and how they word the question.
[ May 30, 2003: Message edited by: Jim Yingst ]
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is definately true, look at the new keyword list from KnB book or any other references
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It is definately true


Gee, thanks for your input. I wonder if anyone here can imagine a situation where it might not be true, hmmm? :roll:
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim
You can think assert of assertion error invoking keyword if the required condition is not met. Let's consider a scenario: We have 52 playing crads in all. Now you may wish to check this in a program that whether the cards are infact 52 or not. eg. assert cards==52; now if the cards are equal to 52 it's OK else an error would be thrown at runtime when this statement is encountered. Provided that exceptions are enabled at runtime.

I wonder if anyone here can imagine a situation where it might not be true, hmmm?


Secondly assert false; will make an assert statement to throw an assertion.
Or
Consider this : assert 2<0; would also be false.
Or were you asking a situation where assert is not a keyword.
Consider this:
boolean assert = false;
if(assert) { throw new RuntimeException(); }
For versions before 1.4 ( excluding 1.4) assert was not a keyword. So it's OK to do so. But now assert is a keyword hence if assertions are enabled when compiling, an error would be reported.
I guess that now assert is a keyword it should not be used an identifier even if the current compiler you are using is less than 1.4 or you don't intent to use assertions for compilers equal to or greater than 1.4.
[ May 31, 2003: Message edited by: Anupam Sinha ]
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, my question was not really intended to ask for more information on assertion; it was intended to ask whether Robbie had actually read my previous reply before contradicting it.
JY: Assert is a keywork in 1.4 but not 1.3.
RK: Assert is definitely a keyword.
JY: Is there any exception to this statement?
[Intended answer]: Yes - assert is not a keyword in 1.3. As Jim said in his first post. :roll:
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim
I am feeling like a fool :roll: . Well I really didn't notice that you are a sheriff and went on to explain you about assert. I really feel very foolish.
 
mari krishna
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
lot many thanks,
mari
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mari,
Welcome to Javaranch, a friendly place for Java greenhorns
We ain't got many rules 'round these parts, but we do got one. Please change your displayed name to comply with the JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
reply
    Bookmark Topic Watch Topic
  • New Topic