Recall & Review
beginner
What is the command to compile a Java program named
HelloWorld.java?Use
javac HelloWorld.java to compile the Java source file into bytecode.Click to reveal answer
beginner
How do you run a compiled Java program named
HelloWorld from the command line?Use <code>java HelloWorld</code> to run the compiled Java class file.Click to reveal answer
beginner
What does the
java command expect as input after the command itself?It expects the name of the class containing the <code>main</code> method to start execution.Click to reveal answer
intermediate
How can you pass arguments to a Java program via the command line?
Add the arguments after the class name in the <code>java</code> command, e.g., <code>java HelloWorld arg1 arg2</code>. These are accessible in the program via the <code>String[] args</code> parameter of <code>main</code>.Click to reveal answer
beginner
What is the difference between
javac and java commands?<code>javac</code> compiles Java source code into bytecode (.class files). <code>java</code> runs the compiled bytecode on the Java Virtual Machine.Click to reveal answer
Which command compiles a Java source file named
App.java?✗ Incorrect
The
javac command compiles Java source files.How do you execute a compiled Java class named
App?✗ Incorrect
Use
java App to run the compiled class.Where do command line arguments appear in a Java program?
✗ Incorrect
Arguments passed on the command line are received in
main(String[] args).What file extension does the Java compiler produce?
✗ Incorrect
The compiler produces bytecode files with the
.class extension.If you run
java HelloWorld but get an error, what might be a common cause?✗ Incorrect
The
java command needs the compiled .class file in the current directory or classpath.Explain the steps to compile and run a Java program from the command line.
Think about what commands you type and in what order.
You got /4 concepts.
Describe how command line arguments are passed to and accessed in a Java program.
Focus on the main method signature and command line syntax.
You got /3 concepts.