Page 1 of 1

About Question enthuware.ocpjp.v7.2.1286 :

Posted: Wed Jul 01, 2015 3:29 pm
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?

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

Posted: Wed Jul 01, 2015 9:08 pm
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.

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

Posted: Thu Jul 02, 2015 11:31 am
by leorbarbosa
This sounds a little confuse to me.
But okay....! Thanks!

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

Posted: Wed Jan 27, 2016 11:53 am
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.

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

Posted: Wed Jan 27, 2016 1:49 pm
by admin
Those are incorrect options and this is one of the reasons.
HTH,
Paul.

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

Posted: Sun Mar 20, 2016 4:53 am
by sumanenthu
Why option1 is not correct? where it's being explicitly said that the standard input and output streams are redirected to console..

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

Posted: Sun Mar 20, 2016 9:03 am
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.

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

Posted: Sun Mar 20, 2016 9:09 am
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.

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

Posted: Sun Mar 20, 2016 9:13 pm
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

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

Posted: Sun Mar 20, 2016 11:24 pm
by sumanenthu
So according to your explanation above both answers 1 and 2 seems to be correct to me.

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

Posted: Mon Mar 21, 2016 4:33 am
by admin
Why do you think option 1 is correct?

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

Posted: Mon Mar 21, 2016 11:30 pm
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?

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

Posted: Mon Mar 21, 2016 11:40 pm
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.

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

Posted: Tue Mar 22, 2016 12:08 am
by sumanenthu
Thanks for clearing the doubt. One thing you said 'Updated'. Means where?

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

Posted: Tue Mar 22, 2016 12:14 am
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) .