• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

An interview question I faced recently

 
Author
Posts: 3445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What gets printed for the following code snippet?




 
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just checked in Eclipse and Java 6, got the output: 65535

Still trying to figure it out.
 
arulk pillai
Author
Posts: 3445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pushkar Choudhary wrote:Just checked in Eclipse and Java 6, got the output: 65535

Still trying to figure it out.




Start with, -1 in binary is represented as all 1's.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A bad question. Whether you get the answer right or wrong proves nothing.

I can understand why the answer is what it is, but the question is a waste of time.
 
arulk pillai
Author
Posts: 3445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will have to admit that there were other good questions. The interviewer clearly indicated that it was an optional question to ascertain how technical I was. He was also more interested in the approach.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A poor question in my opinion. Not sure how it demonstrates how "technical" a person is. If the question was about recitation of numeric casting rules it might make more sense. But to ask someone what will get "printed" is a bit looney ... and a waste of time.
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer this also Java Puzzler book have explaination about it.

According to my way of thinking the process is as follows.


first step is narrowing primitive conversions
second step + third step is widening & then narrowing primitive conversions
fourth step is widening primitive conversions
 
Ranch Hand
Posts: 343
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

James Clarks wrote:A poor question in my opinion. Not sure how it demonstrates how "technical" a person is.



Agreed. Obscure Java trivia questions (unless one is implementing a JVM themselves) speak far more about the interviewer than the candidate.

Cheers!

Luke
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ninad Kulkarni wrote:Refer this also Java Puzzler book have explaination about it.

According to my way of thinking the process is as follows.


first step is narrowing primitive conversions
second step + third step is widening & then narrowing primitive conversions
fourth step is widening primitive conversions



If it was stolen from the java puzzler book, thats even worse
 
Ninad Kulkarni
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Deepak

If it was stolen from the java puzzler book, thats even worse



All credit goes to authors of the Java Puzzlers book for this question already in java puzzle list in their book.
I given example of binary numbers to understand multiple cast process easily in the given question by using JLS3.0.
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ninad, I was not referring to you in my last post, I was referring to the person who took the interview. Just wanted to clarify that
 
Ninad Kulkarni
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Deepak for clarification. Now I got your point.
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic