Operational Systems & Java
 If there is a way to run a java program by just typing the name in UNIX. I mean
instead of typing for example "java Main" just type "Main" and run the program. And
how to implement that in a makefile?
Answer:  Write a script that runs the program and put it in your path. For
instance:
#!/bin/sh
java BlahBlah
Call this whatever you want, mv it to your /usr/local/bin directory, then just type it at
the command line and BlahBlah will be run.
Q: Are there any Java libraries for executing Linux commands? 
Answer:  Try java.lang.Runtime.exec(). E.g.
Runtime.getRuntime().exec("xterm"); 
Note if you want to use shell builtins or shell features like
redirection you need a shell, e.g.:
Runtime.getRuntime().exec(new String[] {"/bin/sh", 
                                " c", "ls / 2>&1 | tee ls.log"});
I d like to know how to know which operating system java application is running
on.
Answer:  You could try using the system Properties. 
e.g.
Properties prop = System.getProperties();
String osString = prop.getProperty( "os.name" );
I would like to know how my Java program can catch when someone sends a
"kill" to my app in Unix or does a Ctrl C in windows?
In Unix there is atexit() function that handles this type of situation. Is this possible in
Java ?
Answer:  Starting with 1.3 there is Runtime.addShutdownHook(). This is for cleanup
only. 
from API: "A shutdown hook is simply an initialized but unstarted thread. When the
virtual machine begins its shutdown sequence it will start all registered shutdown
hooks in some unspecified order and let them run concurrently. When all the hooks
have finished it will then run all uninvoked finalizers if finalization on exit has been
enabled. 
Finally, the virtual machine will halt. Note that daemon threads will continue to run
during the shutdown sequence, as will non daemon threads if shutdown was initiated
by invoking the exit method. Once the shutdown sequence has begun it can be
stopped only by invoking the halt method, which forcibly terminates the virtual
machine.
Once the shutdown sequence has begun it is impossible to register a new shutdown
hook or de register a previously registered hook. Attempting either of these
operations will cause an IllegalStateException to be thrown. 
file:///F|/a_jsite/350_tips/os_win_linux.htm (4 of 8) [2001 07 08 11:24:58]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved