Can someone define the following Exceptions for me in the simplest and organized way possible so I can study them well in Java Coding?

- ClassCastException
- IndexOutOfBoundsException
- NoSuchElementException
- NullPointerException
- IllegalArgumentException

Could you also tell me out of these Exceptions, which one fits this scenario?

When a String has NOT been initialized but a method such as length evoked on it, which exception will be thrown?

Respuesta :

1. ClassCastException - A Java ClassCastException is an Exception that can occur when you try to improperly convert a class from one type to another. ... Because a String cannot be directly cast to an Integer — an Integer is not a type of String — a ClassCastException is thrown.

2. IndexOutOfBoundsException - If a request for a negative or an index greater than or equal to size of array is made, then the JAVA throws a ArrayIndexOutOfBounds Exception.

I only know these exceptions! Hope this helps you!!
ACCESS MORE