tag:blogger.com,1999:blog-64590303667292358212024-03-08T18:28:07.219+00:00Are We There YetI'm the CEO (was CTO) of jClarity (www.jclarity.com) - a new Java/JVM performance analysis company! You'll find a vast majority of my recent blog posts there (http://www.jclarity.com/blog). This is my infrequent personal blog with mad musings on travelling, IT (Java and Open Source in particular) and anything else that wanders its way into my head.Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.comBlogger30125tag:blogger.com,1999:blog-6459030366729235821.post-79515935574388876222013-01-14T14:18:00.000+00:002013-11-25T17:22:51.540+00:00A Garbage Collection Analysis of PCGen, the popular Open Source Character Generator<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<h2 class="western">
Introduction</h2>
<div style="margin-bottom: 0cm;">
I decided to combine two software loves
of mine and perform some analysis on <a href="http://pcgen.sf.net/"><span style="color: #1155cc;"><u>PCGen</u></span></a>,
a popular Java based open source character generator for role-playing
games. I used <a href="http://www.jclarity.com/products/censum"><span style="color: #1155cc;"><u>Censum</u></span></a>,
our (<a href="http://www.jclarity.com/"><span style="color: #1155cc;"><u>jClarity</u></span></a>'s)
new Garbage Collection log analysis tool to perform the analysis.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
This write-up assumes you have a
passing familiarity with Garbage Collection (GC) on the JVM. If
you're not familiar with GC then I recommend you join our <a href="http://www.jclarity.com/friends"><span style="color: #1155cc;"><u>Friends
of jClarity programme</u></span></a>. We're building up a knowledge
base around GC to share freely with the whole Java community, we'd
love for you to come and validate this!</div>
<h2 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.7jmt0dp0ftvz"></a>The projects</h2>
<div>
The two projects I'm using are are PCGen (the project I'm doing the analysis on) and Censum (the GC analysis tool).<br />
<br /></div>
<h3 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.kqw23l5fh64a"></a>PCGen</h3>
<div style="margin-bottom: 0cm;">
<span style="color: #1155cc;"><br /></span>
<span style="color: #1155cc;"><u><a href="http://pcgen.sf.net/">PCGen</a></u></span>
is a popular character generator and maintenance program for d20 role
playing systems such as Star Wars and Dungeons & Dragons. It's a
long running project (> 10 years) and consists of a large
(~750,000 LOC) Java Swing desktop tool that has a ton of proprietary
format data files. Disclaimer: I'm the Chairperson for PCGen.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1Z6WHmUznTsl07irv42zBjLsX_cCs5C3n" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1Z6WHmUznTsl07irv42zBjLsX_cCs5C3n" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
<span style="line-height: 100%;">PCGen is a data
intensive tool. In order to drive its rules engine and to meet the
requirement of a responsive UI (with lots of detail) much of this
data is loaded up front and held in memory. Users have reported the
following issues in the past.</span></div>
<ol>
<li><div style="line-height: 100%; margin-bottom: 0cm;">
Pauses often
occur when dealing with multiple characters and/or high level
characters.</div>
</li>
<li><div style="line-height: 100%; margin-bottom: 0cm;">
When creating a
character of a high level or if more than 2 characters were created,
PCGen simply died. More tech savvy users report that they saw an
<span style="font-family: Courier New, serif;">OutOfMemoryError</span> in the pcgen
log file.</div>
</li>
</ol>
<div style="line-height: 100%; margin-bottom: 0cm;">
<span style="line-height: 100%;">Some work has been
done to mitigate this poor performance in the latest version of PCGen
(6.0) and so I decided to use Censum to determine if those changes
had improved matters.</span><br />
<span style="line-height: 100%;"><br /></span></div>
<h3 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.1d1co989xcfa"></a>Censum</h3>
<div style="margin-bottom: 0cm;">
<span style="color: #1155cc;"><br /></span>
<span style="color: #1155cc;"><u><a href="http://www.jclarity.com/products/censum">Censum</a></u></span>
is jClarity's new Garbage Collection analysis tool. It's focus is to
use powerful analytics to crunch through the raw log data and give
busy developers (like contributors to PCGen!) plain english answers
quickly. Disclaimer: I'm the CTO of jClarity.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1ZKQhzZJ79G4RzKXBbt5kLlry5hNMZrZL" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1ZKQhzZJ79G4RzKXBbt5kLlry5hNMZrZL" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
Censum is a new product that is free
for Open Source projects and of course if you wish to
purchase a copy you can get a free <a href="http://www.jclarity.com/censum"><span style="color: #1155cc;"><u>trial
license</u></span></a> (click on <i>Start Your Free Trial</i>) today!</div>
<h2 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.ol96i6eunnc2"></a>TLDR - The
Conclusion</h2>
<div>
We have good news, some information and bad news.<br />
<br /></div>
<h3 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.1n0c6srfj8r4"></a>The Good News</h3>
<div style="margin-bottom: 0cm;">
<br />
The positive news is that the default
heap settings that PCGen starts with (<span style="font-family: Courier New, serif;">-Xms256m
-Xmx512m</span>) are now adequate in terms of being sized well enough
to keep PCGen running. Even after creating a 5th complex character,
there was no <span style="font-family: Courier New, serif;">OutOfMemoryError</span>.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
Censum shows that once a full GC is run
(typically after each new character has been created), a large
percentage of the heap is recovered and each the character takes up
about 25-50MB of heap space. We can very roughly extrapolate that
with a starting (data loaded) point of ~125MB that PCGen can
comfortably hold about 10-15 characters open at any one time without
crashing. This is perhaps not enough for a GM to have his Goblin
horde up and running, but certainly enough for most regular parties!<br />
<br /></div>
<h3 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.vlsxd8axx1oz"></a>The Bad News</h3>
<div style="margin-bottom: 0cm;">
<br />
The slightly more negative news is
Censum reporting that PCGen has relatively high pause times, likely
triggered by too much premature promotion.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
Too much premature promotion pushes
memory into the old gen space more quickly that we'd like. This can
have the knock-on effect of causing more old gen collections as well
as full GCs, naturally leading to more pause times.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
See the full analysis section for extra
details on high pause times, premature promotion and what PCGen can
do about it.<br />
<br /></div>
<h3 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.r80fmli5sq8f"></a>Where to from here?</h3>
<div style="margin-bottom: 0cm;">
<br />
PCGen could follow Censum's "stop-gap"
recommendation to alter the size of the young generational space. By
using the <span style="font-family: Courier New, serif;">-XX:NewSize</span> flag and
setting that to ~256M, the high pause times problem is alleviated.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
However, the longer term solution is
for PCGen to continue reducing the impact of their data structures
(in particular the representation of a player character). This is in
fact an ongoing project for PCGen today!</div>
<h2 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.nt7hjmk6ee9t"></a>The technical setup</h2>
<div style="margin-bottom: 0cm;">
PCGen is typically run from a shell
script with the default heap settings of <span style="font-family: Courier New, serif;">-Xms256m</span>
and <span style="font-family: Courier New, serif;">-Xmx512m</span>. The script was
altered to provide the minimum set of flags that are required to
produce GC log that can be analysed. The flags that were added to the
<span style="font-family: Courier New, serif;">java</span> command were:</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm; text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">-verbose:gc
-Xloggc:pcgen_gc.log -XX:+PrintGCDetails
-XX:+PrintTenuringDistribution</span></div>
<ul>
<li><div style="margin-bottom: 0cm;">
<span style="font-family: Courier New, serif;">-verbose:gc</span>
and <span style="font-family: Courier New, serif;">-Xloggc:pcgen_gc.log</span>
produce a basic log that outputs to a file called <i>pcgen_gc.log</i>.</div>
</li>
<li><div style="margin-bottom: 0cm;">
<span style="font-family: Courier New, serif;">-XX:+PrintGCDetails</span>
provides the absolute minimum set of GC allocation information that
Censum needs to perform an analysis.</div>
</li>
<li><div style="margin-bottom: 0cm;">
Finally
<span style="font-family: Courier New, serif;">-XX:+PrintTenuringDistribution</span>
gives useful information on when objects are moving from a young
generational space (eden, survivor 1 and survivor 2) to an old
generation space (tenured).</div>
</li>
</ul>
<div style="margin-bottom: 0cm;">
All of these options have little to no
impact on a running JVM. You should always have these switched on in
Production!</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
PCGen was run with Oracle's Java 7u10
on a MBP running Mac OS 10.7.5, with 8GB of RAM, a 256MB SSD drive
and a hyperthreaded Dual Core 2.8Ghz i7 processor.</div>
<h2 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.7bp6ten0nwgk"></a>The PCGen activities</h2>
<div style="margin-bottom: 0cm;">
PCGen begins by loading up basic game
mode and system files + the basic UI to load data sources. The next
step is for the user to select which data sources to load
(roleplaying game rule sets). The popular <i>SRD 3.5 with Monsters</i>
set was loaded (Dungeons and Dragons 3.5e).</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
A Character (<i>Karianna</i>) was
created level by level into a 20th Wizard with fully loaded spells,
equipment, and a Cat familiar (effectively a 2nd character in PCGen).
Several more complex characters were added after that, including a
Great Wyrm Blue Dragon (loads of data!).</div>
<h2 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.j8sdlgvaa87i"></a>Analysis</h2>
<div>
I'll cover the initial data loading use case and then general on going usage (character creation).<br />
<br /></div>
<h3 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.vjylpi7ny7jq"></a>Data Loading</h3>
<div style="margin-bottom: 0cm;">
<br />
I was curious about the memory impact
of the initial data load. Although I get fast loading times with my
SSD drive having PCGen load its data without memory problems is
certainly a project goal! Here is what Censum showed in terms of heap
allocation after GC's.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1DKgQqebxxnZuvxkqHjyJOfn5XmPkQY2E" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1DKgQqebxxnZuvxkqHjyJOfn5XmPkQY2E" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
As you can see, the initial load of
data caused a number of young generational collections and one old
(tenured) GC event at the end of the data load. The heap usage
climbed to a max of about <span style="font-family: Courier New, serif;">325MB</span>,
but after garbage was collected, the heap usage fell back to about
<span style="font-family: Courier New, serif;">100MB</span>. Not too bad for loading
about 15 thick rule books worth of data!</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
However, data loading for PCGen is a
little like the start-up period for an web/application server such as
Tomcat. In terms of your GC analysis it's generally best to be
excluded as part of a one-off start-up as opposed to analysing your
running application.<br />
<br /></div>
<h3 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.4neiqm90f6fh"></a>Creating characters</h3>
<div style="margin-bottom: 0cm;">
<br />
Creating Karianna and advancing her to
20th level involves filling in details of 13 main tabs ~20 sub tabs
and a good deal of data! Another 4 characters were created of similar
complexity, some friendly (a Cat familiar) and some not (a Great Wyrm
Blue Dragon).</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
A few screenshots of the process
follow:</div>
<h4 style="text-align: left;">
<b>Skills</b></h4>
<div style="margin-bottom: 0cm;">
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=11bSAdBPw8RDIJLJZeWl_1L3lWqHMJz-j" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=11bSAdBPw8RDIJLJZeWl_1L3lWqHMJz-j" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
<b><br /></b></div>
<div style="margin-bottom: 0cm;">
</div>
<h4 style="text-align: left;">
<b>Equipment</b></h4>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=16_NhOzQ6PGIBJlYaJTUEp0JAtY3GQ6uN" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=16_NhOzQ6PGIBJlYaJTUEp0JAtY3GQ6uN" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
<b><br /></b></div>
<div style="margin-bottom: 0cm;">
</div>
<h4 style="text-align: left;">
<b>The Embedded Character Sheet</b></h4>
<div style="margin-bottom: 0cm;">
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1_6LzMsZenJU2JZFhTCWgDw8Bm3zMEaNp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1_6LzMsZenJU2JZFhTCWgDw8Bm3zMEaNp" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
</div>
<h2 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.knip13jc4o1y"></a>Censum's Analysis</h2>
<div style="margin-bottom: 0cm;">
On opening the log file, Censum took me
immediately to its Analytics Summary screen, which lets me know at a
glance as to how PCGen's garbage collection is going.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1IDOoXYVv0DBco15AQgBsTP9wmrz-9HfX" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1IDOoXYVv0DBco15AQgBsTP9wmrz-9HfX" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="margin-bottom: 0cm;">
</div>
<h3 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.51jhzwps872d"></a>The good news</h3>
<div style="margin-bottom: 0cm;">
<br />
Immediately I know that:</div>
<ol>
<li><div style="margin-bottom: 0cm;">
I have the right flags to collect
enough GC data for analytics to work properly</div>
</li>
<li><div style="margin-bottom: 0cm;">
My GC throughput is good (PCGen
spends it's time running, not garbage collecting)</div>
</li>
<li><div style="margin-bottom: 0cm;">
There are no nasty <span style="font-family: Courier New, serif;">System.gc()</span>
calls (generally not good practice).<br />
<br /></div>
</li>
</ol>
<h3 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.fi0ietd6927f"></a>The informational
news</h3>
<div style="margin-bottom: 0cm;">
<i><br /></i>
<i>Memory Utilisation</i> (which a
memory leak is a subset of) and <i>Memory Pool Sizes</i> are
informational as the log has not yet gathered 24 hours of data (our
recommended minimum to see a full working day's cycle for an
application).<br />
<br /></div>
<h3 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.h6hbuh8a8vvw"></a>The bad news</h3>
<div style="margin-bottom: 0cm;">
<br />
PCGen appears to have high pause times
as well as a premature promotion problem. Let's dive into those a bit
further!<br />
<br /></div>
<h4 style="text-align: left;">
<b>High Pause Times</b></h4>
<div style="margin-bottom: 0cm;">
High pause times are caused by GC
collectors having to pause application threads in order to clean up
object references in a safe manner. The more object references that
the collectors have to scan over and clean up, the longer the pause!
The longest pauses are usually caused by full GC collections, where
the entire Java Heap (e.g. Both young and old gen spaces are getting
really full) are cleaned up.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
As a user I noticed pauses a couple of
times, not enough to really disturb me, but I am aware that I have
extremely good hardware and that these pause times may be
significantly worse for other users.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1RbRkwhS5_erlr3YzWsDMjptvCq9x2f5B" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1RbRkwhS5_erlr3YzWsDMjptvCq9x2f5B" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
As Censum points out, the 0.15% time
spent paused is not a major concern, it's the 0.666 second pause time
that's concerning. However, I remembered that the highest pause time
could come from the initial data load in PCGen. To correlate this,
Censum provides a graph of pause times.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1I46n8rbQdILiWs8kTaV2G4QtAcO66IPN" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1I46n8rbQdILiWs8kTaV2G4QtAcO66IPN" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
The data load was the worst offender,
but certainly for each character created there was a good ½ second
pause around each character creation point due to a full GC. Again ½
a second wasn't too annoying for me in the context of using PCGen,
but as Censum shows, full GCs take time and so PCGen should look to
reduce the number of full GC's.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
In this case we know that we are
probably getting more full GC's than we'd like due to the other
warning that Censum gives us - too much premature promotion.</div>
<h4 style="text-align: left;">
<b>Premature Promotion</b></h4>
<div style="margin-bottom: 0cm;">
Premature promotion basically means
that objects that should be getting collected in the young gen space
are being promoted into the old gen space before their age is up.
This 'age' is known as the tenuring threshold, and is based on a
combination of software research done in the 1980's and the JVM's
runtime heuristics. Premature promotion can occur due to:</div>
<ol>
<li><div style="margin-bottom: 0cm;">
The rate of new objects being
created overwhelming the young gen space</div>
</li>
<li><div style="margin-bottom: 0cm;">
The size of the objects being
created are too large to fit into the young gen space. e.g. Large
contiguous blocks of memory.</div>
</li>
</ol>
<div style="margin-bottom: 0cm;">
This has a knock on effect of putting
pressure on the old gen space. It fills up more quickly and therefore
more old gen collections and eventually full GCs occur, leading to
more frequent pause times.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=17rEMKP75hOZNJ7yuwc5b2fnduRMEnabJ" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=17rEMKP75hOZNJ7yuwc5b2fnduRMEnabJ" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
When I go to take a look and see how
soon objects should be promoted and how early they are getting
promoted, I get an answer immediately. The Tenuring Summary screen
shows us that the Tenuring threshold is set to 15 (objects can
survive ~15 collections in young gen before being promoted naturally
to old gen). Note also that 100% of objects are being prematurely
promoted!</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1qlH5m23USEc5E-8Rev9N6yduhwFNrghg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1qlH5m23USEc5E-8Rev9N6yduhwFNrghg" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
I then go and look and see when objects
are being promoted. Censum tells me that as majority are being
promoted almost as soon as they arrive in young gen (Tenuring
Threshold of 1). That value indicates to me that the arriving objects
are too large for the current young gen size. However, I double check
and make sure object allocation isn't extremely high, Censum tells me
that object allocation peaks at about 2.5GB/s, which is only about ⅔
of the capability of my MBP, so we're OK there.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1NsW0n8gbOeM78D5_U1F4TaGCMrcCMjkX" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://docs.google.com/document/d/1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E/pubimage?id=1arqk-D_duJXoizBNJXpL1r1swrDkG7DZEletw9jAw_E&image_id=1NsW0n8gbOeM78D5_U1F4TaGCMrcCMjkX" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
</div>
<h4 style="text-align: left;">
<b>Steps for PCGen to take</b></h4>
<div style="margin-bottom: 0cm;">
The next step for the PCGen team would
be to take a look at something like the histogram from <span style="font-family: Courier New, serif;">jmap</span>
to see what large objects are being created. A quick check of <span style="font-family: Courier New, serif;">jmap</span>
output means that I know that we have large (multi-MB) contiguous
arrays of <span style="font-family: Courier New, serif;">String</span>, <span style="font-family: Courier New, serif;">char</span>
and <span style="font-family: Courier New, serif;">byte</span>.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
An option for PCGen at this point is to
resize the young gen space in order to fit these large objects into
young gen space using the <span style="font-family: Courier New, serif;">-XX:NewRatio</span>
or <span style="font-family: Courier New, serif;">-XX:NewSize</span> flags. The size
to set either of these two values would depend on the results
discovered from the <span style="font-family: Courier New, serif;">jmap</span>
usage. In this case setting <span style="font-family: Courier New, serif;">-XX:NewSize</span>
to ~256M is required to alleviate the the number of pauses.</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
However, that's generally not a great
long term solution. The PCGen project is better off reducing the
usage of these large contiguous memory allocations. Lead by Tom
Parker and James Dempsey, this is exactly what the PCGen team is
doing, taking out large memory structures from the monolithic
<span style="font-family: Courier New, serif;">PlayerCharacter</span> class into
smaller more flexible facets.</div>
<h2 class="western">
<a href="http://www.blogger.com/blogger.g?blogID=6459030366729235821" name="h.8if9iapcswz6"></a>Summary</h2>
<div style="margin-bottom: 0cm;">
It's fantastic to see that the
incredibly hard work the PCGen volunteers have put in for the 6.0
release has paid real dividends for the end users!</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
A couple of years ago I was tracking
down a 30+ second pause that a PCGen user had reported when loading
up her 25th level Kobold Shaman. It took me several days to track
down that it was a GC/memory problem as I only had raw GC log files
(which are multithreaded, indeterminant beasts). Going forwards I'll
definitely be using tooling like Censum to solve these issues more
quickly, which means I can get on with adding new features to PCGen!</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
Don't forget to check out <a href="http://pcgen.sf.net/"><span style="color: #1155cc;"><u>PCGen</u></span></a>
for your d20 role-playing game needs and <a href="http://www.jclarity.com/products/censum"><span style="color: #1155cc;"><u>Censum</u></span></a>
if you want to solve thorny GC problems!</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
Cheers,</div>
<div style="margin-bottom: 0cm;">
Martijn (Chairperson - PCGen, CTO -
jClarity)</div>
<div style="margin-bottom: 0cm;">
aka "The Diabolical Developer"</div>
<div style="margin-bottom: 0cm;">
<br /></div>
</div>
Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com6tag:blogger.com,1999:blog-6459030366729235821.post-64170746433009756842012-12-11T19:09:00.001+00:002012-12-11T19:09:09.889+00:00My 2012 - including a new Garbage Collection Tool<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline;">Hi all,</span><br />
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline;"><br /></span>
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline;">So I haven't written here for over a year! Why?</span><br />
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline;"><br /></span>
<br />
<h2 style="text-align: left;">
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline;">TLDR</span></h2>
<span style="font-family: Arial; font-size: 15px;">Well because several amazing things have happened in the last year or so. I am truly, truly blessed to be part of an amazing, vibrant </span><span style="font-family: Arial; font-size: 15px;">community</span><span style="font-family: Arial; font-size: 15px;"> of hackers, dreamers and doers. If you've been following me on <a href="http://www.twitter.com/karianna" target="_blank">Twitter</a> then hopefully you'll have had an idea of what's been going on. If not, or if you were after more details then read on!</span><br />
<span style="font-family: Arial; font-size: 15px;"><br /></span>
<br />
<h2 style="text-align: left;">
<span style="font-family: Arial;"><span style="font-size: 15px;">I'm the CTO of a new Start-up called jClarity</span></span></h2>
<span style="font-family: Arial; font-size: 15px;">I co-founded a new start-up called </span><a href="http://www.jclarity.com/" style="font-family: Arial; font-size: 15px;" target="_blank">jClarity</a><span style="font-family: Arial; font-size: 15px;"> with industry legends </span><a href="http://www.twitter.com/kittylyst" style="font-family: Arial; font-size: 15px;" target="_blank">Ben Evans</a><span style="font-family: Arial; font-size: 15px;"> and </span><a href="http://www.twitter.com/kcpeppe" style="font-family: Arial; font-size: 15px;" target="_blank">Kirk Pepperdine</a><span style="font-family: Arial; font-size: 15px;"> along with a host of other </span><a href="http://www.jclarity.com/team" style="font-family: Arial; font-size: 15px;" target="_blank">exceptional engineers</a><span style="font-family: Arial; font-size: 15px;">. </span><span style="font-family: Arial; font-size: 15px;">We're focusing on intelligent products to optimise Java/JVM applications and ensure the stability of the Cloud during its infancy. Basically we decided <i>to try science,</i> basing our analytics off empirical science as opposed to guesswork.</span><br />
<span style="font-family: Arial; font-size: 15px;"><br /></span>
<span style="font-family: Arial; font-size: 15px;">Today, existing performance tools give you lots of data, lots of graphs and no real answers. They also impact heavily on your running system and become a major bottleneck themselves. Having suffered on the wrong end of this for years, we decided to do something about it! </span><span style="font-family: Arial; font-size: 15px;">We're focusing on simple, light-weight and easy to use tools that give answers as opposed to making you scratch around in deep computer science and Java/JVM theory.</span><br />
<span style="font-family: Arial; font-size: 15px;"><br /></span>
<span style="font-family: Arial;"><span style="font-size: 15px;">Of course community and supporting FOSS is a strong part of this, we're passionate fans of fun tech communities. If you're interested in performance tuning, cloud, virtualisation, the internals of the JVM, how Java really works etc then sign-up to our </span></span><a href="http://www.jclarity.com/friends" style="font-family: Arial; font-size: 15px;" target="_blank">Friends of jClarity</a><span style="font-family: Arial;"><span style="font-size: 15px;"> programme and join in the fun!</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 15px;"><br /></span></span>
<br />
<h2 style="text-align: left;">
<span style="font-family: Arial; font-size: 15px;">The London Java Community continues to kick butt!</span></h2>
<span style="font-family: Arial; font-size: 15px;">We won two awards this year for our work in the Java Standards space. Our two programmes <a href="http://adoptajsr.java.net/" target="_blank">Adopt a JSR</a> and <a href="http://adoptopenjdk.java.net/" target="_blank">Adopt OpenJDK</a> continue to thrive and make a real difference to the ~9 million Java developers out there today.</span><br />
<span style="font-family: Arial; font-size: 15px;"><br /></span>
<span style="font-family: Arial; font-size: 15px;">For example, you can thank Stephen Colebourne and also Richard Warburton/James Gough for ensuring that Java 8 gets some great new date and time APIs via JSR 310!</span><br />
<span style="font-family: Arial; font-size: 15px;"><br /></span>
<br />
<h2 style="text-align: left;">
<span style="font-family: Arial; font-size: 15px;">I spoke at 10+ conferences</span></h2>
<span style="font-family: Arial; font-size: 15px;">I was privileged to be invited to speak at a large variety of conferences this year, from intimate rooms at regional events in their first year</span><span style="font-family: Arial; font-size: 15px;"> to keynotes at some of the largest Java conferences in the world. It was (as always) a learning curve, dealing with different audience sizes, cultures and areas of interest.</span><br />
<span style="font-family: Arial;"><span style="font-size: 15px;"><br /></span></span>
<span style="font-family: Arial;"><span style="font-size: 15px;">My technical talks focused on Java and the Machine - looking at where the language and the JVM hit the Operating system and the hardware and why that matters again. For those of you who missed the 2012 trend on this, basically multi-core CPUs and virtualisation/cloud means that Java developers have to really think about the hardware they are coding on top of again, no more free lunch!</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 15px;"><br /></span></span>
<br />
<h2 style="text-align: left;">
<span style="font-family: Arial;"><span style="font-size: 15px;">The Well-Grounded Java Developer was released!</span></span></h2>
<span style="font-family: Arial;"><span style="font-size: 15px;">After ~2 years of elapsed time Ben Evans and myself are very proud that our first book <a href="http://www.manning.com/evans" target="_blank">The Well-Grounded Java Developer</a> has been released. So far it's all 5 star reviews in Amazon, some even by people we don't know ;-)!</span></span><br />
<span style="font-family: Arial;"><span style="font-size: 15px;"><br /></span></span>
<br />
<h2 style="text-align: left;">
<span style="font-size: 15px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;">I was honoured to be counted as a Java Champion</span></span></h2>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 15px;">The </span><a href="http://java-champions.java.net/" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px;" target="_blank">Java Champions</a><span style="font-family: Arial, Helvetica, sans-serif; font-size: 15px;"> are a group of Java luminaries that I've looked up to my entire career. To be named in their number is still bewildering to me, but there you have it.</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 15px;"><br /></span></div>
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 15px;">We built a solution to figure out your Garbage Collection problems</span></h2>
<span style="font-size: 15px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;">We've released </span><b style="font-family: Arial, Helvetica, sans-serif;">Censum</b><span style="font-family: Arial, Helvetica, sans-serif;">, a new tool for analysing Garbage Collection logs, telling you exactly what you need to change in order to stop those mysterious pauses and the </span><span style="font-family: Courier New, Courier, monospace;">OutOfMemoryErrors</span><span style="font-family: Arial, Helvetica, sans-serif;"> (amongst other things).</span></span><br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 15px; vertical-align: baseline;"><br /></span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 15px;">Garbage Collection often causes production problems, and is a difficult, specialised area that can be very frustrating for busy developers, devops and operations teams. </span><span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 15px; vertical-align: baseline;"><b>Censum</b> analyses complex logs
and tells you about your GC performance problems in plain English, along
with the fix!</span><br /><span style="font-size: 15px; vertical-align: baseline;"></span><br /><span style="font-size: 15px; vertical-align: baseline;"><b>Censum</b> is available to download at <a href="http://www.jclarity.com/">www.jclarity.com</a></span></span><span style="font-family: Arial, Helvetica, sans-serif; font-size: 15px;">.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 15px;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 15px;">So that's been my year in a nutshell - I hope yours was as much fun and that you got to write more code than I did, something I need to rectify in 2013 :-)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 15px;"><br /></span>
</div>
<div>
</div>
</div>
Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-65742642154048947632011-10-04T08:05:00.005+01:002011-10-04T16:58:21.494+01:00JavaOne 2011 - Days 1 and 2 (Sunday/Monday)Hi all,<br />
<br />
So I'm at JavaOne and it's been an interesting first couple of days! I'm live tweeting a number of live announcements and insights but I thought I'd try to round-up my experiences so far on Days 1 and 2.<br />
<br />
Apologies for anyone/thing I've missed - it's been a whirlwind! <br />
<br />
<u>Sunday</u><br />
<u> </u><br />
<br />
<b>My Walk</b><br />
<br />
I started the day with an interesting walk from my apartment to "The Zone". First thing that struck me was the vast numbers of homeless people on the streets, really sad to see and not what I expected from San Fran at all. They say that Britain is a broken society, I think I'm seeing worse here in San Fran.<br />
<br />
<b>JUG Leaders Brunch</b><br />
<br />
The JUG Leaders and Java Champions brunch was the first thing up on Sunday morning. It was fantastic to put names to faces (a bunch of us only knew each other from the mailing list) and of course to see familiar <a href="http://blogs.oracle.com/arungupta/entry/java_champions_and_jug_leaders">friendly faces</a> including Stephen Chin, Bruno Souza, Fabiane Nardon, Kirk Pepperdine, Stephan Janssen and many more! Oracle gave us a briefing on what was going to be announced in the keynotes, one of the focuses being on Java FX 2.0. I'm still personally not sure whether it's going to be 'too little, too late' given the rise of HTML5, but then again I'm not heavily involved in the UI space.<br />
<br />
<b>User Group Sunday</b><br />
<br />
The rest of Sunday was spent with the JUG leaders and other community members for a bunch of Open Conference style sessions. It's always good to discuss the issues that we all commonly face, thanks to John Yeary for organising.<br />
<br />
The Duke awards were presented that evening outside in the Mason Street tent/cafe area and LJC's Trisha Gee accepted a Duke innovation award for the Disruptor framework that her company (LMAX) has been working on. The Zero Turnaround guys also picked up their well deserved award for JRebel.<br />
<br />
The evening ended with us meeting up with Charles Nutter and some of the other JRuby crowd at the Glassfish party in the Thirsty Bear, it never hurts to get free beer! Was also nice to see Dan Hardiker and a certain Mr Gosling there.<br />
<br />
<u>Monday</u><br />
<br />
<b>The Good</b><br />
<br />
1. Oracle's stance and genuine efforts with the community.<br />
<ul>
<li>The Duke awards on Sunday night</li>
<li>The free coffee and beer</li>
<li>Featuring non Oracle speakers on the JavaOne front page</li>
<li>The technical content of the overall program being determined in conjunction with a community committee.</li>
<li>Their community interviews</li>
<li>And more!</li>
</ul>
Credit goes to all of the Oracle team behind this including Nichole Scott, Sharat Chandar, Mark Reinhold, Henrik Stahl, Adam Messinger, Mary-Lou, Tori Weildt, Dalibor, Donald and many more!<br />
<br />
2. Parts of the Keynote were really good. Mark Reinhold was very clear explaining Java 7 and 8, the Java FX 2.0 demo with the Kinect controlled Duke went down well and they involved the JRuby guys to explain invokedynamic and what it means for non-Java languages.<br />
<br />
3. The Mason Street area and the hangout spaces in the hotels are pretty cool<br />
<br />
4. Attendance was way up from last year, real buzz about the place, it's pretty clear that the Java platform is going through an upsurge, exciting to see.<br />
<br />
5. JCP matters again. We had lots of people turning up to the JCP events, buoyed by the results of JSR-348 (step one in reforming the JCP) with lots of feedback and interactive Q&A. Even the public EC meeting was packed out! I was on the panel for a number of these events and was really happy with the amount of interest and feedback, especially considering they're effectively non-technical sessions.<br />
<br />
6. Good talks on Lambda (Alex Buckley) and Jigsaw (Mark Reinhold) for Java 8 from experts who actually engaged the audience!<br />
<br />
7. The O'Reilly cocktail party, was able to talk shop with fellow authors and catch up with friends from OSCON such as Laurel Ruma, Sarah Novotny and the rest of the O'Reilly crew.<br />
<br />
<b>The Indifferent</b><br />
<br />
1. Oracle have tried their best with "The Zone", but the fact remains that running around the 3 hotels is still fairly difficult and trying to find certain rooms inside the hotels also leaves attendees missing out on their events. I haven't put this into "The Bad" section as the sign posting and extra helpers made it bearable (just).<br />
<br />
2. The speakers room was very small and has limited WiFi signal, Oracle, please talk to the OSCON folks on their set-up!<br />
<br />
3. Getting my photo taken in an alleyway in the rain for a tech magazine - us developers don't usually make good models, as was proven today!<br />
<br />
4. Some of the even rooms are still small and pokey and seem to be stuck in a basement level (Parc55 in particular)<br />
<br />
<b>The Bad</b><br />
<br />
1. The WiFi constantly drops in and out, ruining some presenters demos and causing immense frustration for attendees. Lessons need to be learned from some of the European conferences such as Devoxx and FOSDEM. Hoping this improves tomorrow.<br />
<br />
2. The Intel part of the keynote. Caused the entire keynote to be late (they rambled on), was boring (some pretty hokey bar/line graphs) and the its content was better suited to OOW as opposed to JavaOne.<br />
<br />
Phew - busy days so far, looking forward to sleep :-)<br />
<br />
Cheers,<br />
MartijnMartijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com2tag:blogger.com,1999:blog-6459030366729235821.post-47724609907101111752011-09-15T09:48:00.003+01:002011-09-15T09:49:18.371+01:00My Interview with MyFearI was humbled to be interviwed as part of MyFear's Java Hero's series - If you want to know some of my motivations then go <a href="http://blog.eisele.net/2011/09/heroes-of-java-martijn-verburg.html?utm_source=feedburner&utm_medium=twitter&utm_campaign=Feed%3A+EnterpriseSoftwareDevelopmentWithJava+%28Enterprise+Software+Development+with+Java%29">here</a>Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-59022732242446111232011-09-10T13:22:00.003+01:002011-09-10T13:53:38.416+01:00The OpenJDK as the default Java on LinuxHi All, <span style="font-size: x-small;">(this post is x-posted to the<a href="http://www.java7developer.com/blog"> java7developer blog</a> and the <a href="http://londonjavacommunity.wordpress.com/">ljc blog</a>)</span><br />
<br />
<div>
Recently I've received a bunch of private correspondence from people confused/worried over the change in the default Java packaging for Linux. For many Linux distributions, the official Sun/Oracle version of Java has been packaged up as the default Java for the platform. However, due to a recent licensing change, this will no longer be the case! So, is this a positive or a negative thing for the Java and open source ecosystem? Read on for my take on it :-)<br />
<br />
<u>Background</u><br />
<br />
Dalibor Topic <a href="http://robilad.livejournal.com/90792.html">announced</a> that With Java SE 7 and JDK 7 being released, and with <a href="http://openjdk.java.net/">OpenJDK</a> as the official Java SE 7 <a href="http://blogs.oracle.com/henrik/entry/moving_to_openjdk_as_the">reference implementation</a>, that it was finally time to retire the non open source "Operating System Distributor License for Java" (<a href="http://jdk-distros.java.net/">DLJ</a>). <br />
<br />
<u>What does it mean for me?</u><br />
<br />
The knock on effect of this is that Linux distributions will on longer package Oracle's Java (== OpenJDK wrapped up in some proprietary bits and pieces) as the default Java. This can/will cause problems for some Java users initially as there are a smattering of bugs (especially in the Swing UI libs) still left in the OpenJDK that affect programs like <a href="http://pcgen.sf.net">PCGen</a>. However, some Linux distributions had already taken this path some years ago, <a href="http://blogs.oracle.com/barton808/entry/openjdk_default_java_runtime_in">most notably Ubuntu</a> and the last remaining bugs are being cleaned up pretty quickly.<br />
<br />
<u>Positive or Negative?</u><br />
<br />
Overall, I think this is a positive step in the right direction for free and open Java on Linux platforms. This sentiment was welcomed by well known open source advocate Simon Phipps in a <a href="https://twitter.com/#!/webmink/status/108687526046347264">twitter post</a>. The fact the the OpenJDK is now the reference implementation (combined with efforts to open up the issue tracker for the OpenJDK) means that means that a vast host of Java/Linux end users can now directly improve 'official Java' for all of us. </div>
<div>
<br /></div>
<div>
<u>I want the Oracle version!</u></div>
<div>
<br />
Linux users who need to use the proprietary parts of the Oracle JDK 6 or Oracle JDK 7 binaries can of course as usual simply get the gratis download at <a href="http://oracle.com/java">http://oracle.com/java</a> under the same terms as users on other platforms. However, if it is due to a 'bug' that is discovered I strongly encourage those users to <a href="https://bugs.openjdk.java.net/">submit a bug</a> report to the OpenJDK project, so that any issues can be fixed for all of us.</div>
<div>
<br /></div>
<div>
Opinions and further questions are welcome!</div>
<div>
<br /></div>
<div>
Thanks,</div>
<div>
Martijn</div>
Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-58762516691048687572011-09-01T16:48:00.001+01:002011-09-30T15:02:44.026+01:00JavaOne schedule<span style="font-family: Arial, Helvetica, sans-serif;">Here is my JavaOne schedule: I can't mimic the nice colouring that <a href="http://steveonjava.com/steveonjava-track-at-javaone/">Steve On Java</a> has, but hey :-).</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Please note the </span><b style="background-color: white; font-family: Arial, Helvetica, sans-serif;">JCP EC meeting is open and free for all to join</b><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;"> (Sunday 15:45) - we need the voice of the community there, so come along!</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">I'll actually be speaking at</span><span style="font-family: Arial, Helvetica, sans-serif;">:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<ul>
<li><span style="font-family: Arial, Helvetica, sans-serif;">30440 - </span><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Java User Groups and the JCP (Sunday 14:30)</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">23647 - JCP and the Developer Community (Monday 11:00)</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">23641 - </span><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Meet the Executive Committee Candidates (Monday 1900)</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">23645 - </span><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Lightning Talks: JSRs in Progress (Wednesday 0830)</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">25303 - The Diabolical Developer (Redux) (Wednesday 1500)</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">25303 - The Diabolical Developer (Redux) - repeat! (Wednesday 1630)</span></li>
<li><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">37780 - Java Community Keynote (Thursday 0845)</span></li>
</ul>
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Let me know if you want to catch up! I'll be fairly flexible about turning up to most sessions, the benefit of attending a conference like JavaOne is as much isn't catching up with friends an colleagues as much as anything else :-)</span><br />
<span style="background-color: white;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span><br />
<iframe frameborder="0" height="870" scrolling="no" src="https://www.google.com/calendar/embed?title=JavaOne%20Schedule&showTitle=0&showNav=0&showDate=0&showPrint=0&showTabs=0&showCalendars=0&showTz=0&mode=AGENDA&height=870&wkst=1&bgcolor=%23FFFFFF&src=0vlh2md3r014171lb74no8o5cg%40group.calendar.google.com&ctz=America%2FLos_Angeles&dates=20111002%2F20111006" style="border: 0;" width="590"></iframe>Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-87787975060358352152011-04-19T15:42:00.000+01:002011-04-19T15:42:33.318+01:00The Data Grid JSR Backlash and why you should support the JCP reforms<span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px;"></span><br />
<div class="im"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The recent backlash against Red Hat's data grid JSR proposal sparked an interest as I know the JCP is going under reform right now.</span></div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="border-collapse: collapse;"><span class="Apple-style-span" style="border-collapse: collapse;"><br />
</span><br />
For those of you who have missed the debates, here's some background reading for you:</span><span class="Apple-style-span" style="border-collapse: collapse;"></span></span><br />
<div class="im"><ul><li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="border-collapse: collapse;"><a href="http://bit.ly/gDrtP3" target="_blank">http://bit.ly/gDrtP3</a>,</span></span></li>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="border-collapse: collapse;">
<li><a href="http://bit.ly/eeOWWF" target="_blank">http://bit.ly/eeOWWF</a></li>
<li><a href="http://bit.ly/hKiNg1" target="_blank">http://bit.ly/hKiNg1</a></li>
</span></span></ul></div><br />
<span class="Apple-style-span" style="border-collapse: collapse;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">So, here are my thoughts on the subject!<br />
</span></span><br />
<span class="Apple-style-span" style="border-collapse: collapse;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><u>Technical merits</u><br />
<br />
On technical merit the JSR proposal certainly seems sound enough to be a solid starting point for discussion (I'm no expert mind you).</span></span><br />
<div class="im"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
<u>Open standards are good</u><br />
<br />
It's a laudable goal to standardise this space, and Red Hat have got </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">my support on that front. Just like vendor lock-in was bad for </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">databases and app servers, it's also bad for developers and users of data grids.</span></div><div class="im"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
This area is potentially worth Billions and so I can understand why some vendors may be reluctant to form an open std </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">around it, but really, it's a good thing! I believe the vendors should be </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">competing on performance and other factors, not basic </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">get </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">and </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">put</span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> type </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">API calls.</span></div><div class="im"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><u>Where the proposal went wrong</u><br />
<br />
Politically, Red Hat went about this in an unusual way, hence the backlash. Sadly, that sort of backlash can be enough to sink a JSR before it even sets sail.<br />
</span><br />
<span class="Apple-style-span" style="border-collapse: collapse;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">I was a surprised that an organisation with so much JCP experience presented this JSR without the usual pre-collaboration that typically goes on in these cases. So I dug a little deeper to find out why Red Hat had gone about it this way.<br />
<br />
<u>The root cause</u><br />
<br />
Without knowing all of the ins and outs, the new data grid JSR was proposed partly because of Red Hat's frustration with trying to get JSR-107 (data caching) back to an active state (it's been an inactive JSR for some time).<br />
</span></span><br />
<span class="Apple-style-span" style="border-collapse: collapse;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">A std caching API (JSR-107) would be a natural base for any agreements around standardising any further data grid APIs on top of that.<br />
<br />
Red Hat (and others?) had tried to re-vitalise the JSR-107 Expert Group to get </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">the JSR re-opened, ratified and released. That would've been a great start, as it </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">meant that there would be collaboration amongst the same vendors that are </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">then needed for a subsequent data grid JSR.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
<u>Why did that attempt fail?</u><br />
<br />
<b>We don't really know</b>. Unfortunately nobody on the outside can confirm what was/is going on as <b>the JSR-107 mailing list is closed to the public!</b></span><br />
<div class="im"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="im"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This is the crux of the problem with the existing JCP rules, in that 'open standards' are being decided behind closed doors. Thankfully Patrick Curran is working on changing this (see! Oracle isn't always evil ;p).<br />
<br />
<u>So what happens next?</u><br />
<br />
By raising the new JSR, Red Hat has gotten their desired result of getting JSR-107 moving again to <span class="Apple-style-span" style="border-collapse: collapse;"><a href="http://bit.ly/hP0Hyn">complete the caching work</a></span>. It's a </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">shame that they were seemingly forced into this stance. We'd all </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">much rather see deliberate community collaboration, it's certainly </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">not a model of how we want to see inactive JSRs moving again!</span></div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="border-collapse: collapse;">Red Hat's intentions are almost certainly completely honourable, but</span><span class="Apple-style-span"> </span><span class="Apple-style-span" style="border-collapse: collapse;">as some of the other vendor's stated, the raising of the new data grid</span><span class="Apple-style-span"> </span><span class="Apple-style-span" style="border-collapse: collapse;">JSR came across as a great surprise and was therefore not as welcomed</span><span class="Apple-style-span"> </span><span class="Apple-style-span" style="border-collapse: collapse;">as it could have been.</span><br />
<span class="Apple-style-span" style="border-collapse: collapse;"><br />
</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="border-collapse: collapse;">So, JSR-107 will go ahead, but it'll take some amount of bridge </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">mending before data grid JSR gets off the ground.</span><br />
<div><div class="im"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="im"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Lets avoid this in the future and support Patrick Curran's JCP reforms!<br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="im"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Cheers,<br />
Martijn</span></div></div>Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com2tag:blogger.com,1999:blog-6459030366729235821.post-83668318206960328562011-03-03T14:22:00.002+00:002011-03-03T14:23:25.212+00:00OSGi - Are we there yet?A few nights ago John Stevenson (@jR0cket) and I were fortunate enough to be taken through a explanation of OSGi by some of its key proponents: Neil Barlett (@njbarlett), Zoe Slattery (@zoe_slattery) and Alasdair Nottingham.<br />
<br />
I have certainly battled JAR hell and have also experienced problems with keeping web and enterprise applications isolated from each other (manipulating parent delegation and CLASSPATHs anyone?). This has been throughout my Java career (~10 years now), but I had never investigated OSGi properly as an alternative. Why? Because I never spent the time investigating OSGi properly and I was under the strong impression that it was better suited for IDE, App Server and tooling development as opposed to application development.<br />
<br />
So after a good couple of hours of discussion I came out with a greater appreciation for OSGi and the following conclusions.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">The Good</span><br />
<br />
<u>OSGi's core principles are pretty sound</u><br />
<br />
OSGi is a sound solution for modularity, it clearly breaks the developer away from the artificial JAR model of 'modularity' and instead gets you to think about what Java packages you are dependent on. Through some simple metadata information in your manifest file you can specify the packages that you are dependent on (including a version range). For example, your test code may rely on the org.junit.core package within JUnit. Normally you would reference the entire JAR, but with OSGi you can reference just the package org.junit.core, as well as the version range that you want (e.g. 4.7.1 to 4.8.2). That package can then be supplied by any bundle (which still uses the JAR construct) which 'exports' it. You can probably already envision that a much smaller bundle can be provided than the default large JUnit JAR file.<br />
<br />
<u>OSGi actually encourages you to design better APIs</u><br />
<br />
For those following the various clean code or software craftsmanship movements will appreciate the fact that by utilising OSGi, the developer is actually encouraged to think about splitting their public API into loosely coupled 'bundles'. The analogy here is that of Maven, which although polarises developers, does encourage them to use a correct build life cycle (clean, compile, test, package, environmentalise). good API developers should certainly look at supporting OSGi in order to help them designed better APIs<br />
<br />
<u>OSGi is relatively easy to get started with</u><br />
<br />
You can start with an existing application and simply provide the OSGi bundle information in the manifest file for that JAR. You will tend to find that a vast majority of the dependencies already have OSGi bundle versions and it is not difficult to swap to an OSGi based build using Maven or Ant. In fact, as OSGi is already a well established technology it probably pays to have an OSGi bundled version of any project artifacts you produce. The tooling is adequate on most major IDEs (especially Eclipse) although the OSGi community would still like to see improvements in this area.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">What the OSGi alliance is working on improving</span><br />
<br />
<u>A common/std tool for deploying OSGi applications to runtime environments</u><br />
<br />
OSGi does have a std API for deployments, but this does mean that developers need to implement a deployment mechanism for deploying their apps to runtime environments. Most modern application servers do have OSGi container support, but the deployment mechanism is arguably different each time. This is an area that the OSGi alliance is working on and hopefully some standard tooling around this standard will come out soon. Although it seems like a small usability gap for OSGi, my guess is that this is a real adoption blocker.<br />
<br />
<u>Like Java apps in general, OSGi bundles are not Linux/UNIX distro friendly</u><br />
<br />
A major complaint from Linux and UNIX distros over the years has been the fact that Java is not installed according to their packaging standards. Java is also an relatively large installation, which is the source for further criticism. Whilst OSGi certainly helps with the size aspect of Java-based programs, as it is also a late-binding runtime container it does not lend itself to the static, early binding packaging systems that the distros use.<br />
<br />
As John pointed out, the existing Iced Tea (OenJDK) project does already produce bundle data that looks a good deal like OSGi bundle data:<br />
<br />
Looking into the meta-data of the openjdk-6-jdk package, you can see there is a lot of scope for using OSGi style information.<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Package: openjdk-6-jdk<br />
Priority: extra<br />
Section: devel<br />
Installed-Size: 34100<br />
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com><br />
Original-Maintainer: OpenJDK Team <openjdk@lists.launchpad.net><br />
Architecture: amd64<br />
Source: openjdk-6<br />
Version: 6b20-1.9-0ubuntu1<br />
Provides: java-compiler, java-sdk, java2-sdk, java5-sdk, java6-sdk<br />
Depends: openjdk-6-jre (>= 6b20-1.9-0ubuntu1), libc6 (>= 2.4), libx11-6, zlib1g (>= 1:1.1.4)<br />
Recommends: libxt-dev<br />
Suggests: openjdk-6-demo, openjdk-6-source, visualvm<br />
Conflicts: openjdk-6-jre (<< 6b17~pre3-1), openjdk-6-jre-headless (<< 6b17~pre3-1)<br />
Description: OpenJDK Development Kit (JDK)</span><br />
<br />
However, this does need to be investigated further and perhaps if OSGi and project Jigsaw can interoperate and some tooling is built then I could see bundles being deployed according to distribution standards. This would help Java and OSGi applications gain even more acceptance amongst the Linux/UNIX community. This leas us onto the Jigsaw issue...<br />
<br />
<span class="Apple-style-span" style="font-size: large;">The (Potentially) Ugly</span><br />
<br />
Project Jigsaw (Java modularity) is coming as part of JDK 8 and at this stage is not going to work hand-in-hand with OSGi. It is not beyond the realms of possibility that the two will interoperate cleanly in the future and I'm hopeful that the two communities can continue to find common areas despite their fundamentally different approaches.<br />
<br />
However, if they do not come together in some simple to use form then it is likely that the Java modularisation space will be fragmented which will only harm the end developer, end user and the Java ecosystem.<br />
<br />
You can read more on this topic on a blog post by my co-author for "The Well-Grounded Java Developer" Ben Evans. This post has also been cross posted to the LJC blog.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">So are we there yet?</span><br />
<br />
For mainstream adoption by application developers, probably not _yet_. But I think when the tooling gap is closed and as more application developers release OSGi apps, it might just become a de-facto standard for modularity in Java apps. However, there still remains the looming specter of Jigsaw integration/interoperability. There have been signs of the two sides discussing how they can meet in the middle, lets hope that continues.<br />
<br />
Cheers,<br />
MartijnMartijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com2tag:blogger.com,1999:blog-6459030366729235821.post-18347134351662298802011-02-02T08:02:00.000+00:002011-02-02T08:02:19.790+00:00Bit of a hiatusHi all,<br />
<br />
With "The Well-Grounded Java Developer" deadlines approaching and my arms starting to feel the strain I'll be taking a break from writing any blog posts for a few months. Not that it's been real busy here anyhow, but I thought you should know :-).<br />
<br />
Cheers,<br />
MartijnMartijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-48258213310118286302010-12-08T12:11:00.013+00:002010-12-08T12:27:54.074+00:00JBoss - separating application logs without using monolithic jboss-log4j.xmlA minor irritant we've discovered in implementing applications for Jboss AS is that that the logging configuration for applications has to go through their monolithic <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">jboss-log4j.xml</span> file.<br />
<br />
<div>So we've managed to find a work-around (after some investigation of the Jboss class loaders and some trial and error). This technique has been confirmed for jboss-eap-4.3 and jboss-4.2.3.GA but will likely work for other versions.<br />
<br />
If you want to have split application logs and have that log4j.xml based configuration separated out (e.g. Not have it all in the jboss-log4j.xml file) then you can do the following.<br />
<br />
1.) Your WAR/EAR must contain <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">log4j-1.2.16.jar</span>. It must be 1.2.16 or later as earlier versions don't work.<br />
<br />
2.) The class loading for that WAR or EAR must have its java2ParentDelegation=false. So for example the jboss-app.xml file will look something like this:<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><?xml version="1.0" encoding="UTF-8"?></span><br />
<div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><!DOCTYPE jboss-app PUBLIC</span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> "-//JBoss//DTD J2EE Application 1.4//EN"</span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> "http://www.jboss.org/j2ee/dtd/jboss-app_4_2.dtd"></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><jboss-app></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <loader-repository>${your domain}:archive=${your app name}.ear</span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <loader-repository-config>java2ParentDelegation=false</loader-repository-config></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> </loader-repository></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"></jboss-app></span></div><br />
Now this means that the WAR/EAR will use the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">log4j-1.2.16.jar</span> for logging within its own classloader, i.e. It will not use Jboss's log4j.jar library (and therefore the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">jboss-log4j.xml</span> won't be used).</div><div><br />
3.) In the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">MANIFEST.MF</span> file in your WAR/EAR archive you need to set a Class-Path: entry that shows the location (directory) where the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">log4j.xml</span> file that you want to use will reside. For example if your EAR file is deployed in the deploy directory, your Class-Path reference might be something like this:<br />
<br />
<pre><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Class-Path: ../conf/log/${application name}/</span>
</pre><br />
4.) Your <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">log4j.xml</span> file should just be an ordinary one, with no references to any special jboss classes. However, it will have an appender with the specifc name for the log file for the application you want to log for, e.g.<br />
<br />
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier; color: #5b5b5b}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier; color: #5b5b5b; min-height: 14.0px}
</style> <br />
<div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <appender name="${module.name}" class="org.apache.log4j.RollingFileAppender"></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="File" value="${jboss.server.home.dir}/log/${module.name}.log"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="Threshold" value="INFO"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="Append" value="true"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="MaxFileSize" value="2MB"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="MaxBackupIndex" value="20"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <layout class="org.apache.log4j.PatternLayout"></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="ConversionPattern" value="%d{yyyyMMdd HH:mm:ss.SSS} %-5p [%t] %C{1}.%M(): %x %m%n"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> </layout></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> </appender></span></div><div class="p2"><br />
</div>5.) OPTIONAL: You can still have all of your logging also go to the shared central <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">$JBOSS_HOME/${instance}/log/server.log</span> file by adding the following to your <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">log4j.xml</span> file:<br />
<br />
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier; color: #5b5b5b}
</style> <br />
<div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <appender name="all" class="org.apache.log4j.RollingFileAppender"></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="File" value="${jboss.server.home.dir}/log/server.log"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="Threshold" value="INFO"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="Append" value="true"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="MaxFileSize" value="2MB"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="MaxBackupIndex" value="20"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <layout class="org.apache.log4j.PatternLayout"></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> <param name="ConversionPattern" value="%d{yyyyMMdd HH:mm:ss.SSS} %-5p [%t] %C{1}.%M(): %x %m%n"/></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> </layout></span></div><div class="p1"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> </appender></span></div><br />
I've updated the Jboss community wiki with this information (thanks for pointing out the location Jaikiran!).</div>Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com1tag:blogger.com,1999:blog-6459030366729235821.post-84593007187632510252010-11-16T11:18:00.000+00:002010-11-16T11:18:57.110+00:00Java is dead, long live the Java developer! - Part II<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;"></span><br />
<div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;">Hi all,<br />
</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;">This is an updated post based on the recent announcements and events in November, enjoy!</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;"><br />
</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;">Well, what a few months it has been in the Java space! It started with Oracle announcing that the best plan to move the Java language forward was to split the existing openJDK work into Java 7 (for summer 2011), followed by a Java 8 (for summer 2012?). You can see the current feature list for JDK7 at <a href="http://openjdk.java.net/projects/jdk7/features/" style="color: #d52a33; text-decoration: none;">http://openjdk.java.net/projects/jdk7/features/</a>. Now that a decision has been made I think we'll see some good progress on this front.</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;"><br />
This of course threw our plans for the book into a bit of a spin and so Ben Evans and I are now writing "The Well-Grounded Java Developer (covers Java 7)", a subtle yet important shift in the emphasis for the book. This has caused some material to be thrown out (bye bye Date and Time, Closures and more) and other bits to be re-written. If you're interested in the book or what is going on with Java 7, then head on over to <a href="http://www.java7developer.com/" style="color: #d52a33; text-decoration: none;">http://www.java7developer.com</a> for more details!<br />
<br />
<u>But that of course was not all!</u><br />
<br />
The Oracle vs Google lawsuit continues to gather pace with Google counter suing Oracle. It's watch this space for everyone at the moment, but it seems that at this stage the lawyers are going to be kept rather (happily one suspects) busy. Another recent paper filed by Google appears to be a multi-layered defence, no quick resolution here then. You can keep an eye on this over at <a href="http://www.groklaw.net/staticpages/index.php?page=OracleGoogle" style="color: #d52a33; text-decoration: none;">groklaw</a></div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;"><br />
Oracle also announced a partnership with IBM in terms of developing the openJDK, a bit of a coup for Oracle, but understandably there was some backlash as the Java community as a whole realised that the formerly IBM backed Apache Harmony and all it stood for (a truly open Java) was effectively doomed. This has been well covered in the blogosphere, so I'll leave it at that (repeat after me "pragmatic").<br />
<br />
Then came some JCP nomination and election hooha! Some prominent people have sadly left (<a href="http://gee.cs.oswego.edu/dl/html/jcp22oct10.html" style="color: #d52a33; text-decoration: none;">Doug Lea</a> foremost amongst them) and there are also accusations flying about the JCP election process <a href="http://www.jroller.com/scolebourne/entry/stacking_the_jcp_election" style="color: #d52a33; text-decoration: none;">being gamed</a> somewhat.<br />
<br />
Apple stated that they would no longer be providing their own version of Java for Mac OS 10.7 and beyond. However, much to the relief of the Java community they then announced that they were gifting a vast majority of their work to the OpenJDK and would help Oracle integrate that. So although the steward has changed, it's still likely we'll get a first class Java on the Mac. I guess I'll buy a Macbook pro after all.</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;"><br />
</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;">Last but not least we have the Apache foundation vs Oracle battle. Remember the bit about Apache Harmony above? Apache wrote a public letter thanking IBM for their efforts, it was all very professional and seemed as amicable as possible. However, they then went on to bluntly tell Oracle that they would vote against the JSR for Java 7 SE unless Harmony was granted access to the TCK without restrictions. Yo can follow the conversation roughly via the links below</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;"><br />
</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;"><a href="https://blogs.apache.org/foundation/entry/statement_by_the_asf_board1">Apache's opening salvo</a> --> <a href="http://blogs.oracle.com/henrik/2010/11/moving_java_forward_open_response_from_oracle_to_apache.html">Oracle's response</a> --> <a href="http://www.theregister.co.uk/2010/11/16/oracle_statement_to_apache/">Apache's response</a></div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;"><br />
</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;">So we have IBM, Apple and Oracle all pretty much playing in the openJDK/Java 7 sandpit, with Google and Apache firmly on the outer, still some interesting times ahead.</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;"><br />
</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;"><u>Are we there yet?</u><br />
</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;">All in all this has of course led to many pundits claiming that Java is dying if not dead already. I disagree with that assessment, but with a bit of a twist.</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;"><br />
</div><div class="post-body entry-content" style="line-height: 1.4; position: relative; width: 506px;">On the enterprise side of things I think that Java will continue to have a strong presence, especially now that the JVM ecosystem has matured and allowed languages such as Clojure, Scala and Groovy to flourish. This is one of the cruxes that "The Well-Grounded Java 7 Developer" falls on.<br />
<br />
On the desktop I think that JavaFX 2.0 may have come too late to the party and certainly Swing is looking very aged as a relevant desktop client library.<br />
<br />
Mobile? This is probably the big one for the future, we'll have to wait and see what the Google and Oracle lawsuit brings out. Android is 'Java based' and has moved well ahead in terms of mind share (if not devices) over J2ME. If it at least remains 'Java based', then the Java language will continue to do well in this space, especially when all the new young developers continue to build software for the Android. If not, we may see a move towards Java (& JVM langauges) being seen purely as a specialised server side language.<br />
<br />
Java's not dead - it's just got new plumage and there's _plenty_ of excitement for the 'Java' developer :)<div style="clear: both;"></div></div><div class="post-footer" style="line-height: 1.6; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 1.5em;"></div>Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-81832031533994468972010-11-01T13:21:00.001+00:002010-11-01T13:26:37.799+00:00Java is dead, long live the Java developer!Hi all,<br />
<br />
Well, what a few months it has been in the Java space! It started with Oracle announcing that the best plan to move the Java language forward was to split the existing openJDK work into Java 7 (for summer 2011), followed by a Java 8 (for summer 2012?). You can see the current feature list for JDK7 at <a href="http://openjdk.java.net/projects/jdk7/features/">http://openjdk.java.net/projects/jdk7/features/</a>. Now that a decision has been made I think we'll see some good progress on this front.<br />
<br />
This of course threw our plans for the book into a bit of a spin and so Ben Evans and I are now writing "The Well-Grounded Java Developer (covers Java 7)", a subtle yet important shift in the emphasis for the book. This has caused some material to be thrown out (bye bye Date and Time, Closures and more) and other bits to be re-written. If you're interested in the book or what is going on with Java 7, then head on over to <a href="http://www.java7developer.com/">http://www.java7developer.com</a> for more details!<br />
<br />
<u>But that of course was not all!</u><br />
<br />
The Oracle vs Google lawsuit continues to gather pace with Google counter suing Oracle. No quick resolution here then. It's watch this space for everyone at the moment, but it seems that at this stage the lawyers are going to be kept rather (happily one suspects) busy. You can keep an eye on this over at <a href="http://www.groklaw.net/staticpages/index.php?page=OracleGoogle">groklaw</a><br />
<br />
Oracle also announced a partnership with IBM in terms of developing the openJDK, a bit of a coup for Oracle, but understandably there was some backlash as the Java community as a whole realised that the formerly IBM backed Apache Harmony and all it stood for (a truly open Java) was effectively doomed. This has been well covered in the blogosphere, so I'll leave it at that (repeat after me "pragmatic").<br />
<br />
Then came some JCP nomination and election hooha! Some prominent people have sadly left (<a href="http://gee.cs.oswego.edu/dl/html/jcp22oct10.html">Doug Lea</a> foremost amongst them) and there are also accusations flying about the JCP election process <a href="http://www.jroller.com/scolebourne/entry/stacking_the_jcp_election">being gamed</a> somewhat.<br />
<br />
Last but not least, Apple stated that they would no longer be providing their own version of Java for Mac OS 10.7 and beyond. Given the work that it takes to 'macify' the Java experience this may prove to be an issue for Oracle to give the same user experience with Java on the Mac. We'll hopefully see lots of job postings for this role as I personally love developing on my Macbook Pro :).<br />
<br />
<u>Are we there yet?</u><br />
<br />
All in all this has of course led to many pundits claiming that Java is dying if not dead already. I disagree with that assessment, but with a bit of a twist.<br />
<br />
On the enterprise side of things I think that Java will continue to have a strong presence, especially now that the JVM ecosystem has matured and allowed languages such as Clojure, Scala and Groovy to flourish. This is one of the cruxes that "The Well-Grounded Java 7 Developer" falls on.<br />
<br />
On the desktop I think that JavaFX 2.0 may have come too late to the party and certainly Swing is looking very aged as a relevant desktop client library.<br />
<br />
Mobile? This is probably the big one for the future, we'll have to wait and see what the Google and Oracle lawsuit brings out. Android is 'Java based' and has moved well ahead in terms of mind share (if not devices) over J2ME. If it at least remains 'Java based', then the Java language will continue to do well in this space, especially when all the new young developers continue to build software for the Android. If not, we may see a move towards Java (& JVM langauges) being seen purely as a specialised server side language.<br />
<br />
Java's not dead - it's just got new plumage and there's _plenty_ of excitement for the 'Java' developer :)Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com6tag:blogger.com,1999:blog-6459030366729235821.post-54812145931765315762010-08-23T11:05:00.003+01:002020-06-23T10:50:12.968+01:00Dependency Injection in Java 7<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">Hi all,</span><br />
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"></span><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">So apart from recovering from a long bout of the stomach flu, enjoying good food again at a "Come dine with me" night (our parents would be so proud) and planning a rush trip to Vegas I've managed to get out a first draft of the Dependency Injection chapter for the Well Grounded Java 7 Developer.</span><br />
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"></span><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">Java 7 unifies some of the basic standards that the various Dependency Injection frameworks (Spring, Guice, PicoContainer etc) have, making it easier for developers to move between the frameworks as needed.</span><br />
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><u><br />
</u></span><br />
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"></span><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><u>A reminder of what DI is with regards to Java</u></span><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><a href="file:///C:/Downloads/Book/WGJ7D_CH04.doc#_ftn1" name="_ftnref1" title=""><span class="MsoFootnoteReference"><span class="MsoFootnoteReference"><span lang="EN-US" style="color: black; font-family: "verdana" , sans-serif; font-size: 8pt;">[1]</span></span></span></a></span><br />
<div class="Quote">
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><span lang="EN-US"><br />
</span></span></div>
<div class="Quote">
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><span lang="EN-US">The <span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">javax.inject</span> package specifies a means for obtaining objects in such a way as to maximize re-usability, testability and maintainability compared to traditional approaches such as constructors, factories, and service locators (e.g., JNDI). This process, known as Dependency Injection, is beneficial to most nontrivial applications.</span></span></div>
<div>
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span></div>
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"></span><br />
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"></span><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">So without further preamble, here's a short section from the chapter, let me know what you think!</span><br />
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span><br />
<div class="Head3">
<span lang="EN-US"><u><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">Inject annotation</span></u><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><o:p></o:p></span></span></div>
<div class="Body1">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span></span></div>
<div class="Body1">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">The </span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">@Inject</span></span><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> annotation interface can be used in three places to indicate where you'd like a dependency to be injected. Below are the types of members that can be injected, in the order that they are processed at runtime:</span></span></div>
<div class="ListNumbered" style="margin-left: 27pt; text-indent: -13.3pt;">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span></span></div>
<div class="ListNumbered" style="margin-left: 27pt; text-indent: -13.3pt;">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">1.</span><span style="font: normal normal normal 7pt/normal 'Times New Roman';"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> </span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">Constructors</span></span></div>
<div class="ListNumbered" style="margin-left: 27pt; text-indent: -13.3pt;">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">2.</span><span style="font: normal normal normal 7pt/normal 'Times New Roman';"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> </span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">Methods</span></span></div>
<div class="ListNumbered" style="margin-left: 27pt; text-indent: -13.3pt;">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">3.</span><span style="font: normal normal normal 7pt/normal 'Times New Roman';"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> </span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">Fields</span></span></div>
<div class="Body1">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span></span></div>
<div class="Body1">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">You can annotate a constructor with </span></span><span class="CodeinText"><span lang="EN-US" style="font-size: 9pt;"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">@Inject</span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> and expect its parameters to be provided at runtime by your configured IoC container e.g:</span></span></div>
<div class="Body1">
<br /></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">@Inject public MurmurMessage(Header header, Content content)</span></span></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">{</span></span></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;"> this.header = header;</span></span></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;"> this.content = content;</span></span></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">}</span></span></div>
<div class="Body1">
<br /></div>
<div class="Body1">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">In this case both the </span></span><span class="CodeinText"><span lang="EN-US" style="font-size: 9pt;"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">Header</span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> and </span></span><span class="CodeinText"><span lang="EN-US" style="font-size: 9pt;"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">Content</span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> parameters would be injected at runtime. The specification allows for 0+ parameters to be injected for constructors, so injecting a zero-parameter constructor is still valid.</span></span></div>
<div class="Callout">
<span class="CalloutHead"><span lang="EN-US" style="font-size: 8.5pt;"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span></span></span></div>
<div class="Callout">
<span class="CalloutHead"><span lang="EN-US" style="font-size: 8.5pt;"><b><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">WARNING</span></b></span></span><span lang="EN-US"><b><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> </span></b><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">As per the specification there can only be one constructor in a class with an </span><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-style-span" style="font-size: small;">@Inject </span></span><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">annotation, this makes sense as the JRE would not be able to decide which injected constructor took precedence.</span></span></div>
<div class="Callout">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span></span></div>
<div class="Body1">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">You can annotate a method with </span><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-style-span" style="font-size: small;">@Inject</span></span><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> and like a constructor, expect its 0+ number of parameters to be injected at runtime. There are some restrictions in that injected methods cannot be declared </span></span><span class="CodeinText"><span lang="EN-US" style="font-size: 9pt;"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">abstract</span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> and cannot declare type parameters of their own</span><a href="file:///C:/Documents%20and%20Settings/verbma/Desktop/WGJ7D_CH04.doc#_ftn1" name="_ftnref1" title=""><span class="MsoFootnoteReference"><span class="MsoFootnoteReference"><span lang="EN-US" style="color: black; font-size: 8pt;"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">[1]</span></span></span></span></a><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">. The short code sample below demonstrates the use of </span></span><span class="CodeinText"><span lang="EN-US" style="font-size: 9pt;"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">@Inject</span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> with a setter method, a common technique when using Dependency Injection.</span></span></div>
<div class="Body">
<br /></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">@Inject public void setContent(Content content)</span></span></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">{</span></span></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;"> this.content = content;</span></span></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">}</span></span></div>
<div class="Body1">
<br /></div>
<div class="Body1">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">This technique of method parameter injection is especially powerful when it comes to providing service methods with the resources they need to do their job. For example you could pass a DAO argument to a finder service method that was tasked to retrieve some data.</span></span></div>
<div class="Callout">
<span class="CalloutHead"><span lang="EN-US" style="font-size: 8.5pt;"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span></span></span></div>
<div class="Callout">
<span class="CalloutHead"><span lang="EN-US" style="font-size: 8.5pt;"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><b>TIP</b></span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><b> </b>It has become a default best-practice to use constructor injection for setting mandatory dependencies for a class and to used setter injection for non-mandatory dependencies, e.g. fields that already have sensible defaults.</span></span></div>
<div class="Body1">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span></span></div>
<div class="Body1">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">It is also possible to inject fields (as long as they are not </span></span><span class="CodeinText"><span lang="EN-US" style="font-size: 9pt;"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">final</span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">), however the practice is not common. The syntax again is quite simple.</span></span></div>
<div class="Body">
<br /></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">public class MurmurMessenger</span></span></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">{</span></span></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;"> @Inject private MurmurMessage murmurMessage;</span></span></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;"> ...</span></span></div>
<div class="Code">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">}</span></span></div>
<div class="Body" style="text-indent: 0cm;">
<br /></div>
<div class="Body" style="text-indent: 0cm;">
<span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">You can read further about the </span></span><span class="CodeinText"><span lang="EN-US" style="font-size: 9pt;"><span class="Apple-style-span" style="font-family: "courier new" , "courier" , monospace;">@Inject</span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> annotation in the Javadoc, where you can discover some nuances about what types of values can be injected and how circular dependencies are dealt with.</span></span></div>
<div>
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br />
</span></div>
<div>
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">Cheers,</span></div>
<div>
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">Martijn</span><br />
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://examples.javacodegeeks.com/dependency-injection-java-example/" target="_blank">A related Java Code Geeks Article</a></span></div>
<div>
<span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><br clear="all" /></span> <br />
<hr align="left" size="1" width="33%" />
<div id="ftn1">
<div class="MsoFootnoteText">
<span class="FootnoteCharacters"><span lang="EN-US"><span class="FootnoteCharacters"><span lang="EN-US" style="color: black;"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif; font-size: medium;"><span class="FootnoteCharacters"><span lang="EN-US"><span class="FootnoteCharacters"><span lang="EN-US" style="color: black; font-family: "verdana" , sans-serif; font-size: 6.5pt;"><a href="file:///C:/Downloads/Book/WGJ7D_CH04.doc#_ftnref1" name="_ftn1" style="font-size: 6.5pt;" title="">[1]</a> </span></span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-size: medium;"><a href="http://atinject.googlecode.com/svn/trunk/javadoc/javax/inject/package-summary.html">http://atinject.googlecode.com/svn/trunk/javadoc/javax/inject/package-summary.html</a>.</span></span></span></span></span></span></span><br />
<span class="FootnoteCharacters"><span lang="EN-US"><span class="FootnoteCharacters"><span lang="EN-US" style="color: black; font-size: 6.5pt;"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"><a href="file:///C:/Documents%20and%20Settings/verbma/Desktop/WGJ7D_CH04.doc#_ftnref1" name="_ftn1" title="">[1]</a></span></span></span></span></span><span lang="EN-US"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;"> By this we mean you can't do </span><a href="http://download.oracle.com/javase/tutorial/extra/generics/methods.html"><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">http://download.oracle.com/javase/tutorial/extra/generics/methods.html</span></a><span class="Apple-style-span" style="font-family: "arial" , "helvetica" , sans-serif;">.</span></span></div>
</div>
</div>
</div>
Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com4tag:blogger.com,1999:blog-6459030366729235821.post-86863600980787804252010-08-09T15:01:00.003+01:002010-08-09T15:05:02.000+01:00A Little Directory love<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Hi all,</span><br />
<div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">So my next little snippet also comes from Chapter 2 of the book where we deal with the new NIO.2 (Non-Blocking I/O 2) APIs being introduced to Java 7. In particular I'm showing a small code snippet to showcase some of the new support for directories that Java 7 has. The code sample certainly needs a little tidy-up by using the new Automatic Resource Management (ARM) features in Java 7, but for now the example will suffice.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<u><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Dealing with Directories</span></u><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
<br />
The java.nio.file.DirectoryStream interface and its implementing classes allow you to:</span><br />
<ul><li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Iterate over entries in a directory.</span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Deal with large directory structures.</span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Filter entries whilst processing using regular expressions and MIME based content detection.</span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Walk the tree structure in order to perform recursive move, copy, delete operations.</span></li>
</ul><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">A common use case here is to list entries in a directory, e.g. Java source files as shown by the listing below.</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">DirectoryStream<path> stream = null;</path></span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">try<br />
{</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> // Define the directory<br />
Path dir = Paths.get("c:\\workspace");</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> // Declare a filtering stream<br />
stream = dir.newDirectoryStream("*.java");<br />
</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> // List each .java file in that directory</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> for (Path entry: stream)<br />
{<br />
System.out.println(entry.getName());<br />
}<br />
}<br />
catch (IOException e)<br />
{</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> // Poor man's exception handling<br />
e.printStackTrace();<br />
}</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">As you can see, with the new Java 7 APIs this particular task is much simpler than it used to be and this theme is prevalent in the rest of the NIO.2 APIs.</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">There are several other use cases which we will show case in the "NIO.2 in action" section.as well as on our upcoming website (to be revealed later).</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">So are we there yet? In terms of File and Directory interaction in Java 7 there's certainly a massive improvement, so I'll say "Yes" once Java 7 is released.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
Cheers,</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Martijn</span></div>Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com1tag:blogger.com,1999:blog-6459030366729235821.post-52813267491619845452010-08-05T14:09:00.000+01:002010-08-05T14:09:17.251+01:00The Well Grounded Java 7 Developer<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Hi all,</span><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">I've obviously not posted for quite some time and here is the reason why.....</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">It's been a long time coming, but I'm very happy to announce that Ben Evans and I have been contracted to write "<i>The Well Grounded Java 7 Developer</i>" for </span><a href="http://www.manning.com/"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Manning</span></a><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> publications. We've been spending the last month frantically getting the first few chapters out and a whole host of other book related activities, but now that I'm in full chapter writing mode I'll be adding regular posts to this blog.</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">A majority of my future posts will focus on interesting areas in this book and firstly I'd like to show a reworked extract from the new Date and Time API section.</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>Modeling Date and Time</b></span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><div class="Head3"><span lang="EN-US">The new API models time as a sequence of consecutive </span><span lang="EN-US">instants separated by fixed </span><span lang="EN-US">durations<a href="file:///C:/Downloads/Book/WGJ7D_CH02.doc#_ftn1" name="_ftnref1" style="mso-footnote-id: ftn1;" title=""><span class="MsoFootnoteReference"><span style="mso-special-character: footnote;"><span class="MsoFootnoteReference"><span lang="EN-US" style="color: black; font-family: "Verdana","sans-serif"; font-size: 8.0pt; mso-ansi-language: EN-US; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 10.0pt; mso-bidi-language: AR-SA; mso-fareast-font-family: Arial; mso-fareast-language: AR-SA;">[1]</span></span></span></span></a>.<span style="mso-spacerun: yes;"> </span>Java 7 maps these concepts directly on to classes, here's a more detailed explanation:</span></div><div class="Head3"></div><ul><li><span lang="EN-US">The </span><span class="CodeinText"><span lang="EN-US"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">javax.time.Instant</span></span></span><span lang="EN-US"> class represents a specific point on a discrete time-line e.g. January 23rd, 1996 at 09:00:00,0 UTC, the day that Java 1.0 was released.</span></li>
</ul><ul><li><span lang="EN-US">The </span><span class="CodeinText"><span lang="EN-US"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">javax.time.D</span></span></span><span class="CodeinText"><span lang="EN-US"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">uration</span></span></span><span lang="EN-US"> class represents a section of elapsed time in nanoseconds, e.g. The 400 nanoseconds it takes for a PIC12C672-04 Microchip to execute an instruction set.</span></li>
</ul><br />
<div class="Body1">So as you can imagine, any point of time can be modeled by simply applying a <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Duration</span> (positive or negative) to a starting <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Instant</span>.</div><div class="Body1">...</div><div class="Body1">...</div><div class="Body1"><br />
</div><div class="Body1"><b><span class="Apple-style-span" style="font-size: small;">Calendering</span></b></div><div class="Body1"><br />
</div><div class="Body1"><span lang="EN-US">With regards to calendaring, the main Calendar is </span><span class="CodeinText"><span lang="EN-US"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">ISOChronology</span></span></span><span lang="EN-US">, but other calendars such as </span><span class="CodeinText"><span lang="EN-US"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">CopticChronology</span></span></span><span lang="EN-US"> and </span><span class="CodeinText"><span lang="EN-US"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">ThaiBuddhistChronology</span></span></span><span lang="EN-US"> are supported.<span style="mso-spacerun: yes;"> </span>The </span><span class="CodeinText"><span lang="EN-US" style="font-size: 9.0pt; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 10.0pt;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Chronology</span></span></span><span lang="EN-US"> interface can be extended from to provide other implementations.</span></div><div class="Body1"><span lang="EN-US">...</span></div><div class="Body1"><span lang="EN-US">...</span></div><div style="mso-element: footnote-list;"><br />
</div><div style="mso-element: footnote-list;"><b><span class="Apple-style-span" style="font-size: small;">Timezone support</span></b></div><div style="mso-element: footnote-list;"><br />
</div><div style="mso-element: footnote-list;"><span lang="EN-US">Timezone support is also provided via </span>three core classes:</div><div style="mso-element: footnote-list;"><ul><li><span class="CodeinText"><span lang="EN-US"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">LocalDateTime</span></span></span><span lang="EN-US"> – Represents date/time <b>without an offset or a time zone</b>.</span></li>
</ul><ul><li><span class="CodeinText"><span lang="EN-US"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OffsetDateTime</span></span></span><span lang="EN-US"> - Represents date/time <b>with an offset</b> but not time zone.</span></li>
</ul><ul><li><span class="CodeinText"><span lang="EN-US"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">ZonedDateTime</span></span></span><span lang="EN-US"> - Represents date/time <b>with an offset and a time zone</b>.</span></li>
</ul></div><div style="mso-element: footnote-list;"><span lang="EN-US"></span></div><div style="mso-element: footnote-list;"><span lang="EN-US"></span></div><div style="mso-element: footnote-list;">...</div><div style="mso-element: footnote-list;">...</div><div style="mso-element: footnote-list;"><br />
</div><div style="mso-element: footnote-list;"> <hr align="left" size="1" width="33%" /> <div id="ftn1" style="mso-element: footnote;"> <div class="MsoFootnoteText"><a href="file:///C:/Downloads/Book/WGJ7D_CH02.doc#_ftnref1" name="_ftn1" style="mso-footnote-id: ftn1;" title=""><span class="FootnoteCharacters"><span lang="EN-US"><span style="mso-special-character: footnote;"><span class="FootnoteCharacters"><span lang="EN-US" style="color: black; font-family: "Verdana","sans-serif"; font-size: 6.5pt; mso-ansi-language: EN-US; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 10.0pt; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: AR-SA;">[1]</span></span></span></span></span></a><span lang="EN-US"><span style="mso-tab-count: 1;"> </span>This phrase is almost 100% uplifted from an excellent early primer article by Jesse Farnham, see<span style="mso-spacerun: yes;"> </span>http://today.java.net/pub/a/today/2008/09/18/jsr-310-new-java-date-time-api.html for details</span></div></div></div><div style="mso-element: comment-list;"> <hr align="left" class="msocomoff" size="1" width="33%" /> <div style="mso-element: comment;"> <div class="msocomtxt" id="_com_1" language="JavaScript"><span style="mso-comment-author: Sebastian;"><a href="" name="_msocom_1"></a></span> <div class="MsoCommentText"><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-size: 11px;"><br />
</span></span></div><div class="MsoCommentText">The book will be loaded with more in depth explanations and of course plenty of code samples. If you're interested in becoming a reviewer then please let me know!</div><div class="MsoCommentText"><br />
</div><div class="MsoCommentText"><br />
</div></div></div></div></span></div>Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com6tag:blogger.com,1999:blog-6459030366729235821.post-63509540321401488352010-06-09T13:41:00.000+01:002010-06-09T13:41:07.879+01:00The Modern Java DeveloperHi all,<br />
<br />
Here's a brief synopsis that a colleague of mine (Ben Evans) and I have been thinking about for sometime, and we're curious to hear your feedback if you think you'd like to hear about some of the themes within this synopsis at the 2nd LJC <a href="http://londonjavacommunity.wordpress.com/2010/05/20/london-java-community-announces-2nd-unconference-date/">Unconference</a>.<br />
<br />
"The role of the Java developer is undergoing a period of immense change - challenges such as manycore processors, new approaches to concurrency and a wealth of new languages (including functional and dynamic) on the JVM are redefining the nature of Java projects. The core SE/EE APIs have been supplemented by a large and growing body of additional material and technologies which the developer must know.<br />
<br />
Some of the upcoming new Java 7 features - including closures, invokedynamic and standardised dependency injection tackle some of these challenges. But it's not just core language updates that matter anymore, there's also been a change in the modern Java project lifecycle with a host of common tools and practices a developer will now be expected to encounter (largely borrowed from the Agile world). Lastly, there are new JVM languages which are gaining in popularity and which the developers may expect to encounter on future projects."<br />
<br />
Do people agree with the synopsis above? Are they finding their Java projects changing to a new model?<br />
<br />
Feel free to debate as I believe we're definitely not there yet!Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-4566170900992631302010-05-19T19:37:00.000+01:002010-05-19T19:37:26.813+01:00Exciting projects on the go!<br class="Apple-interchange-newline" /><br />
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Hi all,</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">This is another mainly Java/Technology related post, although it's more of an overview of what I'm up to. This is as much to do with getting it sorted in my head as anything else but people have asked what I'm involved in, so here goes:</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">1.) Reviewing an upcoming book on the Hudson Build Server (a favourite build tool of mine). I'm definitely behind on helping out on this one, I really need a few solid hours of quiet time to review the material produced to date.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">2.) Reviewing an upcoming book on Java 6 certification. I'm trying to learn as much about the book review process as possible before hopefully co-authoring my own, so that's my main motivation for this one. I'm still on the fence about certification, I dislike most of it but if it encourages people to study then that's not all bad.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">3.) Negotiating (along with a colleague) a book deal with a big tech book publisher, we're getting closer to some sort of a deal I think! This is the big exciting one for me, I've always wanted to try an author part of book if not an entire one so I really hope we can make this happen.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">4.) Moderating on the <a href="http://www.javaranch.com/">Javaranch</a>, which is going through a bit of an SEO overhaul at the moment. I'm also hopefully getting my wife ("a most excellent Graphic Designer" and that's definitely not just according to me) to help give it a facelift.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">5.) Community leading two open source projects (<a href="http://pcgen.sf.net/">PCGen</a> and <a href="http://ikasaneip.sf.net/">Ikasan EIP</a>). These I wish I could spend a few extra regular hours on a week. PCGen was the project that lead me into Open Source in the first place and the community spirit is just freakin awesome. No matter how many times I take sabbaticals away from it, I always miss it far too much and just have to go back :).</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Ikasan is the new kid on the block that I'm trying to turn into a "successful open source project" as part of my day job. It's got a great deal of potential, but I need to spend a good deal more time with the community in order to realise it.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">6.) Co-organising the <a href="http://www.meetup.com/Londonjavacommunity">London Java Community</a> and the <a href="http://www.meetup.com/grad-dc/">London Graduate and Undergraduate Development Community</a> which currently involves helping organise an <a href="http://www.meetup.com/Londonjavacommunity/calendar/13404590/">Unconference</a> for the LJC and an not yet announced talk for the GDC.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">7.) Writing several talks for conferences (sssh it's a secret)</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">With several of items above, I work with some pretty amazing and motivated people and that's why I pretty much stay involved, it's just plain fun and rewarding to boot!</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">So there you have it, my tech related life in a nutshell :).</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Cheers,</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Martijn</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">As an aside, I spotted the statement "If you want something done, give it to a busy person" on the web a couple of days ago while I was lying in bed nursing a bout of the man flu (which my wife was ever so patient with). I realised that it holds pretty darn true for all of psychotically busy friends and colleagues that I know, they always seem the most organised and on to it.</div>Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-52206935903097031082010-04-19T18:19:00.001+01:002010-04-19T18:26:26.288+01:00Our new homeHi all,<br />
<br />
For those of you who weren't aware, as soon as I came back from New Zealand and Australia I was forced to move as the landlord was selling the place. We've found a great new Garden flat not too far from the old location but the lack of broadband at home is still killing me and is sadly stopping me from contributing to my favourite Open Source projects :(. The new place is taking shape quite rapidly now and it already has that homely feel that only good company can provide. Mind you it doesn't hurt that my wife is an extremely skilled Graphic Designer/Artist and just magically knows where things should go for maximum utility and impact (how do they do that?!). It's a good thing that she keeps me busy manually shifting things about so I don't come up with my somewhat ill thought out ideas on interior decorating.<br />
<br />
We also have our new Cat "Lucifer" (courtesy of our lovely flatmate) who is great company around the place, but his habit of scratching at the door and meowing at all hours of night is not quite as well received. But we're determined to stay strong and not let him come in and purr loudly and be cute at 3am in the morning, I wonder who's going to win :)<br />
<br />
We live in a lovely area of North London with plenty of parks and small local places/shops for local people, making it more like living in a pleasant continental European suburb than the cold concrete jungle that London can sometimes come across as. Still, as "Yummy Mummies" with their prams, countless Dog walkers and over enthusiastic joggers go by it's hard to think what I'm quite doing in this type of neighbourhood. Having started in the hustle, bustle and grime of East London, I find myself missing the soul and energy of that part of town.<br />
<br />
So if you're in the North London neighbourhood then drop me a line, I happen to know of a good pub or two to while the hours away.....<br />
<br />
Are there yet? The big bag of unpacked clothes in our bedroom says no :)Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-43812993366545830622010-04-08T12:00:00.009+01:002010-04-08T20:34:49.109+01:00Java ExperimentsHi all,<br />
<br />
So I've been frantically packing and moving over the last week which means once more I have a pithy excuse to have posted as regularly as I promised, my bad!<br />
<br />
Again this is a Java posting, so a warning to those adverse to seeing source code!<br />
<br />
I ran across another common misunderstanding with Java for those first developing with it (and indeed for some more experienced developers!). This was also highlighted in a recent <a href="http://www.thedailywtf.com/">TheDailyWTF</a> <a href="http://thedailywtf.com/Articles/Java-Destruction.aspx">article</a>. The mis-understanding is explained in the code below and is often asked about as an interview or certification question. <br />
<br />
Thanks to <a href="http://www.selikoff.net/">Scott Selikoff</a>, (I co-opted his code example).<br />
<br />
<div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">package</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> org.martijnverburg.experiments;</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><br />
</div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">/**</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * This class runs experiments to prove various pass by value </span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * and pass by reference rules in the</span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> </span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;">JDK</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> *</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * The use of System.out.println is generally frowned </span><br />
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * upon, but I'll forgive </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">myself</span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> in this case.</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> * </span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> * This probably should be a nice Unit test, many </span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> * apologies!</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> *</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * </span><b><span style="color: #7f9fbf; font-family: 'Courier New'; font-size: 10pt;">@author</span></b><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> Martijn Verburg (aka karianna)</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> */</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">public</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">class</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> PassByValuePassByReferenceExperiments</span><br />
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">{</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><br />
</div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">/**</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * Fire off the experiments</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> *</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * </span><b><span style="color: #7f9fbf; font-family: 'Courier New'; font-size: 10pt;">@param</span></b><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> args </span><span style="color: #7f7f9f; font-family: 'Courier New'; font-size: 10pt;">-</span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> Not used</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> */</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">public</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">static</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">void</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> main(String[] args)</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> PassByValuePassByReferenceExperiments test = </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">new</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> PassByValuePassByReferenceExperiments();</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> test.changeValueOfObjectPassedIn();</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span></div><br />
<div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> /**</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * This method challenges a false assumption whereby the </span><br />
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * developer may </span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';">think that when they pass an </span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';">object reference </span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * into a method as an argument, </span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';">then change the </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">value of </span><br />
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * that </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">object in the </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">method, </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">that </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">the reference they </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">hold </span><br />
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"></span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * onto in the calling </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">method retains that </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">changed value</span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';">.</span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> *</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * TODO: The explanation above isn't the clearest English, </span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * try to tidy </span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';">that up later.</span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"></span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> *</span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * If you misunderstand how this works in Java you may expect</span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"></span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * to see the </span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';">result as:</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"></span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * </span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * 10</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * 10</span></div><div> *</div><div> * The actual output of this experiment is:</div></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * </span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * 10</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * 3</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> */</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">private</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">void</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> changeValueOfObjectPassedIn()</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: medium;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> Integer x = </span><span style="font-family: 'Courier New'; font-size: 10pt;"><span class="Apple-style-span" style="color: #7f0055;"><b>new</b></span></span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> Integer(3);</span></span><br />
<span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: medium;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"></span></span><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: large;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> changeX(x)</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">;</span></span><br />
<span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: large;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"></span></span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">out</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"Value of x is = [" </span><span style="font-family: 'Courier New'; font-size: 10pt;"><span class="Apple-style-span" style="color: black;">+ x + </span></span><span style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"]</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">);</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><div class="MsoNormal" style="font-family: 'Times New Roman'; font-size: medium;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333; font-family: 'Courier New'; font-size: 13px;"> }</span></div></div></span></div><br />
<div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> /**</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * The key concept here is the the Integer x declared </span><br />
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * in the argument list</span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> for the method is a <strong>local copy</strong> </span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * of the original </span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';">reference. So when you alter its value, </span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * you're only altering the local </span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';">version, which incidentally </span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';"> * falls out </span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New';">of scope when the method ends.</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> */</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div><span class="Apple-style-span" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span></span><span class="Apple-style-span" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">private</span></b></span><span class="Apple-style-span" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span></span><span class="Apple-style-span" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">void</span></b></span><span class="Apple-style-span" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> changeX(Integer x)</span></span></div><span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; line-height: 20px;"> {</span><br />
<div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: medium;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> x = </span><span style="font-family: 'Courier New'; font-size: 10pt;"><span class="Apple-style-span" style="color: #7f0055;"><b>new</b></span></span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> Integer(10);</span></span><br />
<span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: medium;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"></span></span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">out</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"Value of x is = [" </span><span style="font-family: 'Courier New'; font-size: 10pt;"><span class="Apple-style-span" style="color: black;">+ x + </span></span><span style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"]</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">);</span><br />
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"></span><span class="Apple-style-span" style="font-family: 'Courier New';"> }</span></div><div class="MsoNormal" style="color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"></span><br />
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><div class="MsoNormal" style="font-family: 'Times New Roman'; font-size: medium;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333; font-family: 'Courier New'; font-size: 13px;">}</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333; font-family: 'Courier New'; font-size: 13px;"><br />
</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333; font-family: 'Courier New'; font-size: 13px;"><span class="Apple-style-span" style="font-family: Georgia, serif;">So are we there yet? Sadly no, all to often developers forget the fundamental rules like this and for new developers this concept can be especially confusing.</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: 'Courier New'; font-size: 13px;"><span class="Apple-style-span" style="font-family: Georgia, serif;"><br />
</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: 'Courier New'; font-size: 13px;"><span class="Apple-style-span" style="font-family: Georgia, serif;">But although some developers might look down upon those who don't have the fundamentals memorised, I actually feel that it can be OK to be a bit forgetful or hazy, after all you can't remember it all! I say that with the proviso that you should actively engage in improving your fundamentals knowledge, writing tiny test cases/experiments like the above code can be a very helpful aid.</span></span></div></div></span></div>Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-12114266919148032432010-03-31T09:49:00.001+01:002010-03-31T09:55:25.047+01:00When Order of Precedence goes badHi all,<br />
<br />
Well I told a lie about posting every week, but hey I was enjoying the sunshine in the antipodean lands (Australia and NZ)! So from here on in I'll try to keep my original promise and write _something_ every week and so here we are! Warning this post is heavily aimed at the Java world, those who prefer a non technical read had best leave now :-).<br />
<br />
So a colleague and I were tracking down a problem late last night and were looking at a particular line of code that wasn't executing in the order that the original author intended:<br />
<div><br />
</div><div><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">if</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.conditionOne() </span><span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px;">&& </span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">(</span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.conditionTwo() || </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.conditionThree())</span><span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px;">)</span></div><div><span style="color: black;"></span></div><div><br />
</div><div>Basically an assumption was made that the<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">(</span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.conditionTwo() || </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.conditionThree()) </span>would be evaluated first. We were reminded that the BEDMAS rules of arithmetic do not necessarily apply to Java order of precedence when evaluating expressions. Feel free to run the experiment below if you, like us, wanted a reminder....</div><div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="text-autospace: none;"><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">package</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> org.martijnverburg.experiments;</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><br />
</div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">/**</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * This class runs experiments to prove various order </span><br />
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * of Precedence rules in the </span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;">JDK</span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * </span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * The use of System.out.println is generally frowned </span><br />
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * upon, but I'll forgive </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">myself</span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> in this case.</span></div><div class="MsoNormal" style="text-autospace: none;"><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> * </span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> * This probably should be a nice Unit test, many </span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> * apologies!</span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * </span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * </span><b><span style="color: #7f9fbf; font-family: 'Courier New'; font-size: 10pt;">@author</span></b><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> Martijn Verburg (aka karianna)</span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> */</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">public</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">class</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> PrecedenceExperiments</span><br />
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">{</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><br />
</div><div class="MsoNormal" style="text-autospace: none;"><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">/**</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * Fire off the experiments</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * </span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * </span><b><span style="color: #7f9fbf; font-family: 'Courier New'; font-size: 10pt;">@param</span></b><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> args </span><span style="color: #7f7f9f; font-family: 'Courier New'; font-size: 10pt;">-</span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> Not used</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> */</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">public</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">static</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">void</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> main(String[] args)</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> PrecedenceExperiments test = </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">new</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> PrecedenceExperiments();</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> test.bracketedAndOrExperiment();</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><br />
</span><br />
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">/**</span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * This method tests an assumption that was made </span><br />
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * in any code base</span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> about the order of precedence </span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> * when (x && (y || z)) gets executed </span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * as</span><span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> opposed when ((y || z) && x) gets </span><br />
<span class="Apple-style-span" style="color: #3f5fbf; font-family: 'Courier New'; font-size: 13px;"> * executed.</span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> */</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">private</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">void</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> bracketedAndOrExperiment()</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span class="Apple-style-span" style="font-family: 'Courier New'; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;">// Run ((y || z) && x)</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">if</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> ((</span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.conditionTwo() || </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.conditionThree()) </span><br />
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> && </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.conditionOne())</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">out</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"Completed case: ((y || z) && x)"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">);</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"></span><br />
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"></span><br />
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><div class="MsoNormal" style="font-family: 'Times New Roman'; font-size: medium;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><br />
</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;">// Run (x && (y || z)) case</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div></div><div class="MsoNormal" style="font-family: 'Times New Roman'; font-size: medium;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">if</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.conditionOne() && </span><br />
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.conditionTwo() || </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.conditionThree()))</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div></div><div class="MsoNormal" style="font-family: 'Times New Roman'; font-size: medium;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div></div><div class="MsoNormal" style="font-family: 'Times New Roman'; font-size: medium;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">out</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"Completed case: (x && (y || z))"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">);</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div></div><div class="MsoNormal" style="font-family: 'Times New Roman'; font-size: medium;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div></div><div class="MsoNormal" style="font-family: 'Times New Roman'; font-size: medium;"></div></span><br />
<span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px;"> }</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px;"><br />
</span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">private</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">boolean</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> conditionOne()</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">out</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"1"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">);</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">true</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">;</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><br />
</div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">private</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">boolean</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> conditionTwo()</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">out</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"2"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">);</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">true</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">;</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><br />
</div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">private</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">boolean</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> conditionThree()</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">out</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"3"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">);</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">true</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">;</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px;">}</span></div><div class="MsoNormal"><br />
So are we there yet? Well I guess for the code base I'm currently working on that would be a no, we've a few more of these cases to discover and iron out. Another musing that comes out of this is that perhaps "maintainability" is sometimes better than code brevity, maybe writing code in the style of <b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">if</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (x</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> && (y</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> || z</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)) </span>can be simplified to it's component parts.<br />
<br />
Sometimes it's the little things.</div></div>Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com4tag:blogger.com,1999:blog-6459030366729235821.post-22505867833592887742010-01-18T14:46:00.000+00:002010-01-18T14:46:53.925+00:00New Zealand, Australia & ListsSo I'm heading to New Zealand and Australia for the next 6 weeks or so which will be absolutely fantastic! However, it is causing a few organisational headaches before I leave and so my last few days have been spent frantically working through my various urgent tasks before I depart the freezing shores of the UK.<br />
<br />
Some things I've discovered that have helped me in these last few days:<br />
<br />
<u>My new Macbook Pro</u><br />
<br />
<u></u>OK, I'll admit it, I'm now a fan-boy :), it's just so damn <b>easy</b> to do stuff on it! I've barely ever used Mac OS before and certainly not it's latest incarnations, but it really has been trivial to use. From downloading and installing software to configuring options it all just works through common sense. I'm super impressed with the hardware as well, it's solid yet light; quiet as a mouse and runs super, super fast.<br />
<br />
It's worth the extra cost, yes, it really, really is.<br />
<br />
<u>Gmail & Google Docs:</u><br />
<u><br />
</u><br />
Having Gmail conversations and being able to label those conversations are invaluable! Need to double check that all of my paid work related tasks are done? Simply search by "Work" label. The Java book I'm working on? The "Book" label, you get the idea :).<br />
<br />
Google docs has allowed me to share several documents with the various teams I'm working with around the world, it that information was just stuck on my computer it would be useless to everyone. The collaboration capabilities of the on-line docs is pretty darn amazing and they're constantly putting out updates to sneak the level of functionality closer to that of Microsoft Office and pals. I can see why some business now run entirely off this system!<br />
<br />
<u>Tripit.com</u><br />
<u><br />
</u><br />
Just discovered this (yeah I know, pretty rubbish for someone who travels as often as I do), do yourself a favour and join this amazing site if you ever plan on doing complicated trips, it's dead brilliant. You simply forward emails you get from airlines, hotels etc. and it's clever software puts it all into an itinerary for you and enhances it with maps, directions, weather and much more!<br />
<br />
<u>Lists:</u><br />
<u><br />
</u><br />
My wife Kerry <b>loves </b>lists, the more lists the merrier! It serves a great purpose in that during times of stress, you can always refer back to "The List" as opposed to your own memory.<br />
<br />
Hopefully I'll post photos and updates via twitter, so you can catch up on what I'm doing and where over in the lands of summer. If you're over in Australia or NZ in the next 45 days or so then drop me a line, I'd love to catch up!Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-9794187511101911652010-01-12T11:22:00.000+00:002010-01-12T11:22:04.152+00:00IE6 - Bane of the webHi all,<br />
<br />
So this is my first post in an attempt to blog once a week, we'll see how it goes :).<br />
<br />
<u>IE6 - A little help from the web</u><br />
<br />
I've been doing an awful lot of front end development recently and like so many before me I've run across the evil monster that is IE6.<br />
<br />
Unfortunately IE6 still holds onto a market share that is too large to ignore and so reluctantly I've been having to put in the various IE6 hacks that are needed to make my sites look halfway decent in that browser.<br />
<br />
So without further ado, here are some helpful links I've found:<br />
<br />
<ul><li><a href="http://css-tricks.com/examples/CleanCode/Beautiful-HTML.png">What Beautiful HTML looks like</a> - A sample on how to write beautifully laid out code.</li>
<li><a href="http://www.alistapart.com/articles/holygrail">The Holy Grail</a> - The original article on how to create CSS layouts; make sure you browse the comments for extra help!</li>
<li><a href="http://www.theholiergrail.com/">The Holier Grail</a> - Sample code for your layout needs.</li>
<li><a href="http://net.tutsplus.com/tutorials/html-css-techniques/9-most-common-ie-bugs-and-how-to-fix-them/">Fix 9 common IE bugs</a> - Workaround details.</li>
<li><a href="http://www.dillerdesign.com/experiment/DD_belatedPNG/#download">Transparent PNGs in IE6</a> - Get them working with this awesome script!</li>
<li><a href="http://www.alistapart.com/articles/taminglists/">Taming Lists</a> - How to do lists properly.</li>
</ul>So "Are we there yet?" - Until IE6 has no more market share, unfortunately not.<br />
<br />
<u>Macbook Pro 13"</u><br />
<br />
Oh and I also now have a new 13" Macbook Pro, it was so amazingly quick to set up and start using. I've literally never used OSX before and I haven't gotten stuck yet, awesome job Apple!<br />
<br />
"So are we there yet?" - Yes, yes we are :).Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-27934967394046784532009-12-17T10:05:00.003+00:002010-01-04T11:25:01.754+00:00Tips on presenting at a conferenceSo I stumped up my £95 (+VAT) and decided to go to the <a href="http://skillsmatter.com/event/cloud-grid/open-source-in-finance-exchange/wd-382">Open Source and Finance eXchange</a>. The day had some fairly interesting topics which unfortunately were (more often than not) ruined by poor presentations. This was particularly irritating as this was a paid conference and I expected a minimal level in the quality of speakers.<br />
<br />
Of course the great value in going to a conference is always the interaction with the other attendees, but still it was a little disappointing.<br />
<br />
So I thought I'd point out some tips for presenting at a conference:<br />
<br />
<ol><li>Be <strong>passionate</strong> in your delivery, no-one and I mean no-one is going to care about what you are talking about when you deliver it in a dull monotone.</li>
<li>Don't let that screen saver/power saver cut out your presentation!</li>
<li><strong>Slow Down</strong> - Often people are nervous when they present, which is only natural, but it means that they have a tendency to speak far too quickly.</li>
<li><strong>Slow Down part 2</strong> - If the language you are speaking in is not your first language, or if you know you have a strong accent, then again for the sake of clarity, slow down!</li>
<li>If you're going to have graphics in your presentation, make sure they are readable when they are projected on the screen.</li>
<li>Don't use complicated graphics, keep it simple! If in doubt get a Graphic Designer to take a look for you.</li>
<li>Don't just repeat what are on your slides, the audience has already read them and you're adding no value.</li>
</ol><br />
Thankfully towards the end of the conference we had some good speakers including probably the best presentation I've ever seen at a conference. If you ever get the chance to see Simon Wardley (from Canonical) speak, then do yourself a favour and go and see him. The podcast of his talk will arrive <a href="http://skillsmatter.com/podcast/cloud-grid/eucalyptus">here</a> soon.Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-60752641051183952742009-12-08T10:14:00.001+00:002009-12-08T10:16:05.333+00:00PCGen - An awesome online communityHi all,<br />
<br />
Just a brief note on one of the important points in running a successful Open Source community. A key ingredient is to give immediate feedback to users that post on your forums and mailing lists.<br />
<br />
An attitude of 'Go and find it yourself Newb!' is not a particularly healthy way to attract new users to your community. Don't forget that a new user is potentially a new volunteer for your project!<br />
<br />
<a href="http://pcgen.sf.net">PCGen</a> _excels_ in this area, no question big or small is left to rot on its boards and the responses are always cheery and polite. If you're looking for an example of how to respond to your users, look no further than the various mailing lists that exist under the PCGen banner (you can find them via the <a href="http://pcgen.sf.net">website</a>).<br />
<br />
The Ubuntu forums are another fames place for this type of attitude and it's certainly helped build their popularity as well.<br />
<br />
So here's a public thank you to the tireless volunteers and community users who take the time and effort to continuously reply to the tons of queries we get at PCGen, well done to you all!Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com0tag:blogger.com,1999:blog-6459030366729235821.post-23605042655510521792009-12-01T14:04:00.000+00:002009-12-01T14:04:51.187+00:00How to be a Rock Star DeveloperHere is the Google Wave text that was taken down by some helpful community members from my talk at the recent <a href="http://www.meetup.com/Londonjavacommunity/">London Java Community</a> Unconference.<br />
<br />
I plan to expand greatly on this talk with hard examples of the various points, let me know if you've got any useful examples you'd like to add!<br />
<br />
<h2>Get the Rock Star attitude</h2><br />
<ul> <li>Be passionate, care about the code</li>
<li>Be a leader - look at new approaches e.g. BDD, New JVM Languages</li>
<li>Be personable, stop and listen! - The person who directs a project the most is one that is the most effective communicator</li>
<li>help newcomers, they give you a fresh perspective - explaining things helps your understanding</li>
</ul><br />
<h2>Be inspired by the rock gods</h2><br />
<ul> <li>Don't reinvent the wheel, covers are rarely as good</li>
<li>Read blogs and community sites - stuff that is not part of your every day blogs - e.g. Kathy Sierra - high level thinking</li>
<li>Stand on the shoulders of giants - smart people have tread that path before, so use their insights</li>
</ul><br />
<h2>Be part of a band</h2><br />
<ul> <li>dont code in isolation - everyone needs a team - coding in isolation leads to be lost in your own little world - very few ideas / service that you can build that a team can't do better</li>
<li>Talk to the users early</li>
<li>The developer who communicate has most influence - many ways to communicate, try do it as clearly as possible to be effective</li>
<li>Bounce ideas off others - a wider audience can give you a wider range of feedback than your local team</li>
</ul><br />
<h2>Play a Fender Stratocaster</h2><br />
<ul> <li>Do development on a fast PC</li>
<li>Use a big tft screen or have several screens</li>
<li>Make your environment comfortable</li>
</ul><br />
<h2>Open your mind</h2><br />
<ul> <li>Learn how to look up reference material, trying not to learn api's verbatim</li>
<li>Read books on development - podcasts, video clubs etc</li>
<li>Read code by the experts - many references externally and internally</li>
<li>Learn a different type of language e.g. if you work with an OO language, dabble with a functional language, shell script - avoids the Golden hammer</li>
</ul><br />
<h2>know your studio</h2><br />
<ul> <li>Learn your ide inside out to be as productive as possible - saves 5,10,30 mins then hours a week</li>
<li>Run a continuous integration server - early feedback</li>
<li>Use source control - don't lose those songs - big investment bank lost all source code because of 2 primadonas keeping code locally and had a power glitch.</li>
<li>Know your OS/Hardware/System Architecture - sockets open, threads, etc</li>
</ul><br />
<h2>Rehersals</h2><br />
<ul> <li>Go back and enhance your old code - how do you convince the management - discuss financial impact of leaving bugs / features in the system - continuous cycle of self improvement</li>
<li>Get cold hard feedback - dont be too precious about your code - OSS has the source of a thousand eyes - commits go to a committers mailing list so people know what to review and can give feedback early - using patch files - fisheyes - no one writes perfect code</li>
<li>At least briefly research yourself before asking others - use google instead of embarassing yourself on a public mailing list</li>
<li>Run test suites</li>
</ul><br />
<h2>Polish your songs before the album release</h2><br />
<ul> <li>Keep source code neat and tidy (Checklist) - read The Daily WTF website for examples of bad formatting</li>
<li>Reduce the simple bugs (PMD, Findbugs and more) - use Find bugs to give you better ways to do things, like an expert on your shoulder</li>
<li>Comment you public apis (Javadocs) - if you provide an API define at least what to call and what to return, to otherwise people will not want to use it</li>
</ul>Martijn Verburghttp://www.blogger.com/profile/01458162075331573781noreply@blogger.com6