• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

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>
 
Arthur, where are your pants? Check under this tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic