About Question enthuware.ocajp.i.v7.2.852 :
Moderator: admin
About Question enthuware.ocajp.i.v7.2.852 :
Hey guys, this question says that this statement: System.out.println("12345".charAt(6)); does not throws the StringIndexOutOfBoundException, but when you try to run it, actually it throws. So what's the correct answer for this one?
Thanks
Thanks
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
Hi,
Did you read the detailed explanation provided with the answer. It explains why that option is not correct.
Further, the explanation does not say that it does not throw StringIndexOutOfBoundsException.
HTH,
Paul.
Did you read the detailed explanation provided with the answer. It explains why that option is not correct.
Further, the explanation does not say that it does not throw StringIndexOutOfBoundsException.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
Re: About Question enthuware.ocajp.i.v7.2.852 :
Under the answer:
It will throw StringOutOfBoundsException.
There is no such exception. The correct name is StringIndexOutOfBoundsException. But that is also not the correct answer
StringIndexOutOfBoundsException should be the correct answer when compiled. Why does it say that it is not?
Thank you.
It will throw StringOutOfBoundsException.
There is no such exception. The correct name is StringIndexOutOfBoundsException. But that is also not the correct answer
StringIndexOutOfBoundsException should be the correct answer when compiled. Why does it say that it is not?
Thank you.
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
As per the API documentation of this method ( http://docs.oracle.com/javase/6/docs/ap ... harAt(int) ), this method throws IndexOutOfBoundsException. Although, in practice the method throws StringIndexOutOfBoundsException, which is a subclass of IndexOutOfBoundsException, the implementation is free to throw some other subclass of IndexOutOfBoundsException. Thus, you should rely only on the published API documentation instead of what it actually throws.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
Re: About Question enthuware.ocajp.i.v7.2.852 :
The answer of "It will throw a StringOutOfBoundsException" option is wrong for sure
It says:
"There is no such exception. The correct name is StringIndexOutOfBoundsException. But that is also not the correct answer."
It should be:
"There is no such exception. The correct name is StringIndexOutOfBoundsException. If the option would be StringIndexOutOfBoundsException then then this option would be the correct answer"
It does not matter what API documentation says. People are reading what the question asks and the question is:
"What will the following code print?" and not "What kind of exception will be thorwn?"
So for sure the code in this question will not print a "IndexOutOfBoundsException".
It says:
"There is no such exception. The correct name is StringIndexOutOfBoundsException. But that is also not the correct answer."
It should be:
"There is no such exception. The correct name is StringIndexOutOfBoundsException. If the option would be StringIndexOutOfBoundsException then then this option would be the correct answer"
It does not matter what API documentation says. People are reading what the question asks and the question is:
"What will the following code print?" and not "What kind of exception will be thorwn?"
So for sure the code in this question will not print a "IndexOutOfBoundsException".
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
xvitcoder wrote:The answer of "It will throw a StringOutOfBoundsException" option is wrong for sure
It says:
"There is no such exception. The correct name is StringIndexOutOfBoundsException. But that is also not the correct answer."
It should be:
"There is no such exception. The correct name is StringIndexOutOfBoundsException. If the option would be StringIndexOutOfBoundsException then then this option would be the correct answer"
It does not matter what API documentation says. People are reading what the question asks and the question is:
"What will the following code print?" and not "What kind of exception will be thorwn?"
So for sure the code in this question will not print a "IndexOutOfBoundsException".
1. None of the options says it will print StringIndexOutOfBoundsException.
2. "StringIndexOutOfBoundsException" is not printed because of System.out.println("12345".charAt(6));.
3. In fact, the statement System.out.println("12345".charAt(6)); prints nothing. This statement just throws a StringIndexOutOfBoundsException. But as explained in the explanation you cannot rely on the fact that it will throw StringIndexOutOfBoundsException because the API says it throws IndexOutOfBoundsException.
In other words, the given statement does NOT print StringIndexOutOfBoundsException. It throws IndexOutOfBoundsException, which is the correct answer.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 9
- Joined: Sun Oct 28, 2012 8:17 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
I think the folks at Oracle either need to fix their documentation or change their code.
-- Robert
-- Robert
-
- Posts: 7
- Joined: Mon Jan 27, 2014 6:25 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
in practice, I've met that 6th's versions of Java on Macs and Wins are different.
despite any documentation.
so the more important is reality than what is written in API documentation, I think.
despite any documentation.
so the more important is reality than what is written in API documentation, I think.
-
- Posts: 14
- Joined: Mon Nov 03, 2014 5:18 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
I agree with xvitcoder that the question is contradictive with the correct answer. The question states: "What will the following code print?"
I know in the API documentation it's String#charAt(int index) throws IndexOutOfBoundsException, so in theory it could also throw an ArrayIndexOutOfBoundsException as it's also a subclass of IndexOufOfBoundsException. The point here however, is that it's not what the question asks, with the given piece of code. Is there even a remote case possible where the piece of code provided: gives any other exception than StringIndexOutOfBoundsException? Personally I think this was a trick question, even if you know that String's charAt throws IndexOufOfBoundsException in the API documentation.
Maybe the answers should be changed from: "It will throw a StringIndexOutOfBoundsException." to "It can only throw an StringIndexOutOfBoundsException." or something like that. Then its more clear that the question is about String's charAt in general, instead of this specific case with the code provided.
EDIT: Ok, I missed the part where it said StringOutOfBoundsException instead of StringIndexOutOfBoundsException in the answer.. my bad..
I know in the API documentation it's String#charAt(int index) throws IndexOutOfBoundsException, so in theory it could also throw an ArrayIndexOutOfBoundsException as it's also a subclass of IndexOufOfBoundsException. The point here however, is that it's not what the question asks, with the given piece of code. Is there even a remote case possible where the piece of code provided:
Code: Select all
System.out.println("12345".charAt(6));
Maybe the answers should be changed from: "It will throw a StringIndexOutOfBoundsException." to "It can only throw an StringIndexOutOfBoundsException." or something like that. Then its more clear that the question is about String's charAt in general, instead of this specific case with the code provided.
EDIT: Ok, I missed the part where it said StringOutOfBoundsException instead of StringIndexOutOfBoundsException in the answer.. my bad..
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
Good discussion
If you like our products and services, please help us by posting your review here.
-
- Posts: 15
- Joined: Tue Jan 13, 2015 12:10 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
On Monday, January, 19 2015, I was at the real 1Z0-803 exam and got an almost similar question. There wasn't the "IndexOutOfBoundsException" opthion. There was only "StringIndexOutOfBoundsException", "ArrayIndexOutOfBoundsException" and several checked exceptions. It look like they have fixed it. Relax! And good luck on your exam!
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
Well, that's great news!
thank you for sharing your experience and information.
thank you for sharing your experience and information.
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Thu Nov 10, 2016 3:07 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
This is really a tricky ambiguous question.
Considering the following code, what should we answer?
What should be the answer to the following two possible questions?
Question 1) What will the following code print?
Question 2) What will the exception thrown when the code is compiled and run?
Say the options of both questions have "It throws IOException" and "It throws FileNotFoundException" and other options are obviously wrong.
Considering the following code, what should we answer?
Code: Select all
static void testMethod() throws IOException{
throw new FileNotFoundException();
}
public static void main(String[] args) throws IOException{
testMethod();
}
Question 1) What will the following code print?
Question 2) What will the exception thrown when the code is compiled and run?
Say the options of both questions have "It throws IOException" and "It throws FileNotFoundException" and other options are obviously wrong.
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
FileNotFoundException. Always go with most specific answer, if possible.
-Paul.
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 3
- Joined: Fri Jun 29, 2018 1:33 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
Bellow is the code I extracted from The String class:
public char charAt(int index) {
if ((index < 0) || (index >= value.length)) {
throw new StringIndexOutOfBoundsException(index);
}
return value[index];
}
I still don't uderstand how IndexOutOfBoundsException will be thrown instead of StringIndexOutOfBoundsException
public char charAt(int index) {
if ((index < 0) || (index >= value.length)) {
throw new StringIndexOutOfBoundsException(index);
}
return value[index];
}
I still don't uderstand how IndexOutOfBoundsException will be thrown instead of StringIndexOutOfBoundsException
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
Please go through the complete discussion above.
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
Is there a list of ALL things we need to know for the examp by heart?
All APIs and which methods, All exception classes, All Date constants ...
I know that there are posts about that in the forum but is there one post that contain all the information ?
All APIs and which methods, All exception classes, All Date constants ...
I know that there are posts about that in the forum but is there one post that contain all the information ?
-
- Posts: 66
- Joined: Mon Feb 20, 2017 12:31 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
Hi Enthuware!
Now I have a big doubt. So ArrayIndexOutOfBoundsException and StringIndexBoundsException shouldn´t be answered like correct in the test? Should we answer IndexOutOfBoundsException any time?
Thank you in advance!
Now I have a big doubt. So ArrayIndexOutOfBoundsException and StringIndexBoundsException shouldn´t be answered like correct in the test? Should we answer IndexOutOfBoundsException any time?
Thank you in advance!
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
Yes, in our opinion, you should go with what the JavaDoc says. In this case, it is IndexOutOfBoundsException.
I will also suggest you not to worry too much about this issue for the exam.
HTH,
Paul.
I will also suggest you not to worry too much about this issue for the exam.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 66
- Joined: Mon Feb 20, 2017 12:31 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
Hi again Paul!
In this example we have to say IndexOutOfBoundsException instead of StringIndex...(I read in the API that is throwing IndexOutOfBoundsException)
"test".substring(2,1); // IndexOutOfBoundsException
Am I right Paul?
Thank you very much!
In this example we have to say IndexOutOfBoundsException instead of StringIndex...(I read in the API that is throwing IndexOutOfBoundsException)
"test".substring(2,1); // IndexOutOfBoundsException
Am I right Paul?
Thank you very much!
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.852 :
Yes, that is correct.
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 63 guests