About Question enthuware.ocpjp.v7.2.1286 :
Moderators: Site Manager, fjwalraven
-
- Posts: 17
- Joined: Wed Nov 26, 2014 1:59 pm
- Contact:
About Question enthuware.ocpjp.v7.2.1286 :
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?
"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?
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
This statement is taken from JavaDoc API description of Console: http://docs.oracle.com/javase/7/docs/ap ... nsole.html
HTH,
Paul.
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.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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 17
- Joined: Wed Nov 26, 2014 1:59 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
This sounds a little confuse to me.
But okay....! Thanks!
But okay....! Thanks!
-
- Posts: 38
- Joined: Fri Nov 13, 2015 4:40 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
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.
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
Those are incorrect options and this is one of the reasons.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 23
- Joined: Sun Feb 21, 2016 10:12 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
Why option1 is not correct? where it's being explicitly said that the standard input and output streams are redirected to console..
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
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.
-
- Posts: 23
- Joined: Sun Feb 21, 2016 10:12 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
And what if I do explicitly? I wonder if such method actually exists.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.
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
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
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.
-
- Posts: 23
- Joined: Sun Feb 21, 2016 10:12 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
So according to your explanation above both answers 1 and 2 seems to be correct to me.
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
Why do you think option 1 is correct?
If you like our products and services, please help us by posting your review here.
-
- Posts: 23
- Joined: Sun Feb 21, 2016 10:12 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
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?
Console cl = System.console(); Will it return null for option 1?
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
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.
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.
-
- Posts: 23
- Joined: Sun Feb 21, 2016 10:12 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
Thanks for clearing the doubt. One thing you said 'Updated'. Means where?
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1286 :
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.
Who is online
Users browsing this forum: No registered users and 77 guests