0
0
Javaprogramming~5 mins

Command line execution in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Acompile App.java
Bjava App.java
Crun App.java
Djavac App.java
How do you execute a compiled Java class named App?
Ajava App
Bjavac App
Crun App
Dexecute App.java
Where do command line arguments appear in a Java program?
AIn the <code>Scanner</code> class automatically
BIn the <code>System.out</code> stream
CIn the <code>String[] args</code> parameter of <code>main</code>
DIn the <code>java.util</code> package
What file extension does the Java compiler produce?
A.class
B.java
C.exe
D.jar
If you run java HelloWorld but get an error, what might be a common cause?
AYou forgot to write <code>javac</code> before <code>java</code>
BThe <code>HelloWorld.class</code> file is missing or not in the current directory
CYou need to add <code>.java</code> extension when running
DJava programs cannot be run from the command line
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.