public static void main ( String[] args ) { }
Most of the interesting stuff happens in a GUI (Graphic User Interface) app only after main has exited. The AWT (Advanced Windowing Toolkit) or Swing thread is still alive fielding keypresses and mouse clicks. To stop the application, you need to close all the GUI Frames down or call System.exit().
In Swing you can control this with JFrame.EXIT_ON_CLOSE.
Note that main does not return an int, as do C/C++ programs. In Java, you return an error code with System. exit( n );
The Java run time splits the command line parameters at spaces, except for parameters enclosed in quotes. It preserves the spaces inside the quotes and strips the quotes. The Java runtime treats quotes literally that are preceded by \. The rule seems to be \ is treated literally, except when you have a string of \ before a " then \ means the next \ is taken literally, but if the next character is a " then that quote is taken literally. I have never seen a stranger quoting scheme.
Command Line Quoting Scheme in Windows | ||
---|---|---|
To Get | You must type | Notes |
E:\Program Files | E:\Program Files | You must surround the parameter in quotes if it contains a space. |
E:\Program Files\ | E:\Program Files\\ | You must double a trailing \, but not embedded ones. |
E:\Program Files\\ | E:\Program Files\\\\ | You must double each trailing backslash, but not embedded ones. |
E:\Program Files\\\ | E:\Program Files\\\\\\ | You must double each trailing backslash, but not embedded ones. |
E:\\Program Files | E:\\Program Files | Don’t need to double multiple embedded \s either. |
E:\\\Program Files | E:\\\Program Files | Don’t need to double multiple embedded \s either. |
E:\Program Files" | E:\Program Files\ | Not that you would ever want this. This is what happens if you carelessly have a single trailing \ on your parameter. This is very common in windows. It means a directory. |
a " character | a \ character" | Parameters with embedded quotes must be preceded by a \. |
a \" character | a \\\ character" | to get an embedded literal \ then you need \\\ |
One practical consequence of this is you should do your utmost to avoid a \ at the end of any parameter or set parameter, particularly a path or classpath. The penalty for failing to this will be for example that ant can’t understand any arguments you pass to it because its command line parsing is screwed up by the trailing \ when it mindlessly uses macro expansion of the classpath on its command line.
Unfortunately, trailing backslashes occur frequently in Windows, to describe drives, directories, especially in paths and classpaths. Given that \ is such a frequently used character in Windows it was not a good idea to snaffle it as a quoting character. It would have been better to just double up " I would be curious to find out how command line quoting works on other platforms. If it is the same, the use of \ is not so problematic since on other platforms, / is use in filenames.
This page is posted |
http://mindprod.com/jgloss/main.html | |
Optional Replicator mirror
|
J:\mindprod\jgloss\main.html | |
Please read the feedback from other visitors,
or send your own feedback about the site. Contact Roedy. Please feel free to link to this page without explicit permission. | ||
Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[18.222.164.7] |
| |
Feedback |
You are visitor number | |