• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Are compilation error on comments part of OCAJP exam?

 
Greenhorn
Posts: 20
  • 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: 6851
470
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
Greenhorn
Posts: 20
  • 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!