This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes help regarding escape character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help regarding escape character" Watch "help regarding escape character" New topic

help regarding escape character

Venu Chakravorty
Ranch Hand

Joined: Aug 19, 2009
Posts: 46
i get a compile time error upon compiling:

perhaps because "\d" is not an escape character, where as in the next code:

"/d" gets printed when i invoke - java A "\d".
in the later case doesn't the String "\d" get assigned to "args[0]"? or maybe i am getting no error because i am trying to assign a value at runtime?

regards, venu
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
The values passed to the program are escaped by the JVM ...

JDBCSupport - An easy to use, light-weight JDBC framework -
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

The only thing that's relevant here is that to write an actual '\' character inside a String in Java source code, you must double it:

args[0] = "\\d";

The same goes for character constants:

char c = '\\';

There's no "escaping" of characters read from the command line or from files; a \ is just an ordinary character at runtime. Escaping is just used to turn off the special meaning of the \ character in source code.

[Jess in Action][AskingGoodQuestions]
Venu Chakravorty
Ranch Hand

Joined: Aug 19, 2009
Posts: 46
I agree. Here's the link:
subject: help regarding escape character
It's not a secret anymore!