Skip to main content\(
\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 2.3 Summary & Reading Questions
-
Java programs must be compiled before execution, unlike Python which is interpreted directly.
-
Every Java program must define a
class, and all code must be inside that class.
-
Each Java program must include a
public static void main(String[] args) method as the entry point.
-
Java enforces that every variable and method must have a clearly defined type, including
void for methods that return nothing.
-
Statements in Java must end with a semicolon (
;), and whitespace is not syntactically meaningful.
-
Java uses dot notation to access class members, such as
System.out.println for output.
-
The
static keyword indicates that a method belongs to the class itself, rather than to an instance of the class.
Reading Questions Reading Questions
1.
Which of the following must be true of every Java program?
It must contain a method called
main() with no parameters.
No. The main method must include a specific parameter: String[] args.
It must include a
public static void main(String[] args) method inside a class.
Correct! This is the required entry point for all Java applications.
It must be saved with a
.exe extension.
No. Java source files use the .java extension and compile to .class.
It must be run using the Python interpreter.
No. Java uses its own compiler and Java Virtual Machine (JVM).
2.
What is the purpose of the
javac command?
To compile Java source code into bytecode
Exactly! javac compiles .java files into .class files.
No. Python programs are run with the python or python3 command.
No. javac only compiles code. Debugging is a separate process.
To edit Java source files
No. You use a text editor or IDE to edit Java files.
3.
What symbol does Java use to indicate the end of a statement?
No. # is used for comments in Python, not for statement termination.
Correct! Java uses semicolons to mark the end of a statement.
No. . is used for dot notation, not to end a statement.
No. } is used to close code blocks.
You have attempted
of
activities on this page.