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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post 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!

OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post 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!

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests