• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

interview question of the day (04/04/2008)

 
Ranch Hand
Posts: 3851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to start this column sort of thing every possible day - of course with mods� permission.

The only rule to answer is: Don't try it out, just answer based on your logic/pre-knowledge. Please follow it.

So the question for today (04/04/2008 at 7:30 PM IST) is:

What'll happen if I assign null to this in a method? And why?

Let�s see how many answers we get.

Thanks.
[ April 08, 2008: Message edited by: ankur rathi ]
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


What'll happen it I assign null to this in a method?



What will happen to you?
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't assign anything to "this". because you need to have variables on the left side of the assignment.
 
Ranch Hand
Posts: 115
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you assign null to this, the execution stops, and the object which you are working with will be ready for garbage collected.

Please correct me, if i am wrong.

Thanks & Regards,
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My answer: I would hope that it is a compile time error. I seem to remember that I once saw such code that did compile. I think it was due to a bug in the Eclipse compiler. But you shouldn't need to know what happens in this case, because anyone who tries to do that in production code should be shot.
 
Author
Posts: 3450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why will this make a good interview question?
 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ankur,

Good that you are starting "Interview Question of the day" posts.

The question seems to be good Arulk , Well you can see many people don't know the answer to this as well.
[ April 06, 2008: Message edited by: SIM KIM ]
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

If we assign null to this it will give a compiler
error as this a final variable and we cannot assign
value to it value.



Dhwani:>Winning is not important but it is the only thing.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by SIM KIM:
Ankur,
Good that you are starting "Interview Question of the day" posts.

The question seems to be good Arulk , Well you can see many people don't know the answer to this as well.



With that reasoning, "how do you write 'Java' in Klingon" would be a good interview question, too...

Mhh, thinking about it, perhaps it *is* a good interview question!
 
Ranch Hand
Posts: 343
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by SIM KIM:
The question seems to be good Arulk , Well you can see many people don't know the answer to this as well.



I am puzzled why you think that the value of a question has anything to do with the number of people who can answer it correctly.

I suppose there are one or two places that absolutely require an in-depth knowledge of the Java API and the compiler rules. But unless that's a non-negotiable requirement, asking a question such as this does absolutely nothing to determine whether the applicant is a good Java programmer; only if he or she has a good grasp of this arcane matter. Interviews are too short to waste on such questions, and you run the real risk that your applicant may draw their own conclusions about you from such a question.

IDEs can automate API references very well. I don't see why we should be checking applicants on whether they can do something that an IDE or compiler can answer for us within a few seconds. We spend far too little time asking applicants about their results and ability to deliver, and far too much time focusing on trivia.

Cheers!

Luke
 
ankur rathi
Ranch Hand
Posts: 3851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Manisha Singh:
You can't assign anything to "this". because you need to have variables on the left side of the assignment.



this is a reference to the current object. Can't we have reference at the left site? We can have.
 
ankur rathi
Ranch Hand
Posts: 3851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by dhwani mathur:
hi

If we assign null to this it will give a compiler
error as this a final variable and we cannot assign
value to it value.



Dhwani:>Winning is not important but it is the only thing.



That�s a good logic but I doubt if it�s correct as we get error something like �you must have a variable at left side��
 
dhwani mathur
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ankur!!

i agree with you on this that it comes to error that

there should be a variable on left side
.

But i still doubt if we can assign null to this

as it is final.


Dhwani:>Winning is not important but it is the only thing.
 
ankur rathi
Ranch Hand
Posts: 3851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by dhwani mathur:
hi ankur!!

i agree with you on this that it comes to error that

there should be a variable on left side
.

But i still doubt if we can assign null to this

as it is final.


Dhwani:>Winning is not important but it is the only thing.



Dhwani, you are absolutely right. We can't assign null to 'this'. It�s a compile time error. I only doubt on the logic that it's because 'this' is final...
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ankur rathi:
I would like to start this column sort of thing every possible day - of course with mods� permission.


Please see this topic.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Luke Kolin:

unless that's a non-negotiable requirement, asking a question such as this does absolutely nothing to determine whether the applicant is a good Java programmer; only if he or she has a good grasp of this arcane matter.



I disagree. You also learn how the applicant deals with "unreasonable" requests. Which might be exactly what you want to learn.
 
Sim Kim
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Luke Kolin ,

I think its a very good question to be asked in the interview . No one will judge you by only this question but its good to know how the person answers this and his approach for it.

Well there can be many other question which I know that do not qualify as good questions like asking the person regarding Java 3D API , WS-I Conformance Claims for tModel (UDDI) etc . I dont expect the person to know everything regarding the Java API but atleast if the guy says he know JAva , he should know what is meant by "this" .
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My answer would be 'why would I ever assign 'this' to null ?'. I dont see any logical reason behind doing it. Firstly this question would reduce the interviewers credibility. Secondly I would start thinking twice about joining a company where an employee would ask me this question.

anyone who tries to do that in production code should be shot.



I can provide the gun free of charge
 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no harm in asking these questions.
Recently I was asked how many petrol pumps are there in New dellhi?
I ansered this question and interviewer was happy
 
arulk pillai
Author
Posts: 3450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Recently I was asked how many petrol pumps are there in New dellhi?
I ansered this question and interviewer was happy




The above analytical question is very common and I was asked this question at least couple of times. You also can get asked questions like "How will you determine how many litres of paint is required to paint the Sydney Harbour Bridge?" etc.
 
Ranch Hand
Posts: 376
Scala Monad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by arulk pillai:



The above analytical question is very common and I was asked this question at least couple of times. You also can get asked questions like "How will you determine how many litres of paint is required to paint the Sydney Harbour Bridge?" etc.



You got to love this answer:

2. Why are manhole covers round?
Why are condoms shaped liked tubes? I have no idea, and have never lost sleep thinking about this. How does this determine my value to the bottom line of a company that is not in the construction industry? Or does it tell you about my analytical abilities because a major software company uses queries such as this to weed out undesirables? Why don't you give me something real to analyze in your own business?

 
reply
    Bookmark Topic Watch Topic
  • New Topic