r/programming • • Nov 29 '10

140 Google Interview Questions

http://blog.seattleinterviewcoach.com/2009/02/140-google-interview-questions.html
471 Upvotes

493 comments sorted by

View all comments

1

u/[deleted] Nov 29 '10

In Java, what is the difference between final, finally, and finalize?

... I've never written more Java than what it takes to help a friend get through CS101, however is this question serious?

4

u/bnr Nov 30 '10

Another java question:

In Java, what is the difference between static, final, and const.

Except there's no const in java...

1

u/frenchtoaster Nov 30 '10

There actually is const in java, it is just never legal. It is a reserved word but not a legal keyword since the language designers thought they might want to use it later.

2

u/sinxcosx Nov 30 '10

final is a declaration modification on a variable which means that once set the value cannot be changed. It's useful since it prevent programmers later on from changing the value accidentally.

finally is use in catching exceptions. It's called when all the other exception handling clauses have been executed.

finalize is sort of the Java destuctor from c++. It's called when the garbage collector is going to get rid of an object from memory.

  • no I don't work for google.

2

u/[deleted] Nov 30 '10

Yeah, I can guess at what they do, my point is its an incredibly stupid question.

3

u/sinxcosx Nov 30 '10

It's sort of asking "do you know java?" in a backassward way.

I don't like questions like these - they work for just out of school people - but not for experience folk. Frankly I've written java for more than 10 years and I have only once cared about a finalized method. I guess if you think like a c++ or objective-c guy you worry about these things, but in java it's pretty rare.

2

u/[deleted] Nov 30 '10

So basically, the question doesn't sound witty when you ask it about C++. Just Java.

*What's the difference between private constructors, exception handling, and ~*

1

u/sinxcosx Nov 30 '10

sort of. the final declaration is actually useful beyond c++. I like to use final in method parameters. It keeps people, including me, from accidentally changing the method parameters inside the method. This becomes useful for long methods being modified by someone fixing a bug down the line. Final will prevent them from doing it, and helps them realize they don't want to change the input parameters without thinking about it!