Skip to main content

Java For Python Programmers Edition 2

Section 2.3 Summary & Reading Questions

  1. Java programs must be compiled before execution, unlike Python which is interpreted directly.
  2. Every Java program must define a class, and all code must be inside that class.
  3. Each Java program must include a public static void main(String[] args) method as the entry point.
  4. Java enforces that every variable and method must have a clearly defined type, including void for methods that return nothing.
  5. Statements in Java must end with a semicolon (;), and whitespace is not syntactically meaningful.
  6. Java uses dot notation to access class members, such as System.out.println for output.
  7. 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.
  • To run a Python program
  • No. Python programs are run with the python or python3 command.
  • To debug Java programs
  • 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.