Solved

Import statement in Java Program

Posted on 2002-06-05
3
221 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
Comment Utility
 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now