| Wed, 09/16/2009 - 03:23 by Emmanuel Stapf | Wed, 09/16/2009 - 03:24 by Emmanuel Stapf | ||
|---|---|---|---|
| < previous diff | next diff > | ||
| Changes to Body | |||
Last week I was at the LASER 2009 summer school on Software Testing. It was pretty interesting and one brief 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 and bet that no one would have the right 6 answers.
| Last week I was at the LASER 2009 summer school on Software Testing. It was pretty interesting and one brief 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 and bet that no one would have the right 6 answers.
| ||
| - | Let's start to do the same here. I'm going to give you the exercises and will post the answers in my next blog entry.
| + | Let's do the same here. I'm going to give you the exercises and will post the answers in my next blog entry.
|
1. What is the value of '''b''' at the end of this code:
| 1. What is the value of '''b''' at the end of this code:
| ||
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''' at the end of the call as well as the return value:
| 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''' at the end of the call as well as the return value:
| ||
<java>
| <java>
| ||
| + | int b;
| ||
int foo () {
| int foo () {
| ||
b = 0;
| b = 0;
| ||
...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 brief 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 and bet that no one would have the right 6 answers.
Let's do the same here. I'm going to give you the exercises and will post the answers in my next blog entry.
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 at the end of the call as well as the return value:
int b; int foo () { b = 0; try { b++; return b; } finally { b++; } }
?
PS: Feel free to post your answers as comments to this blog entry.