About Question enthuware.ocajp.i.v8.2.2017 :

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

Moderator: admin

Post Reply
VijayTripathi
Posts: 8
Joined: Mon Jul 06, 2020 1:11 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.2017 :

Post by VijayTripathi »

For char, the print/println methods translate the character into one or more bytes according to the platform's default character encoding. That is why while printing a char value of 0, a blank space is printed instead of 0 (even though the char's integral value is 0).

Can you please elaborate this. Unable to understand the mystry.

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

Re: About Question enthuware.ocajp.i.v8.2.2017 :

Post by admin »

Not really sure which part you don't understand. Like the ascii value of 'a' is 97, so, if you try to print a char variable containing 97, a will be printed. Similarly, whatever character is represented by value 0, that is printed (it is just a blank character).
If you like our products and services, please help us by posting your review here.

VijayTripathi
Posts: 8
Joined: Mon Jul 06, 2020 1:11 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.2017 :

Post by VijayTripathi »

admin wrote:
Sat Aug 01, 2020 11:08 am
Not really sure which part you don't understand. Like the ascii value of 'a' is 97, so, if you try to print a char variable containing 97, a will be printed. Similarly, whatever character is represented by value 0, that is printed (it is just a blank character).
So, though 0 don't have any character representation that's why it is printing space. Thanks for the explanation.

ignore.your
Posts: 3
Joined: Thu Dec 23, 2021 5:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.2017 :

Post by ignore.your »

Well, the correct answer for any operating system would be: "none of the above"

(char)0 is ascii NUL. How this is printed depends on the operating system shell.

On Linux it could be (char)32, "0" or even "\bf". So #2 and #3 could be correct answers as well.

E.g.: Emacs prints the NUL as ^@. And the last statement is a print, not a println, so actual the output from an Emacs shell window would be:

0.0 ^@ false------------------------------

:D

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

Re: About Question enthuware.ocajp.i.v8.2.2017 :

Post by admin »

No, what you are taking about is how programming environments use the value 0. For eg. 0 may be used to represent a null reference.
But is not what this question is about. It is very clearly creating a java char variable containing a value zero and how it is printed. The integral value of a char is represented as a character based on the default character encoding of the platform on which the JVM is running. So, the given answer and explanation are correct.
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 33 guests