• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Import statement in Java Program

I am using java.util.Vector in my Java program. So, I need to import that class into my program.
This can be done either by ...
import java.util.*;
import java.util.Vector;
Which one will be the right one? Will there be any performance issue when importing the whole package instead of just the class file which I am using?
1 Solution
 It does not actually matter and there are no performance issues if you import the whole package instead of a single class. The classes are imported and used at compile time in a Java application. When you do an import java.util.*; you are not actually loading all the classes in memory, you just indicate to the VM where to find the classes during compilation time.

  But it is a good programming practice to import classes separately since it gives a clearer view of what class resides within which package.

  Hope it helps.
As far as I know there is no deference btween the two. the compiler will only link the classes that you need not the *.

Hope this helps.
As a good practice /coding convention

use import java.util.Vector;  if you are using only Vector class from java.util package.

if you are using more than one Class from package use
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now