6. Flow control and Exceptions Flashcards
Which exception is not defined in Java API:
IndexPositionException
NullPointerException
ArrayIndexOutOfBoundsException
ArrayOutOfBoundsException
IndexPositionException
ArrayOutOfBoundsException
What will be the output:
boolean x = false;
if (x = true) { System.out.println(“x = “ + x);}
x = true
Watch out for boolean assignments (=) that can be mistaken for boolean equality (==) tests. If the example was “if (x = false)..” then the if statement will be skipped.
What data types can evaluate switch statements ?
switch statements can evaluate only to enums or the byte, short, int,
char, and, as of Java 7, String data types. You can’t say this:
long s = 30;
switch(s) { }
Which exceptions are unchecked and should we handle or declare rule.
Subtypes of Error or RuntimeException are unchecked, so the compiler doesn’t enforce the handle or declare rule. You’re free to handle them or to declare them, but the compiler doesn’t care one way or the other.