Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Please explain this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Please explain this" Watch "Please explain this" New topic
Author

Please explain this

Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
I would like to know what the statement below means and what is the meaning of the word "invariant".
Whenever you would have written a comment that asserts an invariant.
Rajinder Yadav
Greenhorn

Joined: May 13, 2003
Posts: 27
Was there something more to that line, hard to tell what context this statement was being used in?
The word 'invariant' means unchangable, something that is constant.


When faced with an easy thing to do and a hard thing to do, always pick the right thing to do!<p><a href="http://yadav.shorturl.com" target="_blank" rel="nofollow">Rajinder Yadav</a>
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Rajinder
Thanks Rajinder for the prompt reply. Sorry for the incomplete question. The question was asking about when should an assert statement be used. So we can say that final vars. and Strings are invariant.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
An invariant is a rule that applies throughout the life of a data structure or procedure, and all changes must maintain the correctness of the invariant.
Say you have a program which is simulating some card game. You know that each pack of cards must have 13 cards of each suit, and that the suits are spades, hearts, diamonds and clubs. So, it is appropriate to use assertions which test the above, eg there cannot be more than 13 cards of the spade suit.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Thanks Rajinder and Roger.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please explain this
 
Similar Threads
Mock question about assert..
How to approach my setters
Making the Data Class a Singleton & Thread Safe
Compilation Fails at Line 2.
Is there a way to get an absolute row id for a JTable model