File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Assertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Assertion" Watch "Assertion" New topic


Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
I went through the sun's explanation, and other links provided in javaranch.
For what I understand, the only interest of assertion is debugging. If Your program fails to execute, it will throw an AssertionException, so you will know where it fails to execute!
Am I right, or does it have more goals?

By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Sure. It's for debugging and testing.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
One of the primary tenets of Asserts is that when they are not invoked (like in a production execution) they have a zero impact on execution. They were only intended to be brought into play during testing. This means that you can throw in as many zillion of them as you want - and leave them in the final code - but not worry about how they impact the performance.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Ravi Veera
Ranch Hand

Joined: Jun 23, 2001
Posts: 127
Asserts are part a important part of a programming and design technique known as "Programming By Contract".
Asserts were first part of the Eifel language. Here's a couple links that will explain these concepts much better than I can.
I do also remember reading a article on XP v/s programming by contract. XP and programming by contract take diametrically opposite approaches to writing code.
Briefly ,The points made were
-XP -minimal intial designcode for success and the code is your documentation and design.
-Programming by contract. Detailed Design,you code only according to design(contract) and your code covers both successes and failures.
Maybe somebody can throw some more light on the XP v/s programming by contract topic .
P.S Here's a couple of more intresting links on the topic.
A collection of links on java and programming by contract stuff..
[ April 25, 2002: Message edited by: Ravi Veeraghanta ]
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
Thx everybody for your help, everybody confirms that assertions is a debuging tool. But does it have other interest aspect?
I never heard this term :"programming by contract". I am going to find more information about it.
Thx for the help and the good links
I agree. Here's the link:
subject: Assertion
It's not a secret anymore!