2

can some tell me the difference between the import we use in java and the one in objective C?

RK-
  • 12,099
  • 23
  • 89
  • 155
  • 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 Answers2

3
  • In Java, import long.package.name.Foo; tells the compiler that any time Foo appears as aa class name in the current source file, it really means long.package.name.Foo - so all import 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).

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
1

#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.

Thilo
  • 257,207
  • 101
  • 511
  • 656