About Question enthuware.ocajp.i.v8.2.1225

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

Moderator: admin

Post Reply
petzchen
Posts: 2
Joined: Sun Dec 04, 2016 1:31 am
Contact:

About Question enthuware.ocajp.i.v8.2.1225

Post by petzchen »

Hi,

the question item enthuware.ocajp.i.v8.2.1225 seems not correct.

The Option: "It throws StringIndexOutOfBoundsException if passed a value higher than or equal to the length of the string (or less than 0)." is a valid option.
The Java Docs (https://docs.oracle.com/javase/8/docs/api/) are not precise here. A StringIndexOutOfBoundsException will be thrown beside the fact that its base class is
of IndexOutOfBoundsException.

Anyway, the more specific solution (Option with StringIndexOutOfBoundsException) is treated as an error here, despite the fact that it is correct.

I am using Java 1.8.0_60 and checked also the jdk sources of the String class. Question Bank version is 1/44.

Maybe I missed something or the issue has been reported already. In that case I say "Sorry" for bothering you.

Happy day
STephan

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

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

Post by admin »

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

petzchen
Posts: 2
Joined: Sun Dec 04, 2016 1:31 am
Contact:

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

Post by petzchen »

Appreciate your feedback. Thanks.

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

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

Post by VijayTripathi »

The Question is asking about if we can pass a char to charAt(). Now as per the information given by you it can, but till the compilation level. If it is the case can you please tell me what happens in the background if the statement is written as "Make it to 65 characters".charAt('A');

Is this tries to convert it into its ASCII value and search for the index position of the ASCII value? or something else!
Thanks in advance!

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

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

Post by admin »

Well, a char is an integral data type. So, you can pass 'A' to charAt. Integral value of 'A' i.e. 65 will be passed. It will be like calling charAt(65).
You can try printing the value of i after this statement and see what happens:
int i = 'A';
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.1225

Post by VijayTripathi »

Yes, I have tried this but even after having string value length as 104. I am getting this error.
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 104(Still why?)
The tested code is:
char checkChar = "This is a string of length 104".charAt('A');

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

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

Post by admin »

As mentioned above, charAt('A') is same as charAt(65). Do you have more than 65 characters in your string "This is a string of length 104" ? What do you think the character at index 65 is in your string?
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.1225

Post by VijayTripathi »

admin wrote:
Tue Jul 07, 2020 12:59 am
As mentioned above, charAt('A') is same as charAt(65). Do you have more than 65 characters in your string "This is a string of length 104" ? What do you think the character at index 65 is in your string?
you are right. Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests