Compile and Run Java Applications from the Command Line – Step-by-Step - Quiz
Total: 10 questions
1. Where the compiler places a .class file by default?
Where the compiler places a .class file by default?
In the same directory as the .java source file.
2. Which option is used to tell the compiler where to place generated .class file(s)?
Which option is used to tell the compiler where to place generated .class file(s)?
The -d option (d is for destination).
3. Let's say there is the following directory structure:
myNewProject
|
|--source
| |
| |-- MyNewClass.java
|
|-- classes
|
|--
Which command, issued from the myNewProject directory, will compile MyNewClass.java and place the resulting MyNewClass.class file into the classes directory (assuming that MyNewClass belong to the default package)?
Let's say there is the following directory structure:
myNewProject
|
|--source
| |
| |-- MyNewClass.java
|
|-- classes
|
|--
Which command, issued from the myNewProject directory, will compile MyNewClass.java and place the resulting MyNewClass.class file into the classes directory (assuming that MyNewClass belong to the default package)?
javac -d classes source/MyNewClass.java
4. Suppose there is the following .java file in such directory structure: package com.examclouds; public class MyNewClass { } myNewProject | |--source | | | |--com | | | |--examclouds | | | |--MyNewClass.java | |--classes | | | |--com | | | |--examclouds | | | |-- (MyNewClass.class goes here) Suppose you are in the source directory, and you are compiling MyNewClass.java and place the resulting MyNewClass.class file into the classes/com/examclouds directory. Write the command for this.
Suppose there is the following .java file in such directory structure: package com.examclouds; public class MyNewClass { } myNewProject | |--source | | | |--com | | | |--examclouds | | | |--MyNewClass.java | |--classes | | | |--com | | | |--examclouds | | | |-- (MyNewClass.class goes here) Suppose you are in the source directory, and you are compiling MyNewClass.java and place the resulting MyNewClass.class file into the classes/com/examclouds directory. Write the command for this.
javac -d ../classes com/examclouds/MyNewClass.java
5. What will happen if the destination directory specified with -d option in javac doesn't exist?
What will happen if the destination directory specified with -d option in javac doesn't exist?
A compiler error.
6. Which option should be used with the java command to set a system property?
Which option should be used with the java command to set a system property?
-D option
7. Launch the class named MyNewClass.class with two String arguments with values ex and 5. And create a system property called myNewProp with value myNewValue.
Launch the class named MyNewClass.class with two String arguments with values ex and 5. And create a system property called myNewProp with value myNewValue.
java -DmyNewProp=myNewValue MyNewClass ex 5
8. How to get Properties object?
How to get Properties object?
Properties p = System.getProperties();
9. Where does java and javac look for the classes?
Where does java and javac look for the classes?
First they look in the directories with standard Java SE (J2SE) classes. Then they look in the directories defined by classpaths.
10. Where classpaths can be declared?
Where classpaths can be declared?
It can be declared as an operating system environment variable or as a command-line option.