Draken said:
From memory ADA also used functions and
procedures. So basically using void defines the difference between a
procedure and a function?
I am not sure what you mean by the "difference between a procedure and a
function", as in Java there are only "methods". However, if by that you mean
that one of them does some work and returns a value (or object), while the
other just does some work and has no return, then you are correct. In Java,
a method which returns something must specify the data type of what will be
returned (i.e. a primitive type for a value or a class for an object);
'void' is thus just a substitute for the data type of nothing.
I realise I made a mistake too, the examples I have seen use "public
static void main (String[] args)" which leads me to ask what the
"String[] args" part is for?
When you call a program, say from a command line, you pass it zero or more
arguments; for example:
java myProgram myFirstArgument 20
In this example, there are two arguments, "myFirstArgument" and "20". The
String[] args is an array which contains all the arguments that you have
passed, plus the name of the program itself (which is stored in the first
position of the array, at args[0].
Since there is no way for the program to initially distinguish what
datatypes the arguments belong to (i.e. it cannot tell that '20' is actually
a number), they are stored into an array of Strings, and the program has to
cast them properly before it can use them.
I don't know about Ada, but Java is a strongly-typed language, and
everything must have an explicitly stated type, either a primitive or an
object type.
HTH,
Berislav