<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>And now here&#039;s something… &#187; java</title>
	<atom:link href="http://christiansons.net/mike/blog/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://christiansons.net/mike/blog</link>
	<description>Java, Ant, SVN, Jetty, cygwin and other stuff…</description>
	<lastBuildDate>Fri, 02 Dec 2011 16:53:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Global unique identifiers in Java, the easy way</title>
		<link>http://christiansons.net/mike/blog/2011/11/global-unique-identifiers-in-java-the-easy-way/</link>
		<comments>http://christiansons.net/mike/blog/2011/11/global-unique-identifiers-in-java-the-easy-way/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 22:50:03 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://christiansons.net/mike/blog/?p=759</guid>
		<description><![CDATA[A recent attempt at creating a unique identifier at work was shot down in flames by Findbugs. My naïve attempt wasn&#8217;t very thoughtful but seemed to work. Integer.toString&#40;Math.abs&#40;random.nextInt&#40;&#41;&#41;&#41; Findbugs indicated there was a possibility that I might end up with a negative value even though I &#8220;cleverly&#8221; used Math.abs(). RV: Bad attempt to compute absolute <a href='http://christiansons.net/mike/blog/2011/11/global-unique-identifiers-in-java-the-easy-way/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>A recent attempt at creating a unique identifier at work was shot down in flames by Findbugs. My naïve attempt wasn&#8217;t very thoughtful but seemed to work.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">abs</span><span style="color: #009900;">&#40;</span>random.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Findbugs indicated there was a possibility that I might end up with a negative value even though I &#8220;cleverly&#8221; used <tt>Math.abs()</tt>.</p>
<blockquote><p>RV: Bad attempt to compute absolute value of signed random integer <a href="http://findbugs.sourceforge.net/bugDescriptions.html#RV_ABSOLUTE_VALUE_OF_RANDOM_INT">(RV_ABSOLUTE_VALUE_OF_RANDOM_INT)</a></p>
<p>If the number returned by the random number generator is Integer.MIN_VALUE, then the result will be negative as well</p></blockquote>
<p>Even though I didn&#8217;t need this random id to be perfect &#8212; the unintended side-effect wasn&#8217;t a technical problem since I used it as a String &#8212; I still wanted to fix it. Stackoverflow to the rescue.</p>
<p>A <a href="http://stackoverflow.com/questions/7567350/findbugs-rv-absolute-value-of-random-int-warning">question-and-answer from Stackoverflow</a> pointed the way to the solution: <tt><a href="http://download.oracle.com/javase/6/docs/api/java/util/UUID.html">java.util.UUID</a></tt>. Somehow, I missed that Sun had added Java&#8217;s own universally unique identifier (UUID) generator in Java 1.5.</p>
<p>In the end, I happily replaced my homemade id generator with Java&#8217;s.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">UUID.<span style="color: #006633;">randomUUID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>The output of which is something like <tt>1c312843-8903-411f-88b2-ff1b92ca80ba</tt>.</p>
<p><em>Cross-posted at <a href="http://java.dzone.com/articles/global-unique-identifiers-java">http://java.dzone.com/articles/global-unique-identifiers-java</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2011/11/global-unique-identifiers-in-java-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java 7 : Fork and Join</title>
		<link>http://christiansons.net/mike/blog/2011/08/java-7-fork-and-join/</link>
		<comments>http://christiansons.net/mike/blog/2011/08/java-7-fork-and-join/#comments</comments>
		<pubDate>Thu, 11 Aug 2011 17:38:22 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[forkjoin]]></category>
		<category><![CDATA[java7]]></category>

		<guid isPermaLink="false">http://christiansons.net/mike/blog/?p=747</guid>
		<description><![CDATA[Check out Julien Ponge&#8217;s article on Fork and Join in Java 7.]]></description>
			<content:encoded><![CDATA[<p>Check out Julien Ponge&#8217;s article on <a href="http://www.oracle.com/technetwork/articles/java/fork-join-422606.html">Fork and Join in Java 7</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2011/08/java-7-fork-and-join/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notes on Java&#8217;s Date class</title>
		<link>http://christiansons.net/mike/blog/2010/09/notes-on-javas-date-class/</link>
		<comments>http://christiansons.net/mike/blog/2010/09/notes-on-javas-date-class/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 21:55:07 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[timezone]]></category>

		<guid isPermaLink="false">http://christiansons.net/mike/blog/?p=560</guid>
		<description><![CDATA[Every so often I get myself confused about Java&#8217;s often-obtuse handling of dates and timezones. So, for my future self&#8217;s benefit, here are some reminder notes&#8230; Please leave a comment if you have corrections or additional tips! (And, preemptively, yes, some day I&#8217;ll give Joda Time a try.) Dates do not have timezones; they reflect <a href='http://christiansons.net/mike/blog/2010/09/notes-on-javas-date-class/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Every so often I get myself confused about Java&#8217;s often-obtuse handling of dates and timezones.  So, for my future self&#8217;s benefit, here are some reminder notes&#8230;  <span id="more-560"></span></p>
<p>Please leave a comment if you have corrections or additional tips!  (And, preemptively, yes, some day I&#8217;ll give <a href="http://joda-time.sourceforge.net/">Joda Time</a> a try.)</p>
<ul>
<li><tt>Date</tt>s do not have timezones; <a href="http://download.oracle.com/javase/6/docs/api/java/util/Date.html"> they reflect UTC</a>.</li>
<li><a href="http://download.oracle.com/javase/6/docs/api/java/util/Date.html#toString()"><tt>Date.toString()</tt></a> returns a <tt>String</tt> representation based on the local machine&#8217;s default timezone.  This makes people think that <tt>Date</tt>s have timezones.</li>
<li>You cannot convert a <tt>Date</tt> from one timezone to another.</li>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #003399; font-weight: bold;">Calendar</span> c = <span style="color: #003399; font-weight: bold;">Calendar</span>.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
c.<span style="color: #006633;">setTime</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
c.<span style="color: #006633;">setTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTC&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399; font-weight: bold;">Date</span> utc = c.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
c.<span style="color: #006633;">setTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;America/Phoenix&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399; font-weight: bold;">Date</span> mst = c.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #339933;">!</span>utc.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>mst<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//throws AssertionError</span></pre></div></div>

<li>However, you <em>can</em> use <tt>DateFormat</tt> to affect the <tt>String</tt> representation of a <tt>Date</tt>, including the timezone.</li>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Date</span> date <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">SimpleDateFormat</span> utcFormat <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ddHHmm&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">SimpleDateFormat</span> mstFormat <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ddHHmm&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
utcFormat.<span style="color: #006633;">setTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTC&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mstFormat.<span style="color: #006633;">setTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;America/Phoenix&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> utc <span style="color: #339933;">=</span> utcFormat.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>date<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> mst <span style="color: #339933;">=</span> mstFormat.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>date<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #339933;">!</span>utc.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>mst<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//should not throw AssertionError</span></pre></div></div>

</ul>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2010/09/notes-on-javas-date-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sun Java 6 on Ubuntu 10.04 10.10 and later</title>
		<link>http://christiansons.net/mike/blog/2010/07/sun-java-6-on-ubuntu-10-04-10-10-and-later/</link>
		<comments>http://christiansons.net/mike/blog/2010/07/sun-java-6-on-ubuntu-10-04-10-10-and-later/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 16:17:04 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://christiansons.net/mike/blog/?p=512</guid>
		<description><![CDATA[Post updated 2011 Jan 19: Given the opportunity to install 10.10, I have added different instructions for Ubuntu 10.10 (Maverick Meerkat). Much to my surprise, but probably not those of the Open Source Ruling Class, Sun&#8217;s Java 6 has been removed from the Ubuntu Multiverse. Apparently the Ubuntu folks have started putting some weight behind <a href='http://christiansons.net/mike/blog/2010/07/sun-java-6-on-ubuntu-10-04-10-10-and-later/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><em><strong>Post updated 2011 Jan 19</strong>: Given the opportunity to install 10.10, I have added <a href="#1010">different instructions for Ubuntu 10.10</a> (Maverick Meerkat).</em></p>
<p>Much to my surprise, but probably not those of the Open Source Ruling Class, <a href="https://wiki.ubuntu.com/LucidLynx/ReleaseNotes#Sun%20Java%20moved%20to%20the%20Partner%20repository">Sun&#8217;s Java 6 has been removed from the Ubuntu Multiverse</a>.  Apparently the Ubuntu folks have started putting some weight behind their recommendations for switching to the &#8220;OpenJDK.&#8221;  Fortunately, the official, &#8220;proprietary&#8221; Java is still available through another Ubuntu repository.</p>
<h2 id="1010">Ubuntu 10.10</h2>
<p>To install Sun&#8217;s Java 6 JDK on Ubuntu 10.10, add the <a href="https://launchpad.net/~sun-java-community-team/+archive/sun-java6">Sun Java6 Community PPA</a> and install: </p>
<pre>
add-apt-repository ppa:sun-java-community-team/sun-java6
apt-get update
apt-get install sun-java6-jdk
update-java-alternatives -s java-6-sun
</pre>
<h2>Ubuntu 10.04</h2>
<p>To make Sun&#8217;s Java 6 JDK available on Ubuntu 10.04 add the new repository like so:</p>
<pre>
add-apt-repository "deb http://archive.canonical.com/ lucid partner"
aptitude update
aptitude install sun-java6-jdk
update-java-alternatives -s java-6-sun
</pre>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2010/07/sun-java-6-on-ubuntu-10-04-10-10-and-later/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Shutting down ehcache properly</title>
		<link>http://christiansons.net/mike/blog/2010/01/shutting-down-ehcache-properly/</link>
		<comments>http://christiansons.net/mike/blog/2010/01/shutting-down-ehcache-properly/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 17:37:29 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[ehcache]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[persistence]]></category>
		<category><![CDATA[shutdownhook]]></category>

		<guid isPermaLink="false">http://christiansons.net/mike/blog/?p=422</guid>
		<description><![CDATA[If you&#8217;re using ehcache&#8217;s disk persistence feature, which allows the cache to survive across JVM restarts, be sure to shut down ehcache properly. To do so when using ehcache within a webapp, simply add its ShutdownListener as a listener in web.xml. &#60;listener&#62; &#60;listener-class&#62;net.sf.ehcache.constructs.web.ShutdownListener&#60;/listener-class&#62; &#60;/listener&#62; Alternatively, or when not using ehcache inside a webapp, instruct ehcache <a href='http://christiansons.net/mike/blog/2010/01/shutting-down-ehcache-properly/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using ehcache&#8217;s disk persistence feature, which allows the cache to survive across JVM restarts, be sure to <a href="http://ehcache.org/documentation/shutdown.html">shut down ehcache properly</a>.</p>
<p>To do so when using ehcache within a webapp, simply add its <tt>ShutdownListener</tt> as a <tt>listener</tt> in <tt>web.xml</tt>.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>net.sf.ehcache.constructs.web.ShutdownListener<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Alternatively, or when not using ehcache inside a webapp, instruct ehcache to register its own <a href="http://java.sun.com/developer/TechTips/2000/tt0711.html">shutdown hook</a> by setting a system property.</p>
<pre>net.sf.ehcache.enableShutdownHook=true</pre>
<p>If you forget one of the above, your persisted cache may not be up-to-date, or worse, not persisted at all.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2010/01/shutting-down-ehcache-properly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Advanced Installer licensing within a Java application</title>
		<link>http://christiansons.net/mike/blog/2009/02/use-advanced-installer-licensing-within-a-java-application/</link>
		<comments>http://christiansons.net/mike/blog/2009/02/use-advanced-installer-licensing-within-a-java-application/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 03:31:34 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[advancedinstaller]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=108</guid>
		<description><![CDATA[Advanced Installer 6.7 has a new licensing and registration feature which allows for time-limited demos/trials and registration of installed software. Caphyon, the maker of Advanced Installer, provides code samples and documentation on licensing integration for C++ and C# applications. To use this feature, the application must make a call into an Advanced Installer library and <a href='http://christiansons.net/mike/blog/2009/02/use-advanced-installer-licensing-within-a-java-application/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.advancedinstaller.com/"><img alt="" src="http://www.caphyon.com/img/index/biglogo_ai.gif" title="Advanced Installer" class="alignleft" width="69" height="99" /></a>Advanced Installer 6.7 has a <a href="http://www.advancedinstaller.com/user-guide/licensing.html">new licensing and registration feature</a> which allows for time-limited demos/trials and registration of installed software.</p>
<p>Caphyon, the maker of Advanced Installer, provides code samples and <a href="http://www.advancedinstaller.com/user-guide/qat-trial.html">documentation on licensing integration</a> for C++ and C# applications.  To use this feature, the application must make a call into an Advanced Installer library and handle its return code.  </p>
<p>The library is a gatekeeper to the rest of the application, effectively deciding whether or not the application is allowed to run.  It determines the software&#8217;s trial status and displays a registration dialog, terminates the application, or returns a code, accordingly.  The Java implementation of this feature works a little differently.</p>
<p>For those using the <a href="http://www.advancedinstaller.com/user-guide/native-java-launcher.html">Java Launcher</a>, integrating the licensing feature is easy: simply add the Java Product on the <a href="http://www.advancedinstaller.com/user-guide/licensing-settings.html">Licensing Options</a> tab.  But, what about those who don&#8217;t use Java Launcher?  Or those that wish to enable users to register from within the application?</p>
<p>There is no official documentation which answers these questions, but based on a discussion following a <a href="http://www.advancedinstaller.com/forums/viewtopic.php?f=2&#038;t=8538">request for help I posted on the Advanced Installer forums</a>, I was able integrate AI&#8217;s licensing feature into my Java application without using the Java Launcher.<span id="more-108"></span></p>
<p>My solution mirrors the C++ implementation and is remarkably simple.  Thanks to Cosmin, a member of the Advanced Installer support team, for sending me in the right direction.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LicenseChecker <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> LIBRARY_KEY <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Replace this String with the Trialware/Registration Library Key&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> TrialLibrary.<span style="color: #006633;">INSTANCE</span>.<span style="color: #006633;">ReadSettingsStr</span><span style="color: #009900;">&#40;</span>LIBRARY_KEY, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//http://www.advancedinstaller.com/user-guide/qa-trial-using.html</span>
        <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">:</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thank you for registering this program.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thank you for trying this program.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Program will continue.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// ...</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">interface</span> TrialLibrary <span style="color: #000000; font-weight: bold;">extends</span> Library <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> TrialLibrary INSTANCE <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TrialLibrary<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">Native</span>.<span style="color: #006633;">loadLibrary</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Trial&quot;</span>, TrialLibrary.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// loads Trial.dll</span>
        <span style="color: #000066; font-weight: bold;">int</span> ReadSettingsStr<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> keyCode, HWND hwnd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> DisplayRegistrationStr<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> keyCode, HWND hwnd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Note: The above uses <a href="https://jna.dev.java.net/">Java Native Access (JNA)</a> to invoke the Advanced Installer library.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2009/02/use-advanced-installer-licensing-within-a-java-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GCViewer, garbage collection and heap analysis tool</title>
		<link>http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/</link>
		<comments>http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 23:46:48 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[garbagecollection]]></category>
		<category><![CDATA[gcviewer]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=94</guid>
		<description><![CDATA[One month ago I wrote about the benefits of using Java&#8217;s built-in garbage collection logging.  With it, you can find answers to important important questions such as &#8220;how much memory is my app using&#8221; and &#8220;how much time is being spent doing garbage collection.&#8221; There is, of course, a hitch: for any non-trivial application or <a href='http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>One month ago I wrote about the benefits of using <a href="http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/">Java&#8217;s built-in garbage collection logging</a>.  With it, you can find answers to important important questions such as &#8220;how much memory is my app using&#8221; and &#8220;how much time is being spent doing garbage collection.&#8221;</p>
<p>There is, of course, a hitch: for any non-trivial application or problem, you will be quickly buried by a mountainous log file.  The longer your application runs, the larger the log file.  It keeps growing, and growing, and&#8230;</p>
<div id="attachment_98" class="wp-caption alignright" style="width: 160px"><a href="http://christiansons.net/mike/blog/wp-content/uploads/2009/01/gcviewer-screenshot.png"><img class="size-thumbnail wp-image-98" title="gcviewer-screenshot" src="/mike/blog/wp-content/uploads/2009/01/gcviewer-screenshot-150x150.png" alt="GCViewer" width="150" height="150" /></a><p class="wp-caption-text">GCViewer</p></div>
<p>What will you do?  Write a second Java app, one that parses the log file &#8212; attempt a homegrown analysis tool?  No!  Instead, I suggest you use <a title="GCViewer homepage" href="http://www.tagtraum.com/gcviewer.html">GCViewer</a>, a free open-source tool for visualizing the <a href="http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/">Java gc log file</a>.</p>
<p><a title="GCViewer homepage" href="http://www.tagtraum.com/gcviewer.html">GCViewer</a> helps you get a quick and comprehensive look at how your application is behaving.  Things like total heap vs. heap used and full GC events become very apparent.  Useful statistics such as time spent during GC are calculated for your convenience.</p>
<p>GCViewer is created by <a href="http://www.tagtraum.com/">tagtraum industries</a> and is available under an <a href="http://www.gnu.org/licenses/lgpl.html">LGPL</a> license.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SeaFlow, Java app for Seattle traffic conditions</title>
		<link>http://christiansons.net/mike/blog/2008/12/seaflow-java-app-for-seattle-traffic-conditions/</link>
		<comments>http://christiansons.net/mike/blog/2008/12/seaflow-java-app-for-seattle-traffic-conditions/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 20:41:45 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[seattle]]></category>
		<category><![CDATA[traffic]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=64</guid>
		<description><![CDATA[Late in 1999, UltiMeth Systems created SeaFlow, a Java-based application for monitoring Seattle-area traffic conditions.  SeaFlow is a powerful desktop version of WSDOT&#8217;s web-based traffic map.  It uses the same WSDOT data but shows greater detail, allows customization, and reduces network traffic. SeaFlow displays vehicle speeds, density, and count metrics.  (WSDOT&#8217;s map shows only density <a href='http://christiansons.net/mike/blog/2008/12/seaflow-java-app-for-seattle-traffic-conditions/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<div id="attachment_67" class="wp-caption alignleft" style="width: 310px"><a href="http://christiansons.net/mike/blog/wp-content/uploads/2008/12/seaflow-screenshot1.png"><img class="size-medium wp-image-67" title="SeaFlow screenshot" src="/mike/blog/wp-content/uploads/2008/12/seaflow-screenshot1-300x179.png" alt="SeaFlow screenshot from Dec. 18, 2008." width="300" height="179" /></a><p class="wp-caption-text">SeaFlow screenshot from Dec. 18, 2008.</p></div>
<p>Late in 1999, <a title="homepage of UltiMeth Systems" href="http://www.ultimeth.com/">UltiMeth Systems</a> created <a title="SeaFlow homepage" href="http://www.ultimeth.com/traffic/">SeaFlow</a>, a Java-based application for monitoring Seattle-area traffic conditions.  SeaFlow is a powerful desktop version of <a title="WSDOT Seattle traffic" href="http://www.wsdot.wa.gov/traffic/seattle/">WSDOT&#8217;s web-based traffic map</a>.  It uses the same WSDOT data but shows greater detail, allows customization, and reduces network traffic.</p>
<p>SeaFlow displays vehicle speeds, density, and count metrics.  (WSDOT&#8217;s map shows only density which is certainly useful, but not a complete picture.)  The visual color representation of each metric can be customized in SeaFlow.</p>
<p>In times of peak demand, such as <a title="WSDOT blog post for 2008-12-18" href="http://wsdotblog.blogspot.com/2008/12/december-8-2008.html">December 18, 2008</a>, WSDOT&#8217;s website may become overwhelemed and yield partial or missing maps.  SeaFlow&#8217;s use of the smaller WSDOT data file &#8212; with maps rendered on the client-side &#8212; reduces demand on WSDOT&#8217;s site and can provide more reliable and complete updates.</p>
<p><a title="SeaFlow homepage" href="http://www.ultimeth.com/traffic/">SeaFlow</a> is a great Java desktop app &#8212; small, efficient, and cross-platform.  Its license is <a title="homepage of GNU GPL" href="http://www.gnu.org/licenses/gpl.html">GPL</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/12/seaflow-java-app-for-seattle-traffic-conditions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java garbage collection logging</title>
		<link>http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/</link>
		<comments>http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 08:00:56 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[garbagecollection]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=28</guid>
		<description><![CDATA[Java&#8217;s built-in garbage collection logging provides a quick, easy, and free way to profile or troubleshoot your Java application.  It can help you understand your application in terms of: memory usage (object count and size) heap size (initial and over time) GC metrics (frequency, pause time, and amount freed) So, now you can answer questions <a href='http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Java&#8217;s built-in garbage collection logging provides a quick, easy, and <em>free</em> way to profile or troubleshoot your Java application.  It can help you understand your application in terms of:</p>
<ul>
<li> memory usage (object count and size)</li>
<li>heap size (initial and over time)</li>
<li>GC metrics (frequency, pause time, and amount freed)</li>
</ul>
<p>So, now you can answer questions like &#8220;how much memory is my app using,&#8221; &#8220;how much time is being spent doing garbage collection,&#8221; and &#8220;how big is the heap over time.&#8221;</p>
<p style="border: thin dashed;">
<em>For help analyzing and visualizing a GC log file, be sure to check out <a href="http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/">GCViewer, a garbage collection and heap analysis tool</a>.</em>
</p>
<p>GC logging is enabled using JVM arguments; below are the arguments I use.  <span id="more-28"></span>(Note: the log file specified as <em>file</em> is reset each time the VM starts.)</p>
<p><code>-verbose:gc -Xloggc:<em>file</em></code></p>
<p>Here&#8217;s an example GC log file which shows three GC events including one full GC.</p>
<pre>[GC 19062K-&gt;7172K(60800K), 0.0087190 secs]
[GC 9346K-&gt;7525K(60800K), 0.0052810 secs]
[Full GC 7525K-&gt;7477K(60800K), 0.0615190 secs]</pre>
<p>In the first event, garbage collection takes just under nine thousandths of a second to collect 11,890K memory used by objects (19,062K to 7,172K) while the heap is 60,800K.  The last event is a full GC lasting just over six hundredths of a second to free up 48K with no change in the heap.</p>
<p>Data like this can be invaluable in saving one&#8217;s sanity or ending arguments! For further details on garbage collection, see Sun&#8217;s <a title="article on GC Portal" href="http://java.sun.com/developer/technicalArticles/Programming/GCPortal/">GC Portal</a> and <a title="doc on GC tuning" href="http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html">Virtual Machine Garbage Collection Tuning</a> documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Jetty, embedded servlet container</title>
		<link>http://christiansons.net/mike/blog/2008/12/jetty-embedded-servlet-container/</link>
		<comments>http://christiansons.net/mike/blog/2008/12/jetty-embedded-servlet-container/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 21:59:06 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[servlet]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=49</guid>
		<description><![CDATA[There&#8217;s no law which states web servers and servlet containers must be large, separate pieces of software.  If there were, Jetty would be a dangerous outlaw (possibly even public enemy number one).  Jetty is an open-source embeddable web server and servlet container, written in Java.  It&#8217;s small, fast, and easy to embed &#8212; perfect for <a href='http://christiansons.net/mike/blog/2008/12/jetty-embedded-servlet-container/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s no law which states web servers and servlet containers must be large, separate pieces of software.  If there were, <a title="Jetty website" href="http://www.mortbay.org/jetty/">Jetty</a> would be a dangerous outlaw (possibly even public enemy number one).  Jetty is an open-source embeddable web server and servlet container, written in Java.  It&#8217;s small, fast, and easy to embed &#8212; perfect for self-contained applications.</p>
<p>Let&#8217;s use an example to discover just how easy embedding Jetty can be.  <span id="more-49"></span>Say we have two servlets, one should be mapped to <tt>/service/one</tt> and the other <tt>/service/two</tt>, served on port <tt>8080</tt>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">Server server <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Server<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Connector connector <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SelectChannelConnector<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
connector.<span style="color: #006633;">setPort</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8080</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
server.<span style="color: #006633;">addConnector</span><span style="color: #009900;">&#40;</span>connector<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
ContextHandlerCollection contexts <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ContextHandlerCollection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
server.<span style="color: #006633;">setHandler</span><span style="color: #009900;">&#40;</span>contexts<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003399;">Context</span> context <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Context</span><span style="color: #009900;">&#40;</span>contexts, <span style="color: #0000ff;">&quot;/service&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #006633;">addServlet</span><span style="color: #009900;">&#40;</span>ServiceOne.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;/one&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #006633;">addServlet</span><span style="color: #009900;">&#40;</span>ServiceTwo.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;/two&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
server.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
server.<span style="color: #006633;">join</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>That&#8217;s it; easy.  For information and more examples on embedding Jetty in your Java application, read <a title="wiki documentation on embedding Jetty" href="http://docs.codehaus.org/display/JETTY/Embedding+Jetty">Embedding Jetty</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/12/jetty-embedded-servlet-container/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

