title: Java String vs. Command Line Argument
body: <p>Why does it happen that a command line argument passed to a Java class seems to be automagically escaped while in an instantiated String object the escape character () is seemingly ignored.</p>
  
  <p>For example, if start with a string like this:</p>
  
  <pre><code>SELECT * FROM my_table WHERE my_col like 'ABC_\' ESCAPE '\'
  </code></pre>
  
  <p>And I try running it through a simple class like this:</p>
  
  <pre><code>public class EscapeTest {
      public static void main (String[] args) {
          String str = "SELECT * FROM my_table WHERE " 
                       + "my_col like 'ABC_\' ESCAPE '\'";
          System.out.println("ARGS[0]: "+args[0]);
          System.out.println("STR: "+str);
  }
  }
  </code></pre>
  
  <p>and I pass the "SELECT" statement above in as a command line arg, I get output that looks like this:</p>
  
  <pre><code>ARGS[0]: SELECT * FROM my_table WHERE my_col like 'ABC_\' ESCAPE '\'
  
  STR: SELECT * FROM my_table WHERE my_col like 'ABC_' ESCAPE ''
  </code></pre>
  
  <p>If I look at the value of ARGS[0] in the Eclipse debugger I see that the slashes are escaped. Why does this happen? Makes it kind of hard to predict I think. </p>