This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Are compilation error on comments part of OCAJP exam?

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider this code :

class Fizz {
public static void main(String[] args) {
char u='\u0000';
//StringB\uilder b = new StringBuilder("abcd");

}

}

At first, the code looks fine. But you get compilation error "Invalid unicode" on the comment which line 4.
My question is should we expect this kind of problem in the actual exam? Thanks in advance :-)
 
Greenhorn
Posts: 13
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I learned something new today. Unicode characters are interpreted even if it is within comments early in the compilation Comments in Java so the \u in StringBuilder throws an error. Thanks for putting out an example like this. I had never considered this type of compilation error before. As for whether they are on the exam, sorry, I can't answer that question.
 
Marshal
Posts: 6971
471
Mac OS X VI Editor BSD Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Neha Agnihotri wrote:My question is should we expect this kind of problem in the actual exam?


No.

The very first time I got to know this when read book Java Puzzlers by Joshua Bloch and Neal Gafter, about 3 years ago, when Campbell told me to read that book.

Such type of question might be a good one as for a party trick, but wouldn't be funny at all even in OCAJP, while there you could find some quite fun stuff.
 
Neha Agnihotri
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great! That’s some relief.
Yes, I too found that book amazing.
Thanks for your reply :-)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!