• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Illegal Escape Character

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,

I have a problem to understand this case :

import java.util.regex.*;



Compilation should be failed at line 7 because the presence of an Illegal escape character.
But if i change the program :

...
Pattern p = Pattern.compile(args[0]);
...

then i run the application by invoking command line :

java Regex "\d"

the application runs successfully, but actually i expect the compilation failed at line 7. Someone please explain this to me.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ July 14, 2008: Message edited by: sargunan Rswamy ]
 
Sargunan Rswamy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try This





import java.util.regex.*;


[ July 14, 2008: Message edited by: sargunan Rswamy ]
 
Faber Siagian
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't see the reply
 
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your program is working fine!
You were expecting a RunTime Exception but your JVM decided that it was ok to go by a single \
Please note that this behaviour is not guaranteed in all JVMs.
For more, please see pg. 482 of k&b scjp 5 study guide.
Also as mentioned there, the command-line behaviour is not in the exam
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Faber ,

You have to make only one change if you are running this program
on Windows.

<blockquote>code:
<pre name="code" class="core">
Pattern p = Pattern.compile("\\d");
</pre>
</blockquote>
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic