Difference between complete package import .* and specified class import java?

Vamsi Emani :

Possible Duplicate:
Why is using a wild card with a Java import statement bad?

Ex. 1

import javax.swing.*

JFrame f = new JFrame()

Ex. 2

import javax.swing.JFrame

JFrame f = new JFrame()

Is there any efficiency gain (even the slightest and minimal) in adapting 2) instead of 1) ? How does java does the referencing of packages internally?

The first time the compiler comes across the word JFrame, I presume that it should search for JFrame in complete swing.* package in case of 1)..Else if in case 2), it might probably get hold of the class directly by some indexing or may be key value hashing? So why is this not considered an efficiency gain even if it is tiny? (Please correct me if my presumptions about the internals are wrong)

EDIT :

Sorry for the duplicate.. Answer at Why is using a wild card with a Java import statement bad?

Noufal Panolan :

There is no runtime penalty for using import javax.swing.* and import javax.swing.JFrame in Java. The only different is in compile time, the import package.* will search for whole package to find the correct class' information.

The Single-Type-Import (e.g., import javax.swing.JFrame) increases the readability of the program and it will be very clear which classes have been used.

The Type-Import-on-Demand (e.g. import javax.swing.*) causes the simple names of all public types declared in the package javax.swing to be available within the class and interface declarations of the compilation unit.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Difference between #import and @class

From Dev

Difference Between import and class.forName in java

From Dev

Difference between dependency and import/access in package diagram

From Dev

What is the difference between package import and normal import in flutter?

From Java

Performance difference between a wild card import and the required class import

From Dev

Difference between import * as & import { default as }

From Java

Java: Use import or explicit package / class name?

From Java

Import class from parent package in Java

From Java

Difference between c# using and Java import

From Dev

Difference between import and execfile

From Dev

difference between import commands

From Dev

Difference between import style

From Dev

Import package with no name Java

From Java

Java Package Import Alias

From Dev

How to import a package in java?

From Dev

How to import java package

From Dev

Difference between import {module} and import module

From Dev

Difference between from .. import and from . import

From

TypeScript - difference between import ... and import {...} (with curly braces)

From Dev

Difference between import * as Button and import {Button}

From

Difference between import React and import { Component } syntax

From Dev

Difference between import math and from math import

From Dev

Is there a difference between "import x" and "import x as _x"?

From Dev

Freemarker: difference between include and import?

From Dev

Difference between Update and Import in CloudFormation

From Dev

Difference between Use, Require and Import

From Dev

Rails - Difference between @import and *= require?

From Dev

What is the difference between these import statements?

From Dev

Elixir: Difference between require and import

Related Related

  1. 1

    Difference between #import and @class

  2. 2

    Difference Between import and class.forName in java

  3. 3

    Difference between dependency and import/access in package diagram

  4. 4

    What is the difference between package import and normal import in flutter?

  5. 5

    Performance difference between a wild card import and the required class import

  6. 6

    Difference between import * as & import { default as }

  7. 7

    Java: Use import or explicit package / class name?

  8. 8

    Import class from parent package in Java

  9. 9

    Difference between c# using and Java import

  10. 10

    Difference between import and execfile

  11. 11

    difference between import commands

  12. 12

    Difference between import style

  13. 13

    Import package with no name Java

  14. 14

    Java Package Import Alias

  15. 15

    How to import a package in java?

  16. 16

    How to import java package

  17. 17

    Difference between import {module} and import module

  18. 18

    Difference between from .. import and from . import

  19. 19

    TypeScript - difference between import ... and import {...} (with curly braces)

  20. 20

    Difference between import * as Button and import {Button}

  21. 21

    Difference between import React and import { Component } syntax

  22. 22

    Difference between import math and from math import

  23. 23

    Is there a difference between "import x" and "import x as _x"?

  24. 24

    Freemarker: difference between include and import?

  25. 25

    Difference between Update and Import in CloudFormation

  26. 26

    Difference between Use, Require and Import

  27. 27

    Rails - Difference between @import and *= require?

  28. 28

    What is the difference between these import statements?

  29. 29

    Elixir: Difference between require and import

HotTag

Archive