Comparing Eiffel and Java

Shared Advantages

Religious feelings aside, these two languages have many more similarities than differences, when compared to other currently popular programming languages. Here is a list of shared advantages: In conclusion, both languages would do a decent job of teaching students about software development, especially compared to what else is out there The only disadvantage is not exposing the students to other programming paradigms, but most people feel that it is impossible to do that in a single language (see Tim Budd's work on Leda for an exception).


Unshared Advantages

Here is a table comparing the good points of each language. In this first table, one language's advantage can be assumed to be the other's disadvantage.
Eiffel Java
Programming by Contract (assertions) 
  • method preconditions 
  • method postconditions 
  • object invariants 
  • loop check mechanisms 
All popular web browsers comprehend
Java applet byte codes. (the "fun factor")
Parameterized Classes (generics) Noticeably more popular in industry
More stable environment; the kernel
library and the language pretty much
standardized in 1995 except for
multithreading/distributed enablers.
Library of universally available standard
classes is larger (640 vs 50), including
a multithread framework; many other
class libraries are widely available.
Very simple syntax C-like syntax (the "familiarity factor")
Object attributes are read-only,
eliminating the need for accessor
functions.
General feature visibity construct
instead of choices like protected
and public.
renaming of inherited features allows
inheritance of classes that happen to
have features whose names clash
with something else

Controversial Advantages

This table shows a few things that are more a matter of taste.
Eiffel Java
Full support for multiple inheritance
of classes, with feature renaming to
avoid name conflicts, and a simpler,
less error-prone definition of how
class features are merged than
other languages like C++. This
allows design of "mixin" style
classes that contain an abstraction
and a partial implementation.
Multiple inheritance is limited to
interfaces. This prevents the programmer
from employing almost all the ill-
advised uses of multiple inheritance
(Although nested classes undoes
some of this restriction). If the effect of
multiple inheritance is desired, it can be
simulated through delegation with a
slight bit of extra typing and as long as the
parent class has an interface.
Program features can only be accessed
by inheriting or using, as a client,
the class that contains that data.
This reduces the chances of having
hidden "pathological connections"
between modules.
Java allows access to static features via
just the class name. This simplifies the
code in some cases, and eliminates one
of the more confusing uses of inheritance.
Eiffel is largely unknown to incoming
students, thus helping to keep them
from thinking in preconceived
paradigms. It is also hard for them
to find solutions to their assignments
on the internet.
Java is well-known by computer
afficionados, and generally has a
positive reputation. This can be
encouraging and motivating to students.
It is impossible to modify an object's
state from the outside.
You are not forced to write a modifier
function for each attribute if you
don't mind making it public.
Eiffel's exception policy is based at the
routine level. A routine is expected to
have a single goal that it either achieves
or it does not. If it does not, the caller
is notified of that failure. The caller
may not complete successfully without
retrying.
Java's exception policy, like C++'s, is to
have each function list possible exceptions
that may be raised. When an exception is
caught, it is considered handled (unless
rethrown), and the program moves on.

Simple Program Comparison

This should help people to get a feel for syntax differences in very simple programs that the students would likely encounter first. If you want to see bigger, object-oriented programs, search the internet, or our own directories!


Eiffel Version


class HELLO

creation
    main

feature

    main is
        do
            io.put_string( "Hello, world!%N" )
        end
end

Java Version


class Hello {

        public static void main( String args[] ) {
                System.out.print( "Hello, world!\n" );
        }
}