Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

The import keyword

The import statement make available one or all the classes in a package to the current source file.

The import keyword

                         

The import statement make available one or all the classes in a package to the current source file. Keywords are basically reserved words which have specific meaning relevant to a compiler. Once a package in a java source file is imported then that class (source file) can use the classes available in the package without specifying the package name to which the class belongs.

Syntax: Here is the syntax to import a package in a class.

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;

Due to the rigid naming convention used by java programming language, java compile easily finds the corresponding source file simply by using fully qualified name of the class along with the package name. Here is the syntax for the style of import a package and the class of that package:

java.util.ArrayList a = new java.util.ArrayList ( 25 );

Note: Here are some points that must consider while importing a package.

  • The character "*" must be used in order to import all the class of a package.
  • Avoid use of the character "*" while using one or two class of a package because it can arise ambiguity when multiple package includes classes having same names.
  • Use import statement in the beginning of the source file just to specify that the class or the entire java package can be referred by using the package name.
  • Java versions from J2SE 5.0 to upward can import the static members of a class also.

                         

» View all related tutorials
Related Tags:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.