• Post Reply Bookmark Topic Watch Topic
  • New Topic

Does import mean import?  RSS feed

 
Ranch Hand
Posts: 42
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings Everyone!
I might very well be distracting folks on here.  Please, bear with me.  I just want to know what the import statement really does in Java.  I tried to Google it, but I am not sure the results I got explains the topic better.
Two of the Google results are shown below:

1.  The import statement in Java allows to refer to classes which are declared in other packages to be accessed without referring to the full package name....

2.  Java keyword: import. The import keyword is used to make classes and interfaces available and accessible to the current source code, without specifying fully qualified package names....

When someone says the import keyword is used to make classes and interfaces available and accessible to the current code, what exactly does this mean?  Does it mean copying the classes or interfaces to the current code? Is import really importing anything?

Thanks in advance for the time and effort you will spare in responding to my newbie questions.
 
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me explain with an example, The following code works without any imports:
If you add an import java.io.File; to your code, you can write:

Does the above example explain the statement :
Biniman Idugboe wrote:The import statement in Java allows to refer to classes which are declared in other packages to be accessed without referring to the full package name

?
 
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Biniman Idugboe wrote:. . . Does it mean copying the classes or interfaces to the current code? Is import really importing anything?
No. There is no copying of code, as there might be in C. The compiler uses import statements to find code which often has already been compiled; it uses whichever classes are required. Those classes are loaded into memory whenever they are needed.
Thanks in advance for the time and effort you will spare in responding to my newbie questions.
That's a pleasure
 
Biniman Idugboe
Ranch Hand
Posts: 42
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys. 
Those classes are loaded into memory whenever they are needed.
  That clarifies it a lot more to me.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Biniman Idugboe wrote:Thanks guys. . . .
That's a pleasure
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!