Hi again! I am having problems with figuring out the usage of Java's asssertions. I know that they are primarily intended for testing reasons and they can disabled/enabled etc. But can anyone of you give me an example how these assertions related things can be tested in the exam? Can f.ex anyone that already has passed the programmer test, recall from their experiences how this feature was tested in their particular exam? I would appreciate your experiences very much! Cheers, janne
Questions can be asked on the appropriate use of assertions. For example, they might show a public method where assertions are used to validate passed parameters and ask if this is a valid use of assertions.
My first column in the Java Developer's Journal was "Using Assertions". You can read it at http://www.sys-con.com/story/?storyid=34283. Even experienced programmers are sometimes not sure when to use assertions. It is a difficult subject.
Download a copy of <a href="http://www.javarules.com" target="_blank" rel="nofollow"><i>"Mastering The Fundamentals of The Java Programming Language"</i></a>
I have a C background, and I have to do some stuff in C++. I celebrated when Sun added assertions because I found them invaluable in testing C/C++ code to make sure things don't break from passing invalid arguments, etc. Because Java doesn't permit conditional compilation as such, assertions are the closest tool the Java programmer gets to a conditional compilation. Remember, assert is a programmer/tester debugging and testing tool; don't put any code in your assertions that the program relies on. I think that once the Java community appreciates the power of assertions, they (assertions) will be much more widely used and understood.
Give a man a fish, he'll eat for one day. <br />Teach a man to fish, he'll drink all your beer.<br /> <br />Cheers,<br /> <br />Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)