Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
40 Cards in this Set
- Front
- Back
the only legal expression in an if statement is a ___ expression
|
boolean, in other words an expression that resolves to a boolean or a Boolean variable
|
|
watch out for ___ that can be mistaken for boolean equality (==) tests:
|
boolean assignments (=)
|
|
curly braces are optional for if blocks that ___. but watch out for misleading indentations
|
have only one conditional statement
|
|
switch statements can evaluate only to ___
|
enums or the byte, short, int, and char data types
|
|
the ___ constant must be a literal or final variable, or a constant expression, including an enum
|
case, you cannot have a case that includes a non-final variable, or a range of values
|
|
unless there is a ___ statement, the matching case is not the only case code that runs
|
break
|
|
the ___ keyword should be used in a switch statement if you want to run some code when none of the case values match the conditional value
|
default
|
|
the ___ ___ can be located anywhere in the switch block, so if no case matches, the ___ ___ will be entered, and if the default does not contain a break, then code will continue to execute (fall-through) to the end of the switch or until the break statement is encountered
|
default block
|
|
a basic for statement has three parts:
|
declaration and/or initialization, boolean evaluation, and the iteration expression
|
|
if a variable is incremented or evaluated within a basic for loop, it must be ___
|
declared before the loop, or within the for loop declaration
|
|
a variable declared (not just initialized) within the basic for loop declaration cannot be
|
accessed outside the for loop (in other words, code below the for loop won't be able to use the variable)
|
|
you can/can't initialize more than one variable of the same type in the first part of the basic for loop declaration
|
can, each initialization must be separated by a comma
|
|
an enhanced for statement (new as of Java 5), has two parts, the ___ and the ___. it is used only to loop through arrays or collections
|
declaration and the expression
|
|
with an enhanced for, the expression is the ___ or ___ through which you want to loop
|
array or collection
|
|
you cannot use a ___ as a condition for an if statement or looping construct. you can't for example say if(x) unless x is a boolean variable
|
number (old C-style language construct) or anything that does not evaluate to a boolean value
|
|
the ___ ___ will enter the body of the loop at least once, even if the test condition is not met
|
do loop
|
|
an ___ ___ ___ will cause the current iteration of the inner-most looping construct to stop and the line of code following the loop to run
|
unlabeled break statement
|
|
an ___ ___ ___ will cause: the current iteration of the inner-most loop to stop, the condition of that loop to be checked, and if the condition is met, the loop to run again
|
unlabeled continue statement
|
|
if the break statement or the continue statement is labeled
|
it will cause similar action to occur on the labeled loop, not the innermost loop
|
|
exceptions come in two flavors:
|
checked and unchecked
|
|
___ exceptions include all subtypes of Exception, excluding classes that extend RuntimeException
|
checked
|
|
checked exceptions are subject to the handle or declare rule; any method that might throw a checked exception (including methods that invoke methods that can throw a checked exception) must
|
either declare the exception using throws, or handle the exception with an appropriate try/catch
|
|
subtypes of Error or RuntimeException are unchecked, so the compiler ___. you're free to handle them, or to declare them, but the compiler doesn't care one way or the other
|
doesn't enforce the handle or declare rule
|
|
if you use an optional ___ block, it will always be invoked, regardless of whether an exception in the corresponding try is thrown or not, and regardless of whether a thrown exception is caught or not
|
finally
|
|
the only exception to the finally-will-always-be-called rule is that a finally will not be invoked if the ___. that could happen if code from the try or catch blocks calls System.exit()
|
JVM shuts down
|
|
just because finally is invoked
|
does not mean it will complete. code in the finally block could itself raise an exception or issue a System.exit()
|
|
uncaught exceptions propagate back through the
|
call stack, starting from the method where the exception is thrown and ending with either the first method that has a corresponding catch for that exception type or a JVM shutdown (which happens if the exception gets to main(), and main() is "ducking" the exception by declaring it)
|
|
you can create you own exceptions, normally by
|
extending Exception or one of its subtypes. your exception will then be considered a checked exception, and the compiler will enforce the handle or declare rule for the exception
|
|
all catch blocks must be ordered from ___. if you have a catch clause for both IOException and Exception, you must put the catch for IOException first in your code. otherwise, the IOException would be caught by catch (Exception e), because a catch argument can catch the specified exception or any of its subtypes! the compiler will stop you from defining catch clauses that can never be reached
|
most specific to most general
|
|
some exceptions are created by programmers
|
some by the JVM
|
|
___ give you a way to test your assumptions during development and debugging
|
assertions
|
|
assertions are typically ___ during testing but ___ during development and debugging
|
enabled, disabled
|
|
you can use assert as a ___ or an ___, but not both together. to compile older code that uses assert as an identifier, use the -source 1.3 command line flag to javac
|
keyword or an identifier
|
|
assertions are disabled at runtime by default. to enable them
|
use a command-line flag -ea or -enableassertions
|
|
selectively disable assertions by using the
|
-da or -disableassertions flag
|
|
if you enable or disable assertions using the flag ___, you're enabling or disabling assertions in general. you can combine enabling and disabling switches to have assertions enabled for some classes and/or packages, but not others
|
without any arguments
|
|
you can/can't enable and disable assertions on a package-by-package basis, and any package you specify also includes any subpackages (packages further down the directory hierarchy)
|
can
|
|
do not use assertions to validate
|
arguments to public methods
|
|
do not use assert expressions that ___. assertions aren't guaranteed to always run, and you don't want behavior that changes depending on whether assertions are enabled
|
cause side effects
|
|
do use assertions-even in public methods-to validate that a particular code block will never be reached. you can use ___ ___ for code that should never be reached, so that an assertion error is thrown immediately if the assert statement is executed
|
assert false;
|