0

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.

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by koduruabhinav
0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.