8

It is not a statement nor an expression.

What is that called then? A directive?

Jonik
  • 80,077
  • 70
  • 264
  • 372
OscarRyz
  • 196,001
  • 113
  • 385
  • 569
  • @SLaks... I don't know.. mmhh reserved word maybe? – OscarRyz May 05 '10 at 15:51
  • Here's referred as an statement: http://java.sun.com/docs/books/tutorial/java/package/usepkgs.html :( – OscarRyz May 05 '10 at 15:53
  • Very commonly referred to as an "import statement", it seems: http://www.google.fi/search?q=java+%22import+statement vs http://www.google.fi/search?q=java+%22import+declaration – Jonik May 05 '10 at 15:55
  • @Jonik Yeap, I .. call it like that also ( or directive sometimes ) http://stackoverflow.com/questions/2774479/only-one-public-class-per-file/2774549#2774549 But not necessarily that's correct. Thanks for the edit btw. – OscarRyz May 05 '10 at 15:59
  • 2
    Great question. Even JLS 7.5.1 slipped up and says "Note that an `import` **statement** cannot import a subpackage, only a type." If you trace the grammatical production, though, you easily confirm that it's not in fact a statement (obviously!). – polygenelubricants May 05 '10 at 16:13

3 Answers3

6

It's called a Declaration.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
1

In the general scope, it is a directive.

Within Java, classes have a tight relationship between their declaration and their containing file (known as a compiler unit in Java's architecture). However, the import statement pre-dates Java.

When it was used in the C language, it was a declaration to the pre-processor (a component that is not existent in Java, to "paste" the file at "this location". This allowed one to "use" declarations without defining them (important for structuring C source code) by pasting in the "header" file which contained all the declarations for an "definition" file which would be linked in at a later date. This style of layout allowed implementations to share each others declared types without being influence by the actual implementation (known as the type definition).

Java inherited from C's legacy, so they used the "import" keyword to locate the type declaration; but Java doesn't really have independent declarations and definitions, opting for the declaration to be "read" from the definition. This was in an attempt to prevent a common C / C++ failure (that of compiling against on version of declarations, to have the code mysteriously fail with an almost-the-same set of definitions (built off a newer or later version of declarations).

So, for C/C++ - A preprocessor directive (equivalent to a preprocessor command).

And for Java - A declaration, as the directive matches a command to a preprocessor that no longer exists, under a restrictive layout that only permits one declaration per included file.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138