aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark ""assert" keyword?!!!" Watch ""assert" keyword?!!!" New topic
Author

"assert" keyword?!!!

mari krishna
Greenhorn

Joined: Feb 13, 2003
Posts: 10
Hi,
Some mock exams say "assert" is a keyword, Is it true.
thanks
Kaz Yosh
Ranch Hand

Joined: May 22, 2003
Posts: 63
that is true.


"If anything can go wrong, it will"
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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 ]

"I'm not back." - Bill Harding, Twister
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
It is definately true, look at the new keyword list from KnB book or any other references


SCJP 2 1.4
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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:
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
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
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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

Joined: Apr 13, 2003
Posts: 1088
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

Joined: Feb 13, 2003
Posts: 10
Hi there,
lot many thanks,
mari
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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!


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
Consider Paul's rocket mass heater.
 
subject: "assert" keyword?!!!