hi,i was a beginner in java i have a doubt.

we use import to use the predefined classes.

we can also use package for importing classes.

import java.lang.*;

package java.lang.*;

what is the difference between imports and package

at what time we have to use differently.


plese try to help me.

I think you got it abit wrong mate. You don't use 'Package' to import classes. You use 'Package' to declare that the file you write this in, belongs to the package you write. I'm not sure if a file belonging to a certain package gets access to other classes within that package (might be why you confused it with import).

Then you use 'Import' to import the package, or class, you wish.

Here I import the File package (class).

import java.io.file;

Here I declare that this source file, belong to the package 'myprogram'.

package myprogram;

And as always, if someone can provide a better explaination, or correction, please do. As I'm here to learn as well.

This question has already been answered. Start a new discussion instead.