The Platform Environment: Commentary

Steven Zeil

Last modified: Aug 19, 2016
Contents:

****

This section describes Java’s facilities for getting access to info about the machine on which the Java virtual machine is really running.

1 Configuration Utilities

1.1 Properties

1.2 Command-Line Arguments

This is very similar to C++. The Java code:

public class Echo {
   public static void main (String[] args) {
	  for (String s: args) {
		 System.out.println(s);
	  }
   }
}

can be compared to the C++:

int main (int nArgs, char** args) {
   for (int i = 0; i < nArgs; ++i) {
      cout << args[i] << end;
   }
   return 0;
}

The main function in C++ gets two arguments instead of one. The first argument indicates how many command line parameters are supplied in the args array. Java does not need this info to be passed spearately, because Java arrays “know” their own length. The main content in both languages is an array of strings. In C++ these are “old-fashioned” C-strings (char*) with the second asterisk indicating that this is an array.

One difference worth noting however. In C++, position zero of the array contains the name of the program as supplied on the command line. Hence, if we run the programs, the first line of output will be different:

> java Echo I am here
I
am
here
> ./cppProgramName I am here
./cppProgramName
I
am
here

1.3 Environment Variables

1.4 Other Configuration Utilities

2 System Utilities

2.1 Command-Line I/O Objects

2.2 System Properties

2.3 The Security Manager

2.4 Miscellaneous Methods in System

3 PATH and CLASSPATH