• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Few Tough questions

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
Pls help me in this.
1. byte a = 10;
a= a+1 ;
This will give compile error.Great !!!
Where as
a+=1;
This does not give error ???

2. //char a = '\u000A'; This will give compile error.Again Great !!!
Where as
//char a = '\u0001';
This does not give error ???

Any logical ans for these?
Sandeep
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. the result is int and must be cast
. auto conversion takes place with +=,*=.....
2.unicode char \u000a is translated by the compiler into a linefeed first thing before compilation so the result is:
1. char c='
2. ';
missing terminator on line one.
hope am right.
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sandeep,
1. byte b=1;
b= b+1;
//In this case b implicitly converted into int
//and the result of right side calculation is
//int. That's why you'll get an error. You can
//do following
b= (byte)(b+1);
b+=1
// In this case Java does conversion to int.
That's all.
2. '\u000A' is a "carriage return" in java. You
cannot use '\u000D' as well. Please search
forums, in this site, youl get a lot of topics
devoted this.
Thanx,
Jam
 
Sandeep Lodhia
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good replies Guys !!! Thanx
But my point in 2nd question is... even though the line is commented, still it gives compilation error.
Pls elaborate.
[ March 13, 2002: Message edited by: Sandeep Lodhia ]
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sandeep
When u compile any Java program and if this code contains any unicode literal then before compilation those unicode literal first converted to ASCII (or machine default) character literal. so before compilation of
1. //char a= '\u000A'; will be translated to
1. //char a='
2. ';

so during compilation line 2 will give compile time error.
Hope this will help u....
 
reply
    Bookmark Topic Watch Topic
  • New Topic