[NTLUG:Discuss] Java/Linux versus school teacher.
    Rusty Haddock 
    rusty at fe2o3.lonestar.org
       
    Mon Mar 19 12:24:05 CDT 2007
    
    
  
Patrick R. Michaud wrote:
    >steve wrote:
    >> Do we have any Java/Linux guru's in the house?
I play one on TV.  Does that count? :-)
    >> [...]
    >>    Assume x and y are String variables with x="Hello" and y=null.
    >> [...]
    >>    2) It the operation y="Hello"; is performed then the result
    >>       of (x==y) is:
    >>        a) true
    >>        b) false
    >>        c) x and y becoming aliases
    >>        d) x being set to the value null
    >>        e) a run-time error
    >>
    >> Question 2 is a problem.  My son said "(a) true" but the
    >> teacher says that the answer is "(b)false" - and whilst
    >> I'm not a Java expert (I'm a C++ person) I can see why.  
    >
    >Actually, the answer in this case is "(a) true".  IIRC,
    >Strings in Java are immutable, and so the compiler optimizes
    >the compiled code such that any repeated constants are
    >folded to always refer to the same String object.  Thus, with
Immutable is irrelevant in this case.  It has nothing to do with repeated
constants getting stored once or n-times.  :-)
    >>      String x="Hello";
    >>      String y="Hello";
    >
    >The compiler generally optimizes this so that x and y both
    >refer to the same String object.  Thus with
And this has been the case with the Java Language since Day 1, I believe.
    >>      if ( x==y )
    >>        println ( "true" ) ;
    >>      else
    >>        println ( "false" ) ;
    >
    >the answer comes out "true".  :-)
    >
    >A useful test might be to try something like:
    >
    >    String x = "Hello";
    >    String y = "He" + "llo";
I completely agree.  This would be a far more pertinent question.
    >At any rate, I think that your son has a case to be
    >made here.  I'm sure that the teacher was intending to
Again, I agree here.  I wonder if the teacher didn't understand the
question he/she was asking or was a Microsoft compiler involved.
Microsloth did manage to mangle the Java language while still calling
it Java.
A copy of the standard Java definition should be presented to the
teacher.
Steve, please correct your son's teacher!
	-Rusty-
P.S.  Teachers are NOT infallible.  I once took an exam to skip FORTRAN
programming in an introductory engineering class (IN COLLEGE no less)
because I had had the subject in high school and I was quite good at it.
I changed my grade on that exam from 82% to a 96% simply by showing the
"correct" answers were wrong and had the answer key corrected in about 5
or 6 different places.  I was an incoming freshman at the time straight
out of high school.  I would have gotten a 100% but I had forgotten
to slash my zeroes in two answers (as I had done with the rest of my
answers).  :-(
-- 
   _____         Rusty Haddock  =  AE5AE  =  rusty at fe2o3.lonestar.org
|\/   o \   o  **Out yonder in the Van Alstyne (TX) Metropolitan Area**
|   (  -<  O o     Every day I think people can't get more stupid.
|/\__V__/               Every day I'm proven horribly wrong.
    
    
More information about the Discuss
mailing list