Page 1 of 1

[HD Pg 48, Sec. 2.5.2 - command-line-arguments]

Posted: Thu Dec 27, 2018 4:09 pm
by OCAJO1
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?

Re: [HD Pg 48, Sec. 2.5.2 - command-line-arguments]

Posted: Thu Dec 27, 2018 9:46 pm
by admin
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:

Code: Select all

C:\temp>java TestClass "\""
args[0] = """
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.

Re: [HD Pg 48, Sec. 2.5.2 - command-line-arguments]

Posted: Fri Dec 28, 2018 6:18 pm
by OCAJO1
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!

Re: [HD Pg 48, Sec. 2.5.2 - command-line-arguments]

Posted: Wed Jan 02, 2019 8:28 pm
by OCAJO1
Happy New year :cheers:

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!