I am not sure what you say when "without complete
implementation". A java library file (jar file), is sufficient
to use it (no need to have the full source code) The javadoc
is usually provided also separately from the code.
How do you create a java library file without the
implementation?
It is sure one can not compile a java program using a library
without the jar file but I don't think this happens often. But
in C++ you need the libraries files - at linking time ok but
you need them - so what is the difference ? (well except if
you want to test compilation, you can do it in java too, just
more work making a dummy jar file)
In large applications, it is usual for client teams to begin
coding (and compiling, but not linking, of course) before the
teams providing the library have finished coding. More
importantly, in large applications, it is usual that the normal
coder cannot check out an exported header file without
authorization; the "interface" (the parts on which client code
depends) is not to be modified lightly.
C++ is far from perfect in this regard, but it still seems to
work better than Java in practice.
As a user you only need to know the interface and what a class
does: this is described in javadoc. A .java file is the
implementation of a class. If you want the definition (as a
user of the class), you use javadoc (no need for a header
file)
I can't compile against Javadoc. And I can't really get the
Java doc until the class implementation is complete, which is
completely backwards. Normally, what's generated by Java doc
should be reviewed before a single line of code is written.
Javadoc is for user of your class. It does not prevent you
from making specification and design documentation before
writing your code. And yes when it comes to detailled design i
write javadoc before code in method.
Yes, but there is still the problem that all of this is in a
single file: the java doc, the class definition, and function
implementations. Ideally, all three would be separate, with the
class definition automatically generated from the doc. Failing
that, putting the doc and the class definition in the same file
is a good compromize. (For the low level documentation, of
course---you still need class diagrams, etc. But there's no
difference between Java and C++ in that regard.) But in a large
project, it is very important to keep the parts on which client
code depends (i.e. the class definition) separate from the
implementation details (the function internals). The
responsibility for each lies in different hands.
That is wrong. I suppose you are thinking in the CLASSPATH
environment variable which may be set in a user enviroment.
When you provide a java program, you also provide the way to
launch it (for exemple a batch file) in which you specify the
classpath *you* want. Put the classpath to libraries bundled
with your binaries, and you be sure your program will work.
In other words, you need an external tool. In some cases, this
is true for C++ as well, but in simple cases, you just
distribute a single executable file, and that's it. It makes
deployment a lot simpler. Of course, in many cases, you can
also just distribute a single jar file. But you run
significantly more risks than with a statically linked
executable.
Obviously, you pay for this with a lack of flexibility: my
statically linked executable (generated on a Sun Sparc, under
Solaris) may not run on your machine (if your machine is a PC
under Windows, for example). Your JAR file will. Provided the
user is careful with the versions of the JVM he uses, and what
he does with CLASSPATH. For some applications, the added
flexibility is worth the risks, for others, the risks aren't
acceptable, and the flexibility isn't needed.
Note that formally, this really doesn't depend on the language.
The C++ standard certainly allows implementations along the
lines of what Java does, and I think you could also create a
Java implementation which partially linked statically (and would
not link in anything which wasn't "pre-linked" statically). In
practice, however, I've never heard of either.
Classpath had been a problem for a lot of people in the early
years of java because it was new (when you think of it now, it
ist obvious)
In other words: it's a problem, but time has provided the
work-arounds, and made them common practice. (We've got a lot
of those in C++ as well.)
Static linking is not perfect otherwise there would not have
been dynamic libraries; dynamic libraries is not perfect:
often you have to provide your own copy to be sure to be
compatible. This is not a java problem.
Not per se, but the Java language definition does encourage
implementations to dynamically load each class. (The runtime
has to behave "as if" the class wasn't loaded until the specific
runtime event that would have triggered the load.) And the
usual implementations do. Where as the usual C++
implementations (at least on the platforms I work on: Solaris
and Linux) generate static libraries by default. (FWIW: even in
C++, I think dynamic loading is used much more than it should
be.)
[...]
Well i guess the documentation was not accurate enough if it
did not mention that if overrided the method should not return
null.
I don't think it mentionned it, but I think the specified
semantics of the program made it more or less implicitly clear.
The problem is that we didn't return null intentionally. We
returned a variable which had been initialized by the
constructor. The constructor which hadn't been called.
Bad use or design of classes is not a java specific problem.
Allowing the call of a virtual function to go through to a class
whose constructor has yet to be called is bad design in the
language itself. Calling a virtual function in the constructor
of a base class is probably bad design as well---in this case,
in the Java standard library. (But to be fair, Swing is,
globally, a lot better than any of the C++ GUI libraries I've
seen.)
The real point, of course, is that Java and C++ are distinctly
different languages, designed with different goals in mind.
Most of my work in on large scale, more or less critical
servers, and the design criteria of Java make it inappropriate
here. For the server itself---it's the language of choice for
GUI based administrator clients, for example.