Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Import statement in Java Program

Posted on 2002-06-05
3
232 Views
Last Modified: 2010-03-31
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.*;
or
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?
0
Comment
Question by:JavaRam
3 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 50 total points
ID: 7056136
 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.
0
 
LVL 1

Expert Comment

by:BaneBane
ID: 7056180
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.
0
 
LVL 1

Expert Comment

by:pran071199
ID: 7058868
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
java.util.*;
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question