aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Few Tough questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Few Tough questions" Watch "Few Tough questions" New topic
Author

Few Tough questions

Sandeep Lodhia
Ranch Hand

Joined: Oct 09, 2000
Posts: 105
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
aymen esawey
Ranch Hand

Joined: Jan 29, 2002
Posts: 61
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.


Aymen Esawey<br />SCJP <img src="smile.gif" border="0"> <br /><a href="http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=32&t=001968" target="_blank" rel="nofollow">how to nuke the SUN </a>
Jamal Hasanov
Ranch Hand

Joined: Jan 08, 2002
Posts: 411
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

Joined: Oct 09, 2000
Posts: 105
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 ]
Nazmul Huda Sarkar
Ranch Hand

Joined: Feb 01, 2002
Posts: 317
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....


Nazmul<br />SCJP,SCWCD,IBM OOAD with UML
 
 
subject: Few Tough questions