20-CS-694 Advanced Programming Techniques Spring 2012
Runtime

Interfaces, Exceptions, Graphics, Animation, Threads, Reflection, Networking, RMI, JDBC, JNI

All lectures
Execute Command, Garbage Collection, ...

Instructions for applets:

   First one: enter a command in the JTextField then hit 'Run It'. Second one: hit 'Run It'.

Documentation:

   Runtime class

    1.   B.java

    Runs a command and displays the result. The line that executes the command is
 InputStream is = 
    Runtime.getRuntime().exec(cmd.getText()).getInputStream();
and the line that displays the result is
 while ((str = br.readLine()) != null) area.append(str+"\n"); 
 
    2.   C.java

    Display the status of memory, then perform a garbage collection, then display the status of memory. The commands that get memory status are these:
  Runtime.getRuntime().totalMemory()
  Runtime.getRuntime().freeMemory()
The line that garbage collects is this:
 Runtime.getRuntime().gc();