Skip to main content
Contents Index
Dark Mode Prev Up Next Scratch ActiveCode Profile
\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 9.7 Summary & Reading Questions
In Java, every variable must be declared with its type before use; undeclared variables cause compilation errors.
Java requires explicit import statements for classes from external packages (e.g.,
java.util.Scanner); otherwise, you get "cannot find symbol" errors.
The
new keyword is mandatory when creating new objects; forgetting it leads to errors as Java treats the constructor call incorrectly.
Every Java statement must end with a semicolon (
;); missing semicolons cause syntax errors.
Java uses generics for type safety in containers like
ArrayList; forgetting to specify the contained type leads to compiler warnings about unchecked operations.
Compiler error messages may sometimes be misleading; understanding common mistakes helps quickly identify the root cause.
Reading Questions Reading Questions
1.
What happens if you use a variable in Java without declaring it first?
The compiler gives an error indicating the variable cannot be found.
Correct! Java requires all variables to be declared before use.
The variable is automatically declared as type
Object.
No. Java does not implicitly declare variables.
The program compiles but throws an error at runtime.
No. This is a compile-time error.
Java ignores the variable and continues compiling.
No. Java will stop compiling with an error.
2.
Why must you include import statements for classes like
Scanner?
Because these classes belong to external packages and are not automatically available.
Correct! Java requires explicit imports for external classes.
Because Java does not support standard input without imports.
No. Standard input is supported but needs the Scanner class explicitly imported.
Because the classes are only available in Python, not Java.
No. This is a Java-specific requirement.
Because the compiler ignores unknown classes without imports.
No. It causes a compile error instead.
3.
What warning occurs when you use an
ArrayList without specifying a type?
An "unchecked" warning indicating potential type safety issues.
Correct! Using raw types disables generic type checks.
No. This is a compiler warning, not an error.
No. It only warns about possible runtime errors.
A logical error in the program.
No. The warning points out type safety concerns.
You have attempted
of
activities on this page.