Java is one of the most popular programming languages used today. The designers of Java credit Objective-C as one of the influences that led to the creation of Java. In addition to the Java language syntax, Java provides standard libraries of objects and a standard runtime environment called the Java Virtual Machine (JVM). Apple supports the use of Java when creating Cocoa applications. Java implements classes, inheritance, and polymorphism in ways that are compatible with Cocoa. Java has several compelling features not shared by other languages used with Cocoa.
Automatic Garbage Collection
Dynamic memory management is one of the most difficult aspects of programming. The Java language and the JVM include technology called automatic garbage collection. Automatic garbage collection is a technique for automatically reusing dynamically allocated memory that is no longer being used by the objects that reserved it. Java programmers can usually ignore the issues of dynamic memory management because the language and JVM take care of that for them. However, to get the best possible performance with Java applications, programmers must still be sensitive to dynamic memory allocation issues. Objective-C does not have the same degree of support for automatic garbage collection.
Java includes a language feature called an interface. An interface specifies a set of behaviors that an object can invoke. Objects can have multiple interfaces. To promote reuse of objects, it is important that each object depend as little as possible on other objects. Java interfaces can be used to minimize the dependencies between objects. A Java object can be constructed so that it works with any other object that implements a particular interface without needing to know the class or other information about the other object. The less an object knows about other objects, the less likely it is to depend on the other objects.
Java interfaces are similar to Objective-C protocols. Cocoa uses protocols extensively. When Java is used with Cocoa, many of Cocoa's protocols are accessed with equivalent Java interfaces.
Security and Safety
Security was one of the design goals of Java. The JVM ensures that Java objects downloaded over the Internet cannot directly harm the computer on which they are run. Most computer languages do not have any security features and, therefore, it is not as safe to download and use objects written with other languages.
The Java Bridge
Apple provides a technology called the Java Bridge. The Java Bridge enables seamless interaction between Java objects and the Objective-Cbased Cocoa objects. Java objects can specialize Objective-C objects. The Java Bridge handles issues such as the different dynamic memory management conventions between Java and Objective-C. Java programs that use Cocoa objects only run on Mac OS X.
100% Pure Java
Java is a cross-platform language because of the Java Virtual Machine. Any computer with a recent version of the JVM can run Java programs even if the programs were written on a different type of computer. Mac OS X includes an up to date JVM implementation and standard libraries.
Java programs that only use Java's standard libraries are called 100% Pure Java programs. Such programs run on any computer with an up to date Java implementation. Mac OS X is an excellent platform for writing 100% Pure Java applications. However, if a Java program uses Cocoa, it will not work on operating systems other than Mac OS X.
The Java language includes JavaBeans, which are a standard for loading objects into running programs. The standard Java libraries include features for loading JavaBeans as well as identifying the interfaces and behaviors that the loaded JavaBeans support. JavaBeans have many features in common with a Cocoa technology called bundles.