@node Obj-C and Java @appendix Differences and Similarities Between Objective-C and Java @cindex Objective-C and Java, differences and similarities @cindex differences and similarities, Objective-C and Java @paragraphindent 0 This appendix explains the differences/similarities between Objective-C and Java. It has nothing to do with JIGS, but is included to help people who want to learn Objective-C and know Java already. @section General @itemize @bullet @item C programmers may learn Objective-C in hours (though real expertise obviously takes much longer). @item Java has global market acceptance. @item Objective-C is a compiled OO programming language. @item Java is both compiled and interpreted and therefore does not offer the same run-time performance as Objective-C. @item Objective-C features efficient, transparent Distributed Objects. @item Java features a less efficient and less transparent Remote Machine Interface. @item Objective-C has basic CORBA compatibility through official C bindings, and full compatibility through unofficial Objective-C bindings. @item Java has CORBA compatibility through official Java bindings. @item Objective-C is portable across heterogeneous networks by virtue of a near omnipresent compiler (gcc). @item Java is portable across heterogeneous networks by using client-side JVMs that are software processors or runtime environments. @end itemize @section Language @itemize @bullet @item Objective-C is a superset of the C programming language, and may be used to develop non-OO and OO programs. Objective-C provides access to scalar types, structures and to unions, whereas Java only addresses a small number of scalar types and everything else is an object. Objective-C provides zero-cost access to existing software libraries written in C, Java requires interfaces to be written and incurs runtime overheads. @item Objective-C is dynamically typed but also provides static typing. Java is statically types, but provides type-casting mechanisms to work around some of the limitations of static typing. @item Java tools support a convention of a universal and distributed name-space for classes, where classes may be downloaded from remote systems to clients. Objective-C has no such conventions or tool support in place. @item Using Java, class definitions may not be divided or extended through the addition of logical groupings. Objective-C's provides categories as a solution to this problem. @item Objective-C provides delegation (the benefits of multiple inheritance without the drawbacks) at minimal programming cost. Java requires purpose written methods for any delegation implemented. @item Java provides garbage collection for memory management. Objective-C provides manual memory management, reference counting, and garbage collection. @item Java provides interfaces, Objective-C provides protocols. @end itemize @section Source Differences @itemize @bullet @item Objective-C is based on C, and the OO extensions are comparable with those of Smalltalk. The Java syntax is based on the C++ programming language. @item The object (and runtime) models are comparable, with Java's implementation having a subset of the functionality of that of Objective-C. @end itemize @section Compiler Differences @itemize @bullet @item Objective-C compilation is specific to the target system/environment, and because it is an authentic compiled language it runs at higher speeds than Java. @item Java is compiled into a byte stream or Java tokens that are interpreted by the target system, though fully compiled Java is possible. @end itemize @section Developer's Workbench @itemize @bullet @item Objective-C is supported by tools such as GNUstep that provides GUI development, compilation, testing features, debugging capabilities, project management and database access. It also has numerous tools for developing projects of different types including documentation. @item Java is supported by numerous integrated development environments (IDEs) that often have their origins in C++ tools. Java has a documentation tool that parses source code and creates documentation based on program comments. There are similar features for Objective-C. @item Java is more widely used. @item Objective-C may leverage investment already made in C based tools. @end itemize @section Longevity @itemize @bullet @item Objective-C has been used for over ten years, and is considered to be in a stable and proven state, with minor enhancements from time to time. @item Java is evolving constantly. @end itemize @section Databases @itemize @bullet @item Apple's EOF tools enable Objective-C developers to build object models from existing relational database tables. Changes in the database are automatically recognised, and there is no requirement for SQL development. @item Java uses JDBC that requires SQL development; database changes affect the Java code. This is considered inferior to EOF. @end itemize @section Memory @itemize @bullet @item For object allocation Java has a fixed heap whose maximum size is set when the JVM starts and cannot be resized unless the JVM is restarted. This is considered to be a disadvantage in certain scenarios: for example, data read from databases may cause the JVM to run out of memory and to crash. @item Objective-C's heap is managed by the OS and the runtime system. This can typically grow to consume all system memory (unless per-process limits have been registered with the OS). @end itemize @section Design Stability @itemize @bullet @item Objective-C: A consistent API is provided by the OpenStep software libraries. Mainstream developers may require knowledge of four to five APIs, all of which have consistent style/conventions. @item Java package APIs are numerous and may use different styles. @end itemize