- Language Philosophies
- Objects and Primitives
- Files and Compilation Units
- Object Models
- Static Behavior
- Different Syntax
- Summary
Files and Compilation Units
Both Objective-C and Java store source code in files (unlike Smalltalk and a lot of Lisp environments). In Java, there is no difference between a file and a compilation unit. Objective-C, unfortunately, inherits the horrible mess that is the C preprocessor. In Objective-C, a compilation unit is a source file and every other file that has been included in it by the preprocessor.
Objective-C extends the C preprocessor slightly, adding a #import directive. This is similar to #include but prevents multiple inclusion. If you #import a file, then you will only get one copy of it in the current compilation unit, no matter how many times you #import it.
In Java, the closest equivalent is the import directive. This is very different; it specifies a namespace that should be used to resolve a class. The Objective-C equivalent is much simpler; it just includes the text content of the specified file.
The preprocessor adds a bit of flexibility to Objective-C. You get things such as conditional compilation and some primitive metaprogramming tools, but it's quite basic.