Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

K&B book, page 503 q9

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
I took a stab at question 9 on page 503 of K&B SCJP 5
book. I guessed incorrectly and noticed that
one of the correct answers is G.
I dont really understand what is happening here.
I would have imagined that the Integer object would be unboxed
to an int...
Can someone be so kind as to elaborate on why G. is a correct answer?
Thank you & regards.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Keith, can you please provide the question and possible answers? I don't have a copy of the book handy.
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
G is correct because when you pass new Long("123"), System.out.format evaluates new Long("123").toString()

Remember:
%s
if argument is null, result is null.
if argument is a primitive type , result=primitive
if argument is a string, result=string
if argument is an object, result=object.toString().
 
Keith Nagle
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that concise answer Antonio.
Much appreciated.

Originally posted by Noam Wolf:
Hi Keith, can you please provide the question and possible answers? I don't have a copy of the book handy.



Sorry Noam, but Im not going to post copyrighted material
in the forums. If you haven't already bought the book,
you should, if you can. Check out Amazon. It's a great book
and would definitely benefit you in your studies.
best regards & good luck.
 
author
Posts: 9031
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

The general policy at the ranch is that it's okay to post mock exam questions as long as you cite the source of the question. So in this case it would have been fine to say: "Here's a question from K&B..."

It's also fine to quote small sections from books. I'd say that most authors are really happy if you're discussing their books, as long as you got your copy legally

hth,

Bert
 
Keith Nagle
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Duly noted Bert.
Thanks for a great publication and keep up the good work!
best regards.
K

Here's the pertinent question Noam,
from the K&B SCJP 5 book:
Which will compile and run without Exception? (Choose all that apply.)
A. System.out.format("%b", 123);
B. System.out.format("%c", "x");
C. System.out.printf("%d", 123);
D. System.out.printf("%f", 123);
E. System.out.printf("%d", 123.45);
F. System.out.printf("%f", 123.45);
G. System.out.format("%s", new Long("123"));
[ June 22, 2008: Message edited by: Keith Nagle ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic