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.

Recommended Answers

All 2 Replies

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.

Thanks man i have understood.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.