So... you think you know Java?

berry120

Fully Optimized
Messages
3,434
Location
UK
The title says it all really. If you think you're good at Java, see how many of these you can get right and how many catch you out ;)

If you don't class yourself as a good Java programmer, it's interesting stuff to find out anyway!

http://mikkle.co.uk/javaquiz
 
That was messed up. None of my fill-in-the-blank answers were evaluated. I'm pretty sure I got all of the output questions right. I've never programmed in Java, but it's similar enough to C++.
 
I've never programmed in Java, but it's similar enough to C++.
I'm afraid this assumption is probably where you fell down...!

The quiz was designed to be the nit-picking, trick question type as a laugh more than anything. It's aimed at casual Java developers to prove that not everything is always as it seems, and perhaps teach a thing or two along the way.

I've got what I'm pretty sure are your set of answers here in front of me, and if so then I'm afraid all your answers were indeed evaluated... you just fell into most of the common traps! ;)
 
Errmm... I think that whoever wrote that quiz needs to take a "So... you think you know PHP?" style quiz. As JogaBonito said, None of my typed answers where read!
 
They're not always listed after you wrote the question - I think this might be a bug in the quiz module for drupal, but they're definitely evaluated.

To give you an example of one of the traps:

Code:
What does this output?

long num = 6l;
System.out.println(num);

The right hand digit is in fact not a 1, but an L. (It's less obvious using some fonts than others.) Judging by the date / time of the reports I've got and the date / time of your posts, it looks like Joga put 61, mistakenly thinking the lower case L was a 1 (that's the most common trap!) and j03 put error, picking up that it was an L but assuming the compiler would complain (second most common trap.)

In fact, putting an L after a number in Java denotes that this number is of type long, not of type integer. If you type:

long num = 2147483649;

...then you'll get an error, because Java evaluates the thing on the right as an int rather than a long, and complains it's too big. You'd need:

long num = 2147483649L;

...before it'd work. Of course in practice you should always use an upper case L for clarity if you need to specify long numbers, but the compiler will still let through a lower case l with the same functionality.

Again, with the:

int num = 0123;

question, it seems you both put 0123 or 123 - but actually, when you start an integer with 0 this tells Java you're writing it in octal, not in decimal... ;-)

See where this quiz is going now? :)
 
That's dirty lol, but to be honest I'm not really disappointed or anything. I've never programmed in Java.
I wouldn't be - if you get more than 1 or 2 right and you've never done Java before then that's pretty good going! :)
 
Back
Top Bottom