1.4-2_Creating and Compiling Packages Flashcards

1
Q

If no package defined, where is the code placed?

A

When NO package statement present, the code is placed in what is known as the “default package”.

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

Which strategy should we use to avoid naming conflicts and reuse of your code?

A

Always name your packages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
How to compile ClassA and ClassB via terminal?
├── packagea
   │ ├── ClassA.class
   │ └── ClassA.java
   └── packageb
       ├── ClassB.class
       └── ClassB.java
A

$ javac packagea/ClassA.java packageb/ClassB.java

🤯️Notice that when defining a package we use dot notation.
⚠️When compiling we use / (forward slash) referencing the directory structure.

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

How to compile packages using wildcards?

A

$ javac packagea/.java packageb/.java

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

What is the difference between path & classpath?

A

PATH is the environment variable where we specify the locations of binaries.
CLASSPATH is the path for Java application where the classes you compiled will be available.

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

How to use an alternate target directory when compiling?

A
$ javac -d classes packagea/MyClass.java
When compiling the -d option specifies the target directory for placing the .class files, otherwise it will be placed in the same path of the class being compiled.
⚠️ Java options are case sensitive. This means you cannot pass -D instead of -d.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does indicate the period (.) when included as a directory in the classpath?

A

The period (.) indicates you want to include the current directory in the classpath.

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

How to compile with JAR files?

A

$jar -cvf myNewFile.jar .
$jar –create –verbose –file myNewFile.jar .
(-c | –create) Create
(-v | –versose) Print details
(-f | –filename) JAR filename
(-C) Target directory to create the JAR from

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

How to specify a Target Directory when creating a JAR?

A

(-C) Target directory to create the JAR from

jar -cvf myNewFile.jar -C dir .

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