jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding import statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding import statement" Watch "Regarding import statement" New topic

Regarding import statement

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 481
Somewhere I have read
import java.*;
This example will compile, and it will try to import any classes within the directory java. It will not, however, import any of the packages located in subdirectories of java. In the preceding instance, there are no classes located directly in the Java package, therefore nothing will be imported.

But in the above coding,it did show compile error as stated

And consider the below program that worked successfully without any error.

And another class in different package

What is the rule behind using import java.* (or) import payroll.*; .Please help me.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
Note that the first code does not compile exactly for the reason you mentioned.

import java.*

does not import subpackages.

You cannot use the Date class because you did not import the package it is in.

The other code compiles because the class you created is part of the payroll package and you import it.
I agree. Here's the link: http://aspose.com/file-tools
subject: Regarding import statement
It's not a secret anymore!