Sunday, 30 November 2008
Property Management in Java (-D option)
System.getProperty is a static method on the System class that takes a (String) key and returns a (String) value. Standard system properties include java.home (where Java is installed) and java.class.path (the Java classpath) and os.name and os.version.
System properties are set on startup using the -D<key>=<value> option. These properties may need to be set in a launch script to a Java program.
Properties can also be maintained in an external file. Then you call System.getProperties to get a reference to the Properties object (that inherits from Hashtable). The Hashtable methods put and putall can be called on the object but their use is strongly discouraged in favour of the method setProperty which allows you to set String keys and values (i.e. it enforces a type-constraint on the keys of the Properties object).
Properties can be maintained in an external file and then setProperty can be used to add them to the application's properties table. Some people like to write singleton managers for properties so access can be centralised and controlled (and type-constraints enforced) for System properties.
System properties are set on startup using the -D<key>=<value> option. These properties may need to be set in a launch script to a Java program.
Properties can also be maintained in an external file. Then you call System.getProperties to get a reference to the Properties object (that inherits from Hashtable). The Hashtable methods put and putall can be called on the object but their use is strongly discouraged in favour of the method setProperty which allows you to set String keys and values (i.e. it enforces a type-constraint on the keys of the Properties object).
Properties can be maintained in an external file and then setProperty can be used to add them to the application's properties table. Some people like to write singleton managers for properties so access can be centralised and controlled (and type-constraints enforced) for System properties.
The Idiosyncracies of the Java VM Shutdown Sequence
JVM shutdown is in two parts.
- All registered shutdown hooks
- All uninvoked finalizers are run
Runtime.getRuntime().addShutdownHook(Thread) registers a new VM shutdown hook.
A shutdown hook is simply an "initialized but unstarted thread". When VM shuts down, it starts all shutdown hooks and runs them concurrently. Then it will run all uninvoked finalizers(assuming finalization-on-exit has been enabled).
Once shutdown has been initiated it can only be stopped by invoking the halt method, to forcibly terminate the JVM. halt has one argument which is status code. Any non-zero value indicates abnormal termination.
Read more in the Runtime (singleton) class documentation below:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
Wednesday, 26 November 2008
Java and Eclipse Shortcuts
Eclipse
Cntrl-Shift-T find Type
Cntrl-L Goto line
Cntrl-B Build
F3 jump to definition
Alt-Enter - File properties (file path, size, file encoding)
Set up different workspaces for "test projects" versus "real projects".
Configuring Eclipse to reference Existing Code
1. Set up a new workspace (different from the source location)
2. use the existing location for the code
3. create projects for specific parts of the code you want to change
Select "autoconfigure JRE and project layout based on source".
Switching Tabs in Eclipse
Control-Tab in Windows applications is replaced by ALT-LEFT and ALT-RIGHT, and Control-F6. Since control-tab is used so frequently it is easy to forget this Eclipse peculiarity.
To override this shortcut, do Windows->Preferences->General->Keys. Then replace "Change Next Editor" from Control-F6 to Control-tab. Sanity at last.
Cntrl-E is another useful way to bring up "Editor List" that allows explicit window switching.
Java
javap -c Disassemble a class file
Cntrl-Shift-T find Type
Cntrl-L Goto line
Cntrl-B Build
F3 jump to definition
Alt-Enter - File properties (file path, size, file encoding)
Set up different workspaces for "test projects" versus "real projects".
Configuring Eclipse to reference Existing Code
1. Set up a new workspace (different from the source location)
2. use the existing location for the code
3. create projects for specific parts of the code you want to change
Select "autoconfigure JRE and project layout based on source".
Switching Tabs in Eclipse
Control-Tab in Windows applications is replaced by ALT-LEFT and ALT-RIGHT, and Control-F6. Since control-tab is used so frequently it is easy to forget this Eclipse peculiarity.
To override this shortcut, do Windows->Preferences->General->Keys. Then replace "Change Next Editor" from Control-F6 to Control-tab. Sanity at last.
Cntrl-E is another useful way to bring up "Editor List" that allows explicit window switching.
Java
javap -c Disassemble a class file
Friday, 21 November 2008
Power of JFlex and CUP in Combination: LALR PArsers for Java
As a Java open source junkie you will have almost certainly have heard of JFlex and CUP but not really delved deeply into it, right? Here's a rapid sommaire of the two technologies.
Classgen is a related technology from the Technical University of Munich. It generates classes in the Visitor style. This page gives a good idea of what specifications look like in Classgen and what it can do. The whole area of creating computer programs based on computer specifications is extremely fascinating. Let the computers do all the hard programming and let humans customize the color schemes of the resulting software.
- JFlex (a rewrite of JLex) is known as the "fast scanner generator for Java".
- CUP (no, not Cambridge University Press, but "Construction of Useful Parsers") is an LALR parser generator for Java. Rusty on ye olde Dragon Book basics? To remind you, LALR is lookahead LR parsing. LR parsing means the parser reads the input Left to right, and produces a Right-most derivation (LR is a general form of shift-reduce parsing, starting from the leaves of a tree and working up to the root - in computer science trees grow downwards from the root!). When referring to LALR(k) the k is the lookahead value. LALR is quite popular since it results in smaller parsing tables than canonical LR tables (Dragon Book Ch4, Syntax Analysis).
Classgen is a related technology from the Technical University of Munich. It generates classes in the Visitor style. This page gives a good idea of what specifications look like in Classgen and what it can do. The whole area of creating computer programs based on computer specifications is extremely fascinating. Let the computers do all the hard programming and let humans customize the color schemes of the resulting software.
Speed Reading Java Open Source Code
Requires more than a passing knowledge of Java knowledge, APIs and standard open source components (par exemple, gnu.getopt).
Monday, 17 November 2008
Navigating Ganymede using Awesome Child-Oriented Fonts like Comic Sans - Makes Reading Java More Fun!
Making your way around Eclipse ain't easy when you're used to MSVC-style GUIs, so here's a primer on how to get things configured double-speedy in the old Ganymede release of Eclipse.
Change Font Size. This should not be difficult but for first-timers it's a super-sized sudoku puzzle.
Windows->Preferences->General->Appearance->Colors and Fonts. Click on the right category e.g. Java editor text font. Set a good font and size. Changing your font regularly keeps code-reading interesting.
Change Font Size. This should not be difficult but for first-timers it's a super-sized sudoku puzzle.
Windows->Preferences->General->Appearance->Colors and Fonts. Click on the right category e.g. Java editor text font. Set a good font and size. Changing your font regularly keeps code-reading interesting.
- Jokeman is a fun font to liven up boring code.
- Kartika9 is very clear and well-spaced.
- Vivaldi is beautiful and elegant but suffers from lack of readability.
- Mistral makes Java look beautiful.
- ComicSansMS is a nice, friendly readable font, classified as "casual, non-connecting script", a "child-oriented font" in the words of its inventor, Vincent Connare, who designed it for children's software. To quote an esteemed computer philosophe, "The real art of discovery consists not in finding new programming languages, but in seeing with new fonts".
- Gill Sans MT is another "soft font" described as a "humanist" font, created by Eric Gill in 1927 and very popular in logos for media companies (e.g. BBC). Eric Gill received the accolade "Royal Designer for Industry" (Gill9 looks fine).
Show Line Numbers: W->P->G->Editors->Text Editors->Show line numbers
Saturday, 4 October 2008
Web Start and Click Once in Web Application Fisticuffs
Presenting Click Once, dubbed Microsoft's "Webstart rip-off", but actually looks smoother and more shiny than Web Start:
http://decav.com/blogs/andre/archive/2007/08/25/live-updating-line-graph-in-wpf.aspx
http://decav.com/blogs/andre/archive/2007/08/25/live-updating-line-graph-in-wpf.aspx
Subscribe to:
Posts (Atom)