ShutDownHook allows you to perform operations (e.g. close opened resources, remove temporary files and so on) just before virtual machine shuts down. A documentation says that JVM may shut down in two cases: program finishes execution normally when all threads finishes their work (except deamon-threads like garbage collector) virtual machine receives a termination signal (for example after sending kill signal under unix or ctrl + C key combination under windows) Below is an example which will start endless loop which do nothing. But an important thing in this code is a part where shutDownHook is added. When an termination signal will be send to JVM a code from a run() method will be executed just before JVM shuts down. public class ShutDownHook { public static void main(String[] args) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { System.out.println("Close opened resources"); } }); while (true) { // do nothing } } }
javac used to compile source files (*.java) javac [-options] files java used to run a compiled code (*.class) java [-options] class [args...] jar used to archive files into JAR (*.jar) jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files In practise: Source for Hello.java package com.blogspot.programmerutilities; public class Hello { public static void main (String[] args){ System.out.println("Hello World!"); } } Location of the file: \src\com\blogspot\programmerutilities\Hello.java Directory structure: -src -com -blogspot -programmerutilities -Hello.java -build Compile source file using javac (-d option points to a directory where compiled files will be placed) javac -d build \src\com\blogspot\programmerutilities\Hello.java After compilation a Hello.class file will be placed in \build directory (and subdirectories accordingly to the package name). -src -com -blogspot -programmerutilitie...
Comments
Post a Comment