can some tell me the difference between the import we use in java and the one in objective C?
-
dup:http://stackoverflow.com/questions/439662/what-is-the-difference-between-import-and-include-in-objective-c – jmj Sep 30 '10 at 07:38
-
1@org: um, no, that question talks about `#import` and `#include` in Obj-C only. This one talks about `import` in Java vs `#import` in Obj-C. – BoltClock Sep 30 '10 at 07:42
-
1@BoltClock's a Unicorn ok, I apologize, – jmj Sep 30 '10 at 07:43
2 Answers
In Java,
import long.package.name.Foo;
tells the compiler that any timeFoo
appears as aa class name in the current source file, it really meanslong.package.name.Foo
- so allimport
really does is allow you to write shorter source code. Finding class definitions is done via the convention of having class names match file names and package names match directory hierarchies.In Objective C, an
#import
statement is actually replaced with the contents of the imported file by the preprocessor, unless that file has already been imported (this is the difference between#import
and the older#include
directive).

- 342,105
- 78
- 482
- 720
-
Does it mean that in Java, instead of writing "long.package.name.Foo" to represent a Foo, import helps us in referring it shortly. – RK- Sep 30 '10 at 07:58
-
1
-
1and that is all that it does. No magical side effects (like Perl's `use` can have for example) to be wary of. – Thilo Sep 30 '10 at 08:04
-
#import
is a variant (that checks for duplication) of #include
, which just results in the contents of the included file being pasted in your source file.
Java's import statement tells the compiler where to look for classes (and other things) that are not qualified by their full name in the source code.

- 257,207
- 101
- 511
- 656