| Mon, 09/14/2009 - 18:44 by Emmanuel Stapf | Mon, 09/14/2009 - 18:52 by Emmanuel Stapf | ||
|---|---|---|---|
| < previous diff | next diff > | ||
| Changes to Body | |||
}
| }
| ||
b++;
| b++;
| ||
| + | }
| ||
| + | </java>
| ||
| + | ?
| ||
| + | |||
| + | 5. The previous sample was too long, what does this return:
| ||
| + | <java>
| ||
| + | int foo () {
| ||
| + | try {
| ||
| + | return 1;
| ||
| + | }
| ||
| + | finally {
| ||
| + | return 2;
| ||
| + | }
| ||
| + | }
| ||
| + | </java>
| ||
| + | ?
| ||
| + | |||
| + | 6. If you have answered properly to the above questions, then you are definitely quite an expert. To prove it, tell us the value of '''b''' below:
| ||
| + | <java>
| ||
| + | int foo () {
| ||
| + | b = 0;
| ||
| + | try {
| ||
| + | b++;
| ||
| + | return b;
| ||
| + | }
| ||
| + | finally {
| ||
| + | b++;
| ||
| + | }
| ||
}
| }
| ||
</java>
| </java>
| ||
? | ? | ||
...and people are still using java?

Last week I was at the LASER 2009 summer school on Software Testing. It was pretty interesting and one talk captured my attention. The speaker, Martin Nordio, asked the audience if they knew Eiffel and only a few hands were raised. So he asked if they knew Java instead. Everyone raised his hand. To show to the audience they were wrong in assuming they knew about Java, he showed 6 samples of source code written in Java and asked the audience what the program did.
So let's start to do the same here. I'm going to give you the exercises and will post the answer in a different blog next time.
1. What is the value of b at the end of this code:
foo () { int b = 1; b++; }
?
2. What is the value of b at the end of this code:
foo () { int b = 1; while (true) { b++; break; } }
?
3. What is the value of b at the end of this code and tell us if this executes normally or with an exception:
foo () { int b = 1; try { throw new Exception(); } finally { b++; } }
?
4. What is the value of b at the end of this code and tell us if this executes normally or with an exception:
foo () { int b = 1; while (true) { try { b++; throw new Exception(); } finally { b++; break; } } b++; }
?
5. The previous sample was too long, what does this return:
int foo () { try { return 1; } finally { return 2; } }
?
6. If you have answered properly to the above questions, then you are definitely quite an expert. To prove it, tell us the value of b below:
int foo () { b = 0; try { b++; return b; } finally { b++; } }
?