This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes dan exam dought Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "dan exam dought" Watch "dan exam dought" New topic

dan exam dought

amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 812
in one of the question

Question 6
class MCZ17 {
public static void main (String[] args) {
String a = "\n"; // 1
String b = "\r"; // 2
String c = "\u000a"; // 3 \u000a = new line
String d = "\u000d"; // 4 \u000d = return

Compile-time errors are generated at which lines?

a. 1
b. 2
c. 3
d. 4

its answer is c,d


The compiler interprets \u000a as a line terminator. The escape sequence \n should be used instead. Similarly, \u000d is interpreted as a line terminator. The escape sequence \r should be used instead.

i didn't get what he means by line terminator ?
is \n escape sequence is not the same thing as line terminator

please explain in details

thanx and regards,

Thanks and Regards, Amit Taneja
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 951

\u000d or \u000c are Unicode escapes. These are useful in the Java code when you can not express the characters in ASCII format in Java Source. As the Jav compiler translated it into there actual Unocode before compiling the code, The use of these codes in string or character constants are invalid. ( Becalues these code actualy place newline in the source, thus break the String in two lines).

I hope this will help


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 812
pls expain in details ...if possible...

please didn't get in some question...
values in string like
String a= "'\u0003'" is right

i don't know why

pls explain... here also unicode is included
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Did you try to compile it and look at the errors?

C:\_Work\java>javac unclosed string literal
String c = "\u000a"; // 3 \u000a = new line
^ unclosed string literal
String d = "\u000d"; // 4 \u000d = return
^ unclosed string literal
^ unclosed string literal
^ ';' expected
5 errors

If this represents a new line:

I guess it could be written like this for comparison
It is sorta covered in the JavaRanch Style Guide.
subject: dan exam dought
It's not a secret anymore!