About Question enthuware.ocpjp.v7.2.1286 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
leorbarbosa
Posts: 17
Joined: Wed Nov 26, 2014 1:59 pm
Contact:

About Question enthuware.ocpjp.v7.2.1286 :

Post by leorbarbosa »

I could not understand when the answer says:
"without redirecting the standard input and output streams."

See that the word “console” here refers to the character input device (typically a keyboard), and the character display device (typically the screen display).

What is wrong?

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

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by admin »

This statement is taken from JavaDoc API description of Console: http://docs.oracle.com/javase/7/docs/ap ... nsole.html
If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and will typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console.
It implies that it is possible to have a "console" in some cases even if the program is not connected to a keyboard and display.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

leorbarbosa
Posts: 17
Joined: Wed Nov 26, 2014 1:59 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by leorbarbosa »

This sounds a little confuse to me.
But okay....! Thanks!

toolforger
Posts: 38
Joined: Fri Nov 13, 2015 4:40 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by toolforger »

Then the answers should refer to the console by saying "redirect to the console" instead of "redirect to Console": Without "the" and with an uppercase letter, this sounds like it means the Console class, not the console the user is viewing.

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

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by admin »

Those are incorrect options and this is one of the reasons.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

sumanenthu
Posts: 23
Joined: Sun Feb 21, 2016 10:12 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by sumanenthu »

Why option1 is not correct? where it's being explicitly said that the standard input and output streams are redirected to console..

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

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by admin »

When you run a java program from the command line, you don't have to redirect the stream to console. They are already directed to the console by default.
If you like our products and services, please help us by posting your review here.

sumanenthu
Posts: 23
Joined: Sun Feb 21, 2016 10:12 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by sumanenthu »

admin wrote:When you run a java program from the command line, you don't have to redirect the stream to console. They are already directed to the console by default.
And what if I do explicitly? I wonder if such method actually exists.

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

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by admin »

Of course, you can redirect the streams in your program. For example, if you want to redirect console output to a file, you can do:
PrintStream out = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);
Or just run the program like this:
java MyClass >output.txt
If you like our products and services, please help us by posting your review here.

sumanenthu
Posts: 23
Joined: Sun Feb 21, 2016 10:12 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by sumanenthu »

So according to your explanation above both answers 1 and 2 seems to be correct to me.

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

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by admin »

Why do you think option 1 is correct?
If you like our products and services, please help us by posting your review here.

sumanenthu
Posts: 23
Joined: Sun Feb 21, 2016 10:12 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by sumanenthu »

The option 1 says that the the standard input and output streams are explicitly redirected to console. And you said that its certainly possible. So, why can't I aquire Console then to write or print something?

Console cl = System.console(); Will it return null for option 1?

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

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by admin »

Ok, I see what you mean.
There are two options - one says without redirecting the streams and another one says with redirecting the streams.
Since you have to select only one option, option 2 is most appropriate.

But I agree that this is not very good. Updated.
thank you for your feedback.
Paul.
If you like our products and services, please help us by posting your review here.

sumanenthu
Posts: 23
Joined: Sun Feb 21, 2016 10:12 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by sumanenthu »

Thanks for clearing the doubt. One thing you said 'Updated'. Means where?

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

Re: About Question enthuware.ocpjp.v7.2.1286 :

Post by admin »

Updated in the question bank. It will be visible in the production version of the question bank soon (in a couple of days) .
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests