Chapter 10: Development Flashcards

1
Q

What does the -d option when used with the javac command?

A

-d or -destination defines the output folder for the compiled classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
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?

A

Command:
-javac -d ../classes com/foo/bar/App.java

Result:
/classes/com/foo/bar/App.class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

Error.

Folder /classes does not exist

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the command for running:

  • MyApp.class
  • With property myProp with value: my value
  • And arguments 10 and x
A

java -DmyProp=”my value” MyApp 10 x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you retrieve the system properties from java code?

A

System.getProperties();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the three ways how the args in a main method can be declared.

A

String[] args
String… args
String args[]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the -cp -classpath flag do in combination with the java an javac commands?

A

-cp or -classpath defines class search locations, for example third party classes.

javac -classpath /com/apache:/com/microsoft MyApp.java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Given the following class:

package com.foo.bar
public class MyApp {}

When compiles using:
javac -d classes MyApp.java

What is the result?

A

classes/com/foo/bar/MyApp.class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
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

A

dirB, dirA, dirC

/home/dirA/dirB is a absolute path
dirA is a relative path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the /jre/lib/ext folder inside a Java installation?

A

A folder that is automatically added to the classpath by Java. Adding JAR files here will automatically add them to the classpath

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
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);
   }
}
A

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);
   }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly