File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "dan exam dought" Watch "dan exam dought" New topic
Author

dan exam dought

amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
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

because

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,
amit


Thanks and Regards, Amit Taneja
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hello,

\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

Thanks.


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: 810
pls expain in details ...if possible...

please didn't get it...as 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
drifter
Ranch Hand

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

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


If this represents a new line:

I guess it could be written like this for comparison
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: dan exam dought
 
Similar Threads
About hex formats
doubt in Literals
confused with new line and unicode
why does java give an error in the comment?
interesting problem in char