[Beowulf] Which is better GNU C or JAVA (for network programing)

Robert G. Brown rgb at phy.duke.edu
Tue Jan 20 08:05:45 EST 2004

On Mon, 19 Jan 2004, prakash borade wrote:

> hey
> 	can anybody tell me 
> what do i choose for programing 
> either GNU c or JAVA  for implementing some
> networkprograms using some linux systemcalls

Gads, that's two questions in two days with the distinct whiff of crowds
of screaming peasants waving swords and torches...

Let it be Jihad, then.

The answer technically is "it depends".  This is to make the vast horde
of java programmers feel loved, and to acknowledge that for writing web
applications their primary scripting language (like perl, python and
many another before it) has a purpose in God's world.

There.  Let us bask for a moment in the serenity of our knowledge that
we have the complete freedom to choose, and that there are no wrong

Now we can give the correct answer, which is "C".

In order to give it, I have to infer an implicit "better than" and a
certain degree of generality in your question is in "which language is
BETTER suited to write an efficient networking program using linux
systemscalls, in GENERAL".

With this qualifier, C wins hands down.  A variety of reasons:

  a) The operating system is written in C (plus a bit of assembler)
  b) Nearly all network daemons and utilities and program clients are
written in C or perhaps an extension of C such as C++
  c) Nearly all decent books on network programming (e.g. Stevens)
provide excellent C templates for doing lots of network-based things
  d) You can do "anything" with C plus (in a few, very rare cases, a bit
of inlined assembler) 
  e) C is a compiler and produces (in the hands of a good programmer) 
code that runs very efficiently.  Java is an interpreter and does not.
  f) C is an open ANSI standard implemented in linux with fully open
source tools with no restrictions or covenants on their usage and with
no "vendors" in any sort of position of control over the language itself
or its core libraries.  Java was invented by Sun, and Sun (AFAIK) still
controls the distribution of its core libraries, and as an interpreted
language, those libraries are sine qua non for portability.  Sun is
relatively linux friendly, but I personally tend not to trust giant
multibillion dollar companies that own core components of something I
need to rely on (or incorporate those components into my code), as they
have an annoying tendency to turn around and want money for it.
  g) Or find themselves imbroiled in a corporate war with someboy ELSE
with deep pockets advancing a different "standard"; for example I'd
guess that Microsoft would like nothing better than to co-opt Java for
themselves and <sigh> turn around and want money for it.  C is co-opt
proof, and GCC is a highly reliable platform upon which to base code in
the certain knowledge that the core compiler and libraries will remain
royalty free.
  h) ...and I could go on.

Note that I do not address java's OO nature, as OO C variants exist AND
as OO programming is largely a matter of programming style, not language
per se anyway.

To conclude with a more ecumenical note because it DOES depend, I should
point out that my acquaintances who code in java seem to be able to
write fairly complex structured programs with the language, and I'd
guess that most posix systems calls are wrapped for use within a java
program as they are in perl and python and etc (I could be wrong, as
java has "sandbox" issues that might well block certain systems calls
from being run at all in which case this is another argument IN GENERAL
for C, although there may well be SPECIFIC cases where it is an argument
in favor of Java).  

Note also that my diatribe above is clearly biased as I don't code in
Java, largely become of all of the reasons above (and then some).
Speed, power, portability, open standard and source, and available code
base and learning support all argue in favor of C about 10 to 1.  UNLESS
you are trying to write a powerful web-distributed application, which is
a PITA in C and what Java was designed for.

Books with good to excellent support for network programming in C:

  W. Richard Stevens, Networking God (deceased):

(pick almost any title, but I like "Unix Network Programming").  Even if
you code in Java, you'll likely want this as I'd bet that Java just
wraps up the C systems calls in interpreted tokens.

  Unix for Programmers and Users, Graham Glass (the current edition is
with King Ables as well, but the older edition is just fine).

  Various websites dedicated to network programming, with examples.
That's what Google is for -- I have the contents of several squirrelled
away already for myself, but the web is amorphous and changes often, so
you'll need to do your own search.

  Any of a LOT of GPL programs that can serve as code templates to get
you started.  xmlsysd/wulfstat, for example, contain templated code for
a network daemon that can run either in forking mode or as an
xinetd-managed daemon plus a client that connects to the daemon.  Glass
and Stevens both have related code snippets (in fact, guess where my
code is derived from).  But there are also a zillion other daemons in
any linux distro, most of them GPL and readily available in source.  I
think you'd have a hard time finding 1/10 as many ready-made examples
(especially ones with highly complex functionality) in Java.



P.S. -- I >>tried<< to be mild, but I suppose I'll need to spend the
rest of the day in a bunker wearing my lead underwear and a tinfoil
skullcap.  Really, I love YAPL's as they pop up from year to year.  I
do.  Marshmellows...ready!  Flame on...

Robert G. Brown	                       http://www.phy.duke.edu/~rgb/
Duke University Dept. of Physics, Box 90305
Durham, N.C. 27708-0305
Phone: 1-919-660-2567  Fax: 919-660-2525     email:rgb at phy.duke.edu

Beowulf mailing list, Beowulf at beowulf.org
To change your subscription (digest mode or unsubscribe) visit http://www.beowulf.org/mailman/listinfo/beowulf

More information about the Beowulf mailing list