aspose file tools
The moose likes Programming Diversions and the fly likes Funny(deadly) Interview Question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Other » Programming Diversions
Reply Bookmark "Funny(deadly) Interview Question" Watch "Funny(deadly) Interview Question" New topic
Author

Funny(deadly) Interview Question

Siddhesh Deodhar
Ranch Hand

Joined: Mar 05, 2009
Posts: 117
For my campus placements, Interviewer asked me one funny(deadly) question.
He said, "write a program whose output is the program itself".

I thought on it for while, Interviewer was smiling saying take your own time kid and started smoking.

After stretching my head i shouted, "Sir, within my code I will read the same code file and display"
"Amazing kid"..you are right, please write it and show me.
With victorious face, i wrote code in front of him in C considering standard's, indentation and other conventions.

Interviewer was very happy and started behaving like he is my uncle. . Asked me few questions about my family and some other technical stuff.
I got selected without any hassle.

He gave me few sample answers which my friends told him. Following are some which i rememebred
- We need to read RAM
- We need to print code as it is in "print" statements.

Well, This might be a joke, but the question he asked me can stand deadly when you are under pressure.

Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd : (SCJP 6 [90%] )
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 952
However often the executable (or the .class or .jar file for Java) is distributed without the source code file. If you had to solve the problem WITHOUT the source code available at run time, how would you do it.

Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 154
    
    2

Another take on this problem is something like...

and run the program with the following arguments:
java Test Test


Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

There is a word for such a program; it's called a "Quine", if you're interested in Googling. The solution you've described -- reading the source and printing it -- is considered a cheat, and is not a valid quine. It's entirely possible to create genuine quines that don't read their own source.


[Jess in Action][AskingGoodQuestions]
Yogesh Gnanapraksam
Ranch Hand

Joined: Dec 17, 2009
Posts: 133
Tina Smith wrote:Another take on this problem is something like...

and run the program with the following arguments:
java Test Test


I don't understand !!! how this is supposed to be Quine
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10040
    
    6

Tina Smith wrote:Another take on this problem is something like...

and run the program with the following arguments:
java Test Test

This won't compile.


Never ascribe to malice that which can be adequately explained by stupidity.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3860
    
    1

Ernest Friedman-Hill wrote:The solution you've described -- reading the source and printing it -- is considered a cheat, and is not a valid quine.

It's probably the sort of cheat that would go down well in an interview if you can't actually create a genuine quine, though .
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2816
    
    2
Matthew Brown wrote:
Ernest Friedman-Hill wrote:The solution you've described -- reading the source and printing it -- is considered a cheat, and is not a valid quine.

It's probably the sort of cheat that would go down well in an interview if you can't actually create a genuine quine, though .

Also a perfectly legitimate answer if the interviewer hasn't actually specified that you can't read the source file. Might as well go with a solution that's simple and easy to maintain.
Daniel Doboseru
Ranch Hand

Joined: Sep 26, 2011
Posts: 57
@Siddhesh: you said:
For my campus placements, Interviewer asked me one funny(deadly) question.

What do you mean be campus placements? You're student and for a place in the campus you had a technical interview as for hiring?
Yogesh Gnanapraksam
Ranch Hand

Joined: Dec 17, 2009
Posts: 133
What do you mean be campus placements?


It refers to an event organized by the college management in which various companies visit the college campus and conduct written tests and technical interviews and give a job offer to the candidates who seem to fit their requirements.
Daniel Doboseru
Ranch Hand

Joined: Sep 26, 2011
Posts: 57
Oh, i see. Very nice thing. We have such a thing too: several companies come and present their offer, technologies etc and afterwards accept CVs from interested students, offering them the chance of a interview. We call them generically InfoTechs (ElectroTech, InstallTech, MechaniTech depending of the faculty).
simi selva
Greenhorn

Joined: Nov 18, 2011
Posts: 2
nice.. I have to learn more about quines...
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4095
    
    1
from wikipedia:

A quine is a computer program which takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the computability theory and computer science literature are self-replicating programs, self-reproducing programs, and self-copying programs.

sounds a lot like a worm to me.

where did this interview take place?
viruses are us ?

SCJP
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4095
    
    1

However often the executable (or the .class or .jar file for Java) is distributed without the source code file. If you had to solve the problem WITHOUT the source code available at run time, how would you do it.

so much for my career as a virus writer
Bhanuprakash Sreenivas
Greenhorn

Joined: Jan 01, 2010
Posts: 8
Since Java is compiled and then interpreted , technically it is not feasible to get a exact copy of the
source code.
For example - The comments of a source will not be visible.

Directly interpreted languages like Javascript can be used to achieve this.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

Bhanuprakash Sreenivas wrote:Since Java is compiled and then interpreted , technically it is not feasible to get a exact copy of the
source code.
For example - The comments of a source will not be visible.

Directly interpreted languages like Javascript can be used to achieve this.


Indeed, the many working examples above are all imaginary.
Bhanuprakash Sreenivas
Greenhorn

Joined: Jan 01, 2010
Posts: 8
Ernest Friedman-Hill wrote:
Bhanuprakash Sreenivas wrote:Since Java is compiled and then interpreted , technically it is not feasible to get a exact copy of the
source code.
For example - The comments of a source will not be visible.

Directly interpreted languages like Javascript can be used to achieve this.


Indeed, the many working examples above are all imaginary.


Oops.. jumped the gun
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 380

here is java Quine program

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10040
    
    6

naveen yadav wrote:here is java Quine program



This doesn't work...I get a "File not found" error...Note that there are examples above that DO work, without requiring the source file.
Andy Jack
Ranch Hand

Joined: Nov 22, 2012
Posts: 257
an important question is - why do i need a quine ?

Java Newbie with 72% in OCJP/SCJP - Super Confused Jobless Programmer.
I am a "newbie" too. Please verify my answers before you accept them.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3860
    
    1

You don't. There's no practical use (that I can think of), it's just a puzzle. Some people find the challenge interesting.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Funny(deadly) Interview Question
 
Similar Threads
What is the relation between abstraction and security?
Doubt in Object oriented concept
Interview Questions
Interview Experiences
Bjarne Stroustrup's interview - uncut version!