Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6166473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:20:42+00:00 2026-05-23T22:20:42+00:00

Why does it happen that a command line argument passed to a Java class

  • 0

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.

For example, if start with a string like this:

SELECT * FROM my_table WHERE my_col like 'ABC_\' ESCAPE '\'

And I try running it through a simple class like this:

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);
}
}

and I pass the “SELECT” statement above in as a command line arg, I get output that looks like this:

ARGS[0]: SELECT * FROM my_table WHERE my_col like 'ABC_\' ESCAPE '\'

STR: SELECT * FROM my_table WHERE my_col like 'ABC_' ESCAPE ''

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:20:43+00:00Added an answer on May 23, 2026 at 10:20 pm

    The contents of your string str does not contain any backslashes. Those are being handled by the Java compiler understanding the escape sequences of Java string literals.

    The command line processor presumably isn’t doing that – it’s not treating backslash specially in any way, although this will depend on your shell. (In most Unix shells it would treat backslash differently. My guess is that you’re on Windows.)

    So, your command line argument does have backslashes in. They haven’t been escaped by the executing Java process – they’re just “there” in the string.

    Now it sounds like the debugger is escaping the string when it’s displaying it to you, so that you can see things like tabs and newlines. It’s important to understand that this is just the way the debugger displays the string – there’s no such thing as an “escape” within a Java string itself.

    EDIT: As per comment:

    To express this string in Java source code, you have to escape the backslashes:

    String str = "SELECT * FROM my_table WHERE my_col like 'ABC_\\' ESCAPE '\\'"; 
    

    Backslashes have to be escaped as backslash is the escape character in Java string literals.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone happen to have some sort of a nice command line script they
Does anyone happen to remember the function name used to generate sequential row number
Does anyone happen to know if there is a token I can add to
Does anyone happen to know what the maximum length of a method name is
If I use mod_rewrite to control all my 301 redirects, does this happen before
Does the Java language have delegate features, similar to how C# has support for
We have a java program that requires a large amount of heap space -
Does anyone know? And a bigger question is what happens when you encounter this
How many messages does the queue for a standard window hold? What happens when
Does Google force employees who have offers from Facebook to leave immediately?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.