Chapter 10: Development Flashcards
What does the -d option when used with the javac command?
-d or -destination defines the output folder for the compiled classes.
Considering the following folders: /home /sources /com/foo/bar/App.java /classes
And working dir is /home/sources
What is the command for compiling App.java and putting the result into the classes folder? And what is the result?
Command:
-javac -d ../classes com/foo/bar/App.java
Result:
/classes/com/foo/bar/App.class
Given the following folders:
/home
/sources/App.java
And working dir is /home
What is the result of running the following command:
javac -d classes sources/App.java
Error.
Folder /classes does not exist
Describe the command for running:
- MyApp.class
- With property myProp with value: my value
- And arguments 10 and x
java -DmyProp=”my value” MyApp 10 x
How do you retrieve the system properties from java code?
System.getProperties();
Describe the three ways how the args in a main method can be declared.
String[] args
String… args
String args[]
What does the -cp -classpath flag do in combination with the java an javac commands?
-cp or -classpath defines class search locations, for example third party classes.
javac -classpath /com/apache:/com/microsoft MyApp.java
Given the following class:
package com.foo.bar public class MyApp {}
When compiles using:
javac -d classes MyApp.java
What is the result?
classes/com/foo/bar/MyApp.class
Given the following folders: /home /dirA /dirB /dirC
Working dir is Home.
What folders are searched for classes when used in:
-cp /home/dirA/dirB:dirA
dirB, dirA, dirC
/home/dirA/dirB is a absolute path
dirA is a relative path
What is the /jre/lib/ext folder inside a Java installation?
A folder that is automatically added to the classpath by Java. Adding JAR files here will automatically add them to the classpath
Improve the following code to use Static Imports: public class App { public static void main(String[] args) { System.out.println(Integer.MAX_VALUE); System.out.println(Integer.toHexString(42); } }
Add two static imports:
import static java.lang.System.out;
import static java.lang.Integer.*;
public class App { public static void main(String[] args) { out.println(MAX_VALUE); out.println(toHexString(42); } }