Section 16.8 - Ada language vs. Java language

It makes sense to close a discussion of Ada and Java by comparing the two languages.

Ada and Java have more similarities than differences. Both the Ada language and the Java language were designed with safety in mind (both support strong typing, omit pointers, and perform many compile-time and run-time checks). Both support an object-oriented approach based on a single inheritance hierarchy. When generating class files, both Ada and Java support garbage collection, multitasking, and platform-independent graphical user interfaces (GUIs).

There are differences, of course. Here are some technical advantages of the Ada language over the Java language (SigAda has a similar list):

  1. Ada supports enumerated types.
  2. Ada supports operator overloading for infix operators (for example, you can define an infix + operation for complex numbers).
  3. Ada supports generics. There is no Java equivalent, though Java's "Interface" and its root Object class can sometimes be used to do similar things.
  4. Ada supports "in", "out", and "in out" to document the use of parameters, and these modifiers work on both tagged types and scalars.
  5. Ada is easier to read in some cases (compare "and" with "&&"; compare "for I in 1..10" with "for (i=1; i <= 10; i++)"; compare "a=b" with "a==b").
  6. Ada permits array boundaries to start with any scalar. The Java language requires array boundaries to start at 0, a common source of "one-off" errors.
  7. Ada supports numeric range checks more specific than the built-in types. This can be used to detect errors that Java doesn't.
  8. Ada supports method calls using named and unordered parameters, and supports default parameter values.
  9. Ada supports subprogram access types and nested subprograms.

Java has some technical advantages over Ada, too:

  1. Java supports "interface" types. There is no standard Ada equivalent, though Ada generics and the nesting of objects can sometimes be used to do similar things. Ada programs that generate Java code can use and define Java interfaces, using a special pragma to do so.
  2. Java permits specifications to be circular (A depends on B which depends on A), while Ada does not. There is some argument that this is a disadvantage, since circular references can indicate poorly structured systems, but in terms of ease-of-use this is an advantage.
  3. Java class definitions tend to be shorter than Ada. Here are some of the reasons for this:
    1. Ada enforces a distinction between objects and access values to objects. This causes definitions to be longer (for example, in Ada you have to define X_Obj and X_Ptr types everywhere, while all of that is not used in the Java language).
    2. Ada requires an explicit list of all classes used ("with" statements) in a class being defined. Java does not require a list of classes used; the closest Java has is its "import" statement, which is like the "use" clause in Ada.
    3. Java has an implicit "this" parameter for non-static methods; Ada requires all parameters to be explicitly listed.
    4. Java interfaces have to be handled using a somewhat clumsy Ada syntax.
  4. Java supports hierarchies of exception definitions. Java also includes definitions of exceptions that might be thrown (raised) by each method as part of the method definition.

Naturally, more than technical issues make a decision. Here are some other issues regarding the use of the Java language and Ada language for creating Java applets and applications:

  1. There are a number of tooling issues. At the time of this writing there are more Ada compilers than Java compilers, but by the time you read this there should be many compilers for both languages. Most Ada compilers generate native (high-speed) code that can take advantage of the underlying hardware, while Java compilers are just beginning to appear. However, currently only one Ada compiler can generate class files and applets, so the quantity of compilers tilts towards Java if you're solely interested in generating applets and/or class files. You'll also need to compare the tool capabilities themselves: which have better interactive development environments (IDEs)? Which have additional functionality (like user interface generators) that you'd like? Since just-in-time Java compilers that take class files can compile both Java and Ada class files, the choice of language is irrelevant for just-in-time compilers.
  2. There are large reusable component libraries for both languages, each with different focuses. Compare the relevant reusable components in the different languages for your application.
  3. There is an ISO (international) standard for Ada, while a standard for Java is probably many years away (at the time of this writing).
  4. There is a large standard test suite for Ada compilers; none yet exists for Java.
  5. There are sometimes vendor restrictions prohibiting use of the Java language for safety-critical systems; Ada is commonly used in such areas, and compilers can be bought without such prohibitions.
  6. The use of Java in real-time applications is somewhat currently a research area, while Ada is already used in such areas and has been for many years.
  7. Most Java materials and tools assume that users are using the Java language. Thus, if you're developing a Java application in Ada you'll need to learn the translation conventions (as discussed in previous sections) and be able to make such translations mentally. No such translations are needed if you're using the Java language.

Quiz:

Which of the following statements is true?

  1. The Java language lets you write your own infix operators, while the Ada standard supports interface types and hierarchical exceptions.
  2. A web browser that includes a just-in-time compiler for class files can't compile programs written in Ada.
  3. When generating Java class files, both Ada and Java support garbage collection and a standard graphical user interface.
  1. Statement 1.
  2. Statement 2.
  3. Statement 3.

You may also:

PREVIOUS Go back to the previous section

NEXT     Skip to the next section

OUTLINE  Go up to lesson 16 outline

David A. Wheeler (dwheeler@dwheeler.com)

The master copy of this file is at "http://www.adahome.com/Tutorials/Lovelace/s16sf.htm".