1.4-1_Understanding Package Declarations and Imports Flashcards

1
Q

How are grouped Java classes?

A

into packages

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

What does the import statement does?

A

The import statement tells the compiler which package to look in to find a class.

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

[WildCards] What is the wildcard symbol?

A

The * is the wildcard, that matches all classes in the package.

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

[WildCards] Does the wildcard slowdown your execution?

A

Including wildcard on import doesn’t slow down your program execution

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

Which package is automatically imported?

A

Everything in java.lang is automatically considered to be imported.

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

When is required to import packages?

A
✅ When referencing a class which is in another package. 
✅ When you're using classes from different packages but have the same name.
⚠️Importing a class that is in the same package as the class importing it. (Is a redundancy)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

[WildCards] Does a wildcard in a simple import matches also fields and methods?
import {package};

A
No, this is only achievable via static imports.
With a simple import You cannot import methods only class names.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Could you have multiple wildcards in an import statement?

A

No, You can only have one wildcard and it must be at the end.
✅ import java.nio.;
❌ import java.nio.
.*;

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

[Naming Conflicts] What does Naming conflicts mean when importing classes?

A

When the class is found in multiple packages, Java gives you a compiler error.

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

[Naming Conflicts] Is there any precedence regarding wildcards and naming conflicts?

A
If you explicitly import a class name, it takes precedence over any wildcards import.
import java.util.*;
import java.sql.Date;
java.sql.Date will take precedence in these imports.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What options do you have when you need to use 2 classes with the same name?

A
o  You can pick one to use in the import and use the other’s fully qualified class name.
o  Or you could have neither with an import and always use the fully qualified class name.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly