Table 2.5 page 49, last entry.
java TestClass "\"" args[0] = """ To pass a quote character as an argument, you have to escape it using a backslash.
I tried it, and got compiler error - unbalanced quotes. Also tried \", got the same error.
Tried "\'" (backslash and single quote within two double quotes) and got \'! Also tried \r and "\r" and both resulted in \r!
So doesn't look like back slash inside double quotes or outside, has any meaning to the compiler as it takes in arguments to main()!
What happened?
[HD Pg 48, Sec. 2.5.2 - command-line-arguments]
Moderator: admin
-
- Posts: 221
- Joined: Mon Nov 26, 2018 2:43 pm
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 48, Sec. 2.5.2 - command-line-arguments]
You are doing something wrong or something different from what is given in the book. I ran the code as given in the book got the expected output:
I am guessing that you are trying to set the args array in the code because you are running from NetBeans. As I have said before, you should not use an IDE at this stage
You will only waste your time chasing ghosts.
Code: Select all
C:\temp>java TestClass "\""
args[0] = """

-
- Posts: 221
- Joined: Mon Nov 26, 2018 2:43 pm
- Contact:
Re: [HD Pg 48, Sec. 2.5.2 - command-line-arguments]
That is strange. I ran it both from command line as well as netbeans' argument line. Both caused the same compiler error. I'll look at the actual code, maybe something funny crept in there!
-
- Posts: 221
- Joined: Mon Nov 26, 2018 2:43 pm
- Contact:
Re: [HD Pg 48, Sec. 2.5.2 - command-line-arguments]
Happy New year
I looked at this again. The command line accepts "\"", but for some - who knows why - reason, netbeans' argument input line has to have '\"' (\" within two single quotes) so it would not cause an unbalanced quotes complier error!

I looked at this again. The command line accepts "\"", but for some - who knows why - reason, netbeans' argument input line has to have '\"' (\" within two single quotes) so it would not cause an unbalanced quotes complier error!
Who is online
Users browsing this forum: Google [Bot] and 6 guests