A right
a text-output stream.
automatic flushing is enabled
B. fail
it can have registered shutdown hooks (threads)
C password is not encrypted it just suppresses echoing, so the password is not visible on the user's screen.
D. Fail
a text-output stream.
A. PrintWriter: It is used for writing text data to a character stream. It automatically flushes the stream after writing, ensuring that the data is immediately sent to the output destination.
PrintWriter has methods that allow character output. Additionally, PrintWriter has an option for auto-flushing that can be enabled in the builder. When enabled, certain write and println methods will automatically flush the output buffer.
The correct answer is A. PrintWriter outputs characters and automatically flushes the stream. Explanation: A. PrintWriter is a class in Java that outputs characters to an output stream and automatically flushes the stream when a newline character is written, when the println method is invoked, or when a carriage return character is written. B. System.exit() does not invoke the close() method for the InputStream/OutputStream resources. It terminates the currently running Java Virtual Machine (JVM). It's the responsibility of your code to close streams before exiting. C. Console.readPassword() does not encrypt the text entered. It simply disables echoing, so the password is not displayed on the console when it's entered. D. PrintStream does not output only bytes. It can output all primitive data types and strings using its print and println methods.
I would vote for D. Because it is fact: "All characters printed by a PrintStream are converted into bytes using the platform's default character encoding."
As regards A: "... if automatic flushing is enabled ..." so it is not true always. B is not true. So I vote for C - Tested (https://www.geeksforgeeks.org/console-readpassword-method-in-java-with-examples/).
I find this a rather tricky one because and would like to know the answer.
So what I found is that a PrintWriter doesn't automatically flushes the stream, it does however have a constructor accepting a boolean to ENABLE autoflushing..
for D.. I found this in the oracle docs: All characters printed by a PrintStream are converted into bytes using the platform's default character encoding. The PrintWriter class should be used in situations that require writing characters rather than bytes.
So it's either A or D
It has a constructor that can take an OutputStream as an argument, and an optional second argument that specifies whether the stream should be automatically flushed when println is called. This means that the data is immediately written to the underlying output stream, instead of being buffered.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
1 month, 3 weeks agocathDev
3 months agod7bb0b2
6 months agod7bb0b2
7 months agoOmnisumem
9 months, 1 week agoOmnisumem
9 months, 1 week ago[Removed]
10 months, 2 weeks ago[Removed]
10 months, 2 weeks agoStavok
11 months, 3 weeks agobelal97
12 months ago