Dec 02

We talked about classpath earlier in context with compilation.

Today I would like to give some additional hints and tipps:

  • in case a classpath is given, the given folder and all folders below will be searched through. Folders above the classpath will be not regarded.
  • with set CLASSPATH=<path> the default-folder will be set. This path will be searched through in case no classpath is given
  • in current path search is done with ‘.‘ in case classpath is not set with set CLASSPATH=.
  • It will always the first found appropriate class-file used. In case  there are further appropriate class-files in the folder below, they will be ignored.
  • The search-order is strict due to the given order of folders and their subfolders, eg -classpath C:/Angestellter:.:C:/Buchhalter the search-order is
    • C:/Angestellter and sub folders
    • . (current path) and sub folders
    • C:/Buchhalter and sub folders
  • instead of -classpath the short form -cp can be written on most of the engines

Please keep in mind that I used unix-convention (since more often checked in SCJP). In windows : need to be replaced with ;  eg for dividing the single classpaths

Nov 30

While program execution parameters can be passed which the program is picking up. Let’s take – as usual – an example;

Program Test has the following code:

public class Test{

public static void main(String args[]) {

for (String s:args)




Starting the program with

java Test 1 2 3

leads to the Output:


String args [ ] is overtaking the passed values.

Declaration of main public static void main(String args[]) is not the one and only valid one. Others may be as well suitable, e.g.

public static void main(String … x)

static public main (String [ ] y)

static public void main (String [ ] y)

Tagged with:
Nov 28

with -D system-properties can be set for execution:

java -D<variable-name>=<property-value> <main class>

or with example-values

java -DmyValue=my Test

So we have set the system property “my Value” with the value “my” for the run of Test created. It is also possible to have values with spaces (e.g. my and yours). Therefore you have to set the String in quotes:

java -DmyValue=”my and yours” Test

If preferred those system properties can be set directly in code. The responsible class is java.util.Properties:

Properties p = System.getProperties();
//system property myValue get the value “my”

You can even list all system properties with


A single value can be retrieved with

System.out.println( p.getProperty(“myValue”));

Tagged with:
Nov 26

As already explained a program is started with

java <filename> oder java <option> <filename>

One Option as already explained in context with assertions (and already mentioned several times in recent posts) is option -ea to enable assertions and therefore can be used. The opposite to this is -da to disable them.

With java -help more options are shown.

Tagged with:
preload preload preload Blog Top Liste - by Blogverzeichnis - Blog Verzeichnis Software
Webbhotell Top Blogs