<?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>Tigraine &#187; Java</title>
	<atom:link href="http://www.tigraine.at/category/programmierung/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tigraine.at</link>
	<description>Daniel Hoelbling talks about programming</description>
	<lastBuildDate>Fri, 03 Feb 2012 00:02:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Never assume! Stack iterators in Java</title>
		<link>http://www.tigraine.at/2010/05/12/never-assume-stack-iterators-in-java/</link>
		<comments>http://www.tigraine.at/2010/05/12/never-assume-stack-iterators-in-java/#comments</comments>
		<pubDate>Wed, 12 May 2010 08:43:13 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2010/05/12/never-assume-stack-iterators-in-java/</guid>
		<description><![CDATA[I spent almost 2 hours of debugging Java code yesterday due to one assumption that proved fatally wrong: I assumed a Stack, by definition a LIFO data structure would iterate over it’s elements from the top of the stack to the bottom. So inserting 1, 2, 3 the resulting order when iterating through the stack [...]]]></description>
			<content:encoded><![CDATA[<p>I spent almost 2 hours of debugging Java code yesterday due to one assumption that proved fatally wrong: I assumed a Stack, by definition a <a href="http://en.wikipedia.org/wiki/LIFO">LIFO</a> data structure would iterate over it’s elements from the top of the stack to the bottom. </p>
<p>So inserting 1, 2, 3 the resulting order when iterating through the stack should be 3, 2, 1.</p>
<p>Well, at least that’s what .NET does. Java is different. Look at the following Java code:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:ce41b27c-d44a-4660-a061-e7dbd1266df2" class="wlWriterEditableSmartContent">
<pre name="code" class="java">
Stack&lt;Integer&gt; stack = new Stack&lt;Integer&gt;();
stack.push(1);
stack.push(2);
stack.push(3);

for(Integer i : stack) {
	System.out.println(i);
}
</pre>
</div>
<p>And this C#:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:e36e607a-e4c1-4b13-adeb-c0b33588b3ab" class="wlWriterEditableSmartContent">
<pre name="code" class="csharp">
var stack = new Stack&lt;int&gt;();
stack.Push(1);
stack.Push(2);
stack.Push(3);

foreach (var i in stack)
{
&#160;&#160;&#160;&#160;Console.WriteLine(i);
}
</pre>
</div>
<p>Well, they look exactly the same, but Java will return 1,2,3 while C# will honor the Stack’s special semantics and return 3,2,1. Great stuff isn’t it?</p>
<p>The workaround was quite simple, yet it had cost me 2 hours of my life trying to hunt a bug in my code, never thinking the bug could lie in a simple foreach iteration through the stack.. </p>
<p>Lesson learned: Never assume you know anything about data structure semantics unless you have checked that your assumptions are indeed true. Implementations differ and sometimes this will bite you.</p>
<p>Oh and did I mention that the way Java does it is simply wrong?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2010/05/12/never-assume-stack-iterators-in-java/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>C# Talk</title>
		<link>http://www.tigraine.at/2007/12/14/c-talk/</link>
		<comments>http://www.tigraine.at/2007/12/14/c-talk/#comments</comments>
		<pubDate>Fri, 14 Dec 2007 17:53:51 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programmiersprache]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2007/12/14/c-talk/</guid>
		<description><![CDATA[Now and then I delve through some Java tutorials or Java applications for my studies. And everytime I do so I immediately lack the getter/setter language features of C#. To make myself clear (to non-C# Developers). Java has either Public or Private properties, but no way to add validation Logic etc to those. It is [...]]]></description>
			<content:encoded><![CDATA[<p>Now and then I delve through some Java tutorials or Java applications for my studies.<br />
And everytime I do so I immediately lack the getter/setter language features of C#.</p>
<p>To make myself clear (to non-C# Developers).<br />
Java has either <em>Public </em>or <em>Private</em> properties, but no way to add validation Logic etc to those.<br />
It is usually considered bad coding technique to expose instance variables outside of the class so almost everything has to be accessed through functions.<br />
So to expose a integer variable called <strong><em>State </em></strong>you would have to create something similar to this:</p>
<p><img border="0" width="305" src="http://www.tigraine.at/wp-content/uploads/2007/12/get-set-java.jpg" alt="get_set_Java" height="112" style="border: 0px" /> </p>
<p>It works and once you&#8217;re used to it you will create setter/getter methods in your sleep.<br />
But, when pulling up your IntelliSense (ok, you don&#8217;t have that in Java, but you know what I mean) on that class you will be somewhat overwhelmed by get/set functions <img src='http://www.tigraine.at/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>So, how did C# handle this?<br />
They borrowed a bit from Delphi and C# and created properties with get/set blocks (nothing new).<br />
So our code from above would look like:</p>
<p><font color="#333333"><img border="0" width="291" src="http://www.tigraine.at/wp-content/uploads/2007/12/get-set-c.jpg" alt="get_set_C" height="127" style="border: 0px" /> </font></p>
<p>The great thing: Intellisense gets easier, you have something clearly marked as <strong>property</strong> not as function (that&#8217;s used to access a property).<br />
Usability for your API has just increased <img src='http://www.tigraine.at/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>But, despite the awesomeness of this function (already in the .NET Framework since 1.0) in .NET 3.5 they managed to improve this feature a bit.<br />
How? Imagine all those cases where you don&#8217;t have any validator logic on your properties, you just want a simple public field in your class.<br />
In older Frameworks you&#8217;d have to create get/set Blocks for this Field although you don&#8217;t want any logic there (exposing Instance-Variables is stupid no matter how you do it).</p>
<p>So, 3.5 Introduced this:</p>
<p><img border="0" width="271" src="http://www.tigraine.at/wp-content/uploads/2007/12/get-set-35.jpg" alt="get_set_35" height="40" style="border: 0px" /></p>
<p>Great, we came down to 1 line of code, and what happened?<br />
.NET creates the private instance-variable automatically and handles the simple get/set stuff for us. When we decide we need validation or something in the get/set blocks we can just come back and expand those blocks without having to change any code outside the class (it was a get/set property all the time)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2007/12/14/c-talk/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Interessanter Ansatz für ein Server-Protokoll</title>
		<link>http://www.tigraine.at/2007/11/08/interessanter-ansatz-fur-ein-server-protokoll/</link>
		<comments>http://www.tigraine.at/2007/11/08/interessanter-ansatz-fur-ein-server-protokoll/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 00:35:11 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Protokoll]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Studium]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2007/11/08/interessanter-ansatz-fur-ein-server-protokoll/</guid>
		<description><![CDATA[Ich glaube mir ist aus Versehen was interessantes gelungen. Im Rechnernetze Kurs an der Uni war von uns gefragt ein eigenes Protokoll für einen Socket Server unter Java zu entwerfen. Im Grunde wollten man wohl ein relativ simples HTTP ähnliches Protokoll mit GET, POST und LIST von uns. Ich musste aber natürlich über das Ziel [...]]]></description>
			<content:encoded><![CDATA[<p>Ich glaube mir ist aus Versehen was interessantes gelungen.</p>
<p>Im Rechnernetze Kurs an der Uni war von uns gefragt ein eigenes Protokoll für einen Socket Server unter Java zu entwerfen.</p>
<p>Im Grunde wollten man wohl ein relativ simples HTTP ähnliches Protokoll mit GET, POST und LIST von uns. Ich musste aber natürlich über das Ziel hinwegballern.</p>
<p>Rausgekommen ist ein IMAP ähnlicher Socket-Server der nicht nur für jedes Socket einen Thread öffnet sondern auch für jeden Command einen weiteren startet um nie zu blockieren.<br />
Und auch wenn das jetzt ziemlich brutal klingt, der tiefere Sinn dahinter war der dass man dadurch Befehle aneinanderreihen kann und das im Server sehr simpel über Thread.join() gelöst wird.</p>
<p>Spezielles zum Konzept und der Paket Syntax gibts unter more.</p>
<p><a href="http://www.tigraine.at/wp-content/uploads/2007/11/javaserver.JPG" title="Java Source Code of Packet Spec"><img src="http://www.tigraine.at/wp-content/uploads/2007/11/javaserver.JPG" alt="Java Source Code of Packet Spec" /></a></p>
<p>Sämtliche Befehle werden mit einem Token prefixed (wie in <a href="http://www.faqs.org/rfcs/rfc3501.html">IMAP</a>) und dieser Token wird vom ClientHandler (der eigene Thread für jeden Client) in einer Hashtable als Key angelegt während der zu launchende Thread (CommandExecution) die Value ist. Existiert der Key bereits in der Hashtable so wird der alte Thread durch den gerade neuen ersetzt und der neue macht Thread.join() auf den alten. Dadurch wird der neue erst ausgeführt wenn der alte Befehl abgearbeitet ist, also dessen run() Methode durch ist.<br />
Der Token diehnt auch dazu dass der Client die Response vom Server zuordnen kann (wie in IMAP).</p>
<p>Was auf jeden Fall noch verändert werden muss bevor man damit irgendwas bauen kann ist dass alles auf Threadpools umgebaut werden muss (Das andauernde Threads starten frisst enorm Ressourcen). Außerdem ist der Server momentan sehr verwundbar gegen <a href="http://de.wikipedia.org/wiki/Denial_of_Service">DoS</a> Attacken.</p>
<p>Ich werde versuchen bis nächste Woche mal den Java Code soweit aufzubereiten dass ich ihn ohne mir Spott und Hohn einzuhandeln hier unter der GPL herzeigen kann.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2007/11/08/interessanter-ansatz-fur-ein-server-protokoll/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I hate Java</title>
		<link>http://www.tigraine.at/2007/10/06/i-hate-java/</link>
		<comments>http://www.tigraine.at/2007/10/06/i-hate-java/#comments</comments>
		<pubDate>Sat, 06 Oct 2007 18:39:07 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Rechnernetze]]></category>
		<category><![CDATA[Studium]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2007/10/06/i-hate-java/</guid>
		<description><![CDATA[Gut dass ich mir sicher sein kann das das nicht wirklich viele Leute lesen, sonst müsste ich wohl einen Flame-War allein wegen der Überschrift fürchten, ganz zu schweigen von dem was noch kommt. Aber zurück zum Thema. Gute Vorsätze fürs Semester und so wollte heute erstmalig umgesetzt werden und ich hab mich an die Rechnernetze [...]]]></description>
			<content:encoded><![CDATA[<p>Gut dass ich mir sicher sein kann das das nicht wirklich viele Leute lesen, sonst müsste ich wohl einen Flame-War allein wegen der Überschrift fürchten, ganz zu schweigen von dem was noch kommt.</p>
<p>Aber zurück zum Thema.<br />
Gute Vorsätze fürs Semester und so wollte heute erstmalig umgesetzt werden und ich hab mich an die Rechnernetze Aufgabe rangemacht.<br />
Die Sache fing simpel an, <a href="http://www.eclipse.org/downloads" target="_blank">Eclipse</a> runterladen und installieren, und los gehts.<br />
Zwei vorgefertigte Klassen implementieren und jeweils eine Read und Write Methode erstellen die die Klasse auf die Festplatte als Datei schreiben würde.</p>
<p>Bisher eigentlich ganz simpel, und eigentlich sollte es auch so bleiben dachte ich. Löblicherweise wurde sogar ein Link zu einem <a href="http://java.sun.com/docs/books/tutorial/essential/io/datastreams.html" target="_blank">DataStream</a> Tutorial gegeben und nach einigem herumgesuche hab ich es sogar geschafft (unter Zuhilfenahme der <a href="http://java.sun.com/j2se/1.5.0/docs/api/" target="_blank">Javadoc</a>) ein halbwegs funktionierendes Programm zusammenzuzimmern.</p>
<p>Nun, warum hasse ich also Java?<br />
Ein 30 Zeilen Programm hat mich fast 2 Stunden Arbeit gekostet. Herumprobieren mit dem Code, herumspielen mit der IDE, Debugger testen (Guter Tipp: <em><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Throwable.html#printStackTrace()" target="_blank">Exception.printStackTrace()</a></em> ist dein bester Freund!)<br />
Und das beste: Ich bin nicht fertig und habe noch 3 Punkte am Aufgabenblatt vor mir.</p>
<p>Denn: Nachdem der erste Teil der Aufgabe simpel war (Ein Objekt das nicht Serializable ist auf die Platte zu schreiben) scheitere ich wohl an der zweiten Aufgabenstellung. Nämlich ein Collection Objekt in eine File zu schreiben.</p>
<p>An und für sich auch simpel, ich habe nur keinerlei Lust den gesamten <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/DataOutputStream.html#writeUTF(java.lang.String)" target="_blank">Stream.writeUTF</a> Mist den ich schon für das einzelne Objekt geschriebne habe nochmal in der Collection Klasse erneut zu schreiben mit irgendwelchen armen Count variablen etc. Eklige Sache.</p>
<p>Nun, eigentlich kann Java garnichts dafür, unter .NET wäre die Sache ähnlich verzwickt, nur dass ich mich da mit der Sprache soviel sicherer fühle dass das ganze bis zu dem aktuellen Punkt wohl nur 10 Minuten gedauert hätte.</p>
<p>Übrigens, sagte ich schon dass ich das neue Eclipse ziemlich gut finde? Vor allem das Word-Hopping <img src='http://www.tigraine.at/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Mit CRTL+Pfeiltaste kommt man innerhalb eines Wortes anhand des <a href="http://en.wikipedia.org/wiki/Camel_case" target="_blank">Camel Casings</a> weiter. Also bis zum nächsten großgeschriebenen Wort (genial wenn alle Variablen z.B. strInputParam2 etc heißen)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2007/10/06/i-hate-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

