Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Comment Statement

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

this is question 28 from Abhilash java quiz

public class ADirtyOne
{
//char a = '\u000A';
}
An attempt to compile the above class
1.will complete successfully.
2.will compile sucessfully but with a warning message.
3.will not compile - complains on an invalid expression.

I think the answer is 1.But the given answer is 3. I tried to compile the code, and itz showing the error.When // used for commenting, it comments the entire statement next to it right? Then why is the compiler showing the errror?

Thankz for the reply.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you notice the unicode character, I believe it is LF, hence it interprets it as:
//char a = '
';

Therefore the error
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try our SCJP FAQ
 
usha prithvi
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Barry,

From the link provided I understood that char A = '\u000A'; gives compiler error. But in the code written //char A = '\u000A; the line should be ignored since // is present. Still, why does the compiler shows an error? PLease explain.

Thankz
[ July 14, 2005: Message edited by: usha prithvi ]
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class ADirtyOne
{
//char a = '\u000A';
}

what happens is that the unicode character '\u000A' is for a new line.
So when the compiler compiles the line it takes the character to the new line which is uncommented , because of which we get the compile time error

others please clarify

regards ,
bhavesh
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unicode escape sequences such as \u000A are parsed by the compiler and converted to their Unicode character equivalents before the source code is parsed for comments. So by the time the compiler gets around to evaluating which lines are commented out, the code has already been interpreted as

 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On a related note with attached explanation:
http://qa.jtiger.org/GetQAndA.action?qids=5
and
http://qa.jtiger.org/GetQAndA.action?qids=8
 
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic