This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reg Character Literals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Reg Character Literals" Watch "Reg Character Literals" New topic
Author

Reg Character Literals

Vishnu Munnangi
Ranch Hand

Joined: Sep 28, 2004
Posts: 114
Hi Everyone,

This is a question from one of the mock exams.
please go through the code...

Which character(s) will be correctly declared and initialized?
(Select two correct answers)

public class Test002 extends Super
{
public static void main(String args[])
{
char c1 = '\u00AA';
char c2 = '\u00DD';
char c3 = '\u000D';
char c4 = '\u000A';
}
}

class Super
{
final void m() { }
}

A: c1 and c2.
B: c3 and c4.
C: only A is correct.
D: only B is correct.
Answers given are A,C.

My question is whether we have to remember character literals for escape sequences for the SCJP exam.
I know that escape sequences are '\b', '\f', '\n','\r','\t','\\','\'','\"'.
Is that all sufficient or we need to remember their literal representation too.
That is '\u000A' is for new line
and '\u000D' is for return etc.,

Thanks in Advance.
Gurpreet Singh
Ranch Hand

Joined: Oct 05, 2004
Posts: 34
Vishnu, along with escape sequences you mentioned, you do only need to remember that '\u000A' and '\u000D' cannot be correctly used as characters, better use \n \r in place of them. That's it.

I suggest you go through this test :
www.danchisholm.net\july21\topic\section4\literals1.html
[ October 19, 2004: Message edited by: Gurpreet Singh ]
sashi balu
Greenhorn

Joined: Jul 23, 2004
Posts: 16
Dan had the foll. tip(or rather phrase) to remember the escape sequences apart from '\\','\'','\"',

"B"ig "F"arms "N"eed "R"ed "T"ractors ( '\b', '\f', '\n','\r','\t').

Hope that helps
Sashi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reg Character Literals
 
Similar Threads
Unicode Characters
char assignments
Garbage Collection Qstn from K&B Doubt
how many objects will be eligible for garbage collection
Valid char values!