• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

import vs include

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the impression that the import or reserved word is similar to the include statement used in C or is include also used in java?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Kevin,
As you stated, Java's 'import' looks the same as C/C++'s #include (Java does not use include). But there are a few (some might say major, some might say minor) differences.
First of all, Java's import statement doesn't include the file, as #include in C/C++ does, it just tells the compiler where to look for its class references. Therefore the import statement isn't used to import/include C-style header files in which you declare all the used functions, as the #include statement in C/C++ is used most of the time. Note that this isn't needed as, unlike C/C++, Java doesn't make a distinguishment between declaring a function and defining the function, as Java class files simply acts as both the declaration and the implementation of the object.
The second difference between Java's import statement and C/C++'s #include is that the latter statement is parsed by a preprocessor, transforming the statement into the equivalent C expressions/statements, thus actually adding the source code of the included file into the including file before compilation. Java does not have this kind of preprocessing because, in fact, you doesn't really need it.
Hope this helped,
Tim
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that in Java 1.4 and lesser releases, the import statement just tells the compiler where to find other classes. It looks like in Java 1.5, import statements will also be used to tell the compiler where to find static methods, if I've understood the brief readings I've done on the subject.
-------------
Tim B.,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic