• 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
  • Tim Cooke
  • Ron McLeod
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Java Puzzlers - 'Hello Whirled' challenge

 
Marshal
Posts: 6198
501
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just for fun, here's a little challenge from the book. (if you have the book, no cheating)

Take the following code, and tell me what does it print?
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It initially looked it would print "Hello world". But then I copied the code and when I tried to compile it, I realised the error! Interesting find.
 
Ranch Hand
Posts: 50
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I too guessed output to be Hello world, and then to check my answer, tried to copy the code and run. Unfortunately, I copied only the code part (without comment), so it worked perfectly for me :P . I had to look up the answer in the book to find out what am I missing.
 
Tim Cooke
Marshal
Posts: 6198
501
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It was a real devil this one I thought.

For the benefit of everyone else, the twist in this code was the fact that the compiler was attempting to interpret some UniCode value in the comment block when it encountered a \u pattern. So in the comment line:

from F:\TestRoot\apps\a1\units\include\PolicyHome.idl

The Java Compiler is attempting to resolve "\units" as Unicode, which it is not, so fails.
 
Marshal
Posts: 81608
593
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree; if you miss out that documentation comment you do indeed get Hello world.
 
That new kid is a freak. Show him this tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic