What does the zeroth element of the string array passed to the publicstatic void main method contain

T

Tom Anderson

Or have written a command-line program once in our lives. There are
nooks and crannies of Java which have unexpected behavior; this isn't
one of them, unless you're a C/C++ programmer

Or shellscript - $(dirname $0) FTW! - or perl, or python, or ...

I agree entirely that this is not a difficult feature of java. I do often
wonder about it, though. On the one hand, i like it, because the program's
name is not usually at all interesting (and not even all that meaningful a
concept in java, where you invoke 'java' and pass a classname, which you
know statically inside main, as an argument), and the traditional unix way
means you effectively have a 1-based array to deal with, which is ugly. On
the other hand, it's a difference to every other language on the planet.
Oh well, not exactly a big deal.

tom
 
M

Martin Gregorie

I agree entirely that this is not a difficult feature of java. I do
often wonder about it, though. On the one hand, i like it, because the
program's name is not usually at all interesting (and not even all that
meaningful a concept in java, where you invoke 'java' and pass a
classname, which you know statically inside main, as an argument), and
the traditional unix way means you effectively have a 1-based array to
deal with, which is ugly. On the other hand, it's a difference to every
other language on the planet. Oh well, not exactly a big deal.
The program name is (potentially) another useful argument, though this
use seems to have rather fallen into disrepute

For instance, vi, ed and sed were at one time (and maybe still are on
some *NIXen) all hard links to the same binary.

Linux has separate binaries for vim, ed and sed while vi is a symlink to
vim - at least Fedora 9 does it that way and I guess the same applies to
other distros.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top