What is the need to import libraries several times

in most code examples, I see people doing this.

import javax.swing.*; // for the frame
import java.awt.*; // for the checkBox and the label
import java.awt.event.*; // for the checkBox listener

If I'm right, when we talk about importing java.awt. * It imports everything inside it, so it is not necessary to specify the import java.awt.event. *; or is there a speed improvement? can someone explain what imports the library, imports a simple text class to include in the source, or tells jvm to include the bytecode of what is imported? so importing into java means nothing but switching the namespace, so I don't need to enter long class names?

+3
source share
4 answers

subpackage. . Java-.

java.awt - ( ), java.awt.event - , . , . ( ). ( ), import.


BTW, : . , java (: classes from java.lang, ). , import .

, .

+5

...

import java.awt.*;

... , . . , java. * java-.

, , *.

+4

.

.

import java.awt.*, java.awt.Outer.Inner, Outer.Inner.

In contrast, when you say import java.awt.Outer.*, you can refer to the inner class as Inner.

+1
source

Importing is just a compile-time function, in the byte encoder you will find only direct links to certain classes, every time an instance of it is used. The import constructs exist only to exclude the use of the fully qualified class name each time.

+1
source

All Articles