Ch1 Welcome to Java Flashcards
What package do the Files and Paths class belong to?
java.nio.file
Compile and run the following two classes using the java terminal commands:
- packagea/ClassA
- packageb/ClassB (contains the main method)
- javac packagea/ClassA.java packageb/ClassB.java
- java packageb.ClassB
Where does the javac command place the compiled classes by default?
In the same directory as the source code.
How can we use the javac command to compile ‘packagea/ClassA’ in the directory ‘classes’
javac -d classes packagea/ClassA.java
Compile and run the two classes below using the java terminal commands. Compile them into a directory called ‘classes’.
- packagea/ClassA
- packageb/ClassB (contains the main method)
- javac -d classes packagea/ClassA.java packageb/ClassB.java
- java -cp classes packageb.ClassB
What options are there to specify the classpath to the java or javac command?
- ‘-cp’
- ‘-classpath’
- ’–class-path’
Create a JAR file: ‘myNewFile.jar’ based on the current directory.
jar -cvf myNewFile.jar .
– or –
jar –create –verbose –file myNewFile.jar .
Create a JAR file: ‘myNewFile.jar’ based on the directory ‘dir’
jar -cvf myNewFile.jar -C dir .