<?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>ComSubVie's Creative Content &#187; Java</title>
	<atom:link href="http://markus.ocrs.at/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://markus.ocrs.at</link>
	<description>a blog about computer science, rc-modeling, movies and other things...</description>
	<lastBuildDate>Thu, 18 Jun 2009 13:56:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Java ist komisch</title>
		<link>http://markus.ocrs.at/2009/01/29/java-ist-komisch/</link>
		<comments>http://markus.ocrs.at/2009/01/29/java-ist-komisch/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 22:59:58 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmieren]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=286</guid>
		<description><![CDATA[Nachdem wir heute am TGM eine kleine Diskussion hatten, wobei der Christoph behauptet hat, dass man in Java zu einem char kein int addieren kann, und ich das einfach nicht glauben konnte, musste ich das gleich mal probieren. Und er hatte fast recht. Beim ersten Versuch gelang es mir nicht, den Fehler zu erzeugen, aber [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem wir heute am TGM eine kleine Diskussion hatten, wobei der Christoph behauptet hat, dass man in Java zu einem <tt>char</tt> kein <tt>int</tt> addieren kann, und ich das einfach nicht glauben konnte, musste ich das gleich mal probieren. Und er hatte fast recht. Beim ersten Versuch gelang es mir nicht, den Fehler zu erzeugen, aber ich habe es dann doch geschafft:</p>
<p>Wenn man (also typischer Java-Programmierer, also nicht schreibfaul) programmiert ist das eigentlich einfach zu erreichen. Der folgende Code liefert beim Kompilieren eine entsprechende Fehlermeldung (<em>possible loss of precision</em> - was ja durchaus nicht falsch ist, wobei das eigentlich nur eine Warnung sein sollte, und kein Fehler, aber da ist Java ja sowieso ein bisschen komisch):</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #009900;">&#123;</span><br />
&nbsp; &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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">char</span> zeichen <span style="color: #339933;">=</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; zeichen <span style="color: #339933;">=</span> zeichen <span style="color: #339933;">+</span> x<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> zeichen <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Wobei die vom C-Programmierer favorisierte kurze Schreibweise (die auch mein erster Versuch war) problemlos funktioniert und beim Ausführen auch das erwartete Ergebnis zurückliefert:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #009900;">&#123;</span><br />
&nbsp; &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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">char</span> zeichen <span style="color: #339933;">=</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; zeichen <span style="color: #339933;">+=</span> x<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> zeichen <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Eine alternative funktionierende Lösung wäre ein entsprechendes Casten:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #009900;">&#123;</span><br />
&nbsp; &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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">char</span> zeichen <span style="color: #339933;">=</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; zeichen <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>zeichen <span style="color: #339933;">+</span> x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> zeichen <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Abschließend kann man sagen, dass sich Java da zwar schon ein bisschen seltsam verhält (es bringt zum Beispiel auch nichts nur das <tt>x</tt> auf <tt>char</tt> zu casten, man muss das Ergebnis der Addition casten. Aber zumindest funktioniert eine Addition sehr wohl, wobei die Nichtfunktionalität ja eh niemand so wirklich glauben wollte&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/01/29/java-ist-komisch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java 5 &amp; enums</title>
		<link>http://markus.ocrs.at/2009/01/16/java-5-enums/</link>
		<comments>http://markus.ocrs.at/2009/01/16/java-5-enums/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 13:02:35 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Humor]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmieren]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=121</guid>
		<description><![CDATA[Christoph hat mir letztens einen Link geschickt: No, silly! It&#8217;s an enum! Ich habe mich dabei beim Lesen königlich amüsiert, das könnte durchaus die reale Entstehungsgeschichte der Java-Enums sein. Kurz zusammengefasst:
JLD#3: So an enum is&#8230; a non-instantiable, memberless, final class with subclasses, members and instances?
JLD#2: Yes!
JLD#1: Precisely!
JLD#3: But that&#8217;s just a plain old class!
JLD#1: No, silly! It&#8217;s an enum!
Java ist zum [...]]]></description>
			<content:encoded><![CDATA[<p>Christoph hat mir letztens einen Link geschickt: <a href="http://maycontaintracesofbolts.blogspot.com/2009/01/no-silly-its-enum.html">No, silly! It&#8217;s an enum!</a> Ich habe mich dabei beim Lesen königlich amüsiert, das könnte durchaus die reale Entstehungsgeschichte der <a href="http://java.sun.com/docs/books/tutorial/java/javaOO/enum.html">Java-Enums</a> sein. Kurz zusammengefasst:</p>
<blockquote><p><strong>JLD#3:</strong> So an enum is&#8230; a non-instantiable, memberless, final class with subclasses, members and instances?<br />
<strong>JLD#2:</strong> Yes!<br />
<strong>JLD#1:</strong> Precisely!<br />
<strong>JLD#3:</strong> But that&#8217;s just a plain old class!<br />
<strong>JLD#1:</strong> No, silly! It&#8217;s an <em>enum</em>!</p></blockquote>
<p>Java ist zum Teil schon sehr bescheuert&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2009/01/16/java-5-enums/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EJB Again</title>
		<link>http://markus.ocrs.at/2008/05/21/ejb-again/</link>
		<comments>http://markus.ocrs.at/2008/05/21/ejb-again/#comments</comments>
		<pubDate>Wed, 21 May 2008 11:30:33 +0000</pubDate>
		<dc:creator>ComSubVie</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Programmieren]]></category>

		<guid isPermaLink="false">http://markus.ocrs.at/?p=155</guid>
		<description><![CDATA[Ich habe wieder einmal feststellen müssen, das man wahrhaftig viel Zeit mit Enterprise JavaBeans verscheißen kann. Ich hab mir nur eine kleine TestBean gebaut (inzwischen ist es schon ein bisschen mehr), die einen Kunden persistieren soll, bzw. aktualisieren falls dieser schon existiert. Der erste Versuch war wie folgt:
1234567891011121314public Long addCustomer&#40; String userName, String password, String [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe wieder einmal feststellen müssen, das man wahrhaftig viel Zeit mit Enterprise JavaBeans verscheißen kann. Ich hab mir nur eine kleine TestBean gebaut (inzwischen ist es schon ein bisschen mehr), die einen Kunden persistieren soll, bzw. aktualisieren falls dieser schon existiert. Der erste Versuch war wie folgt:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> addCustomer<span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> userName, <span style="color: #003399;">String</span> password, <span style="color: #003399;">String</span> firstName, <span style="color: #003399;">String</span> lastName, <span style="color: #003399;">String</span> emailAddress <span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Customer customer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Customer<span style="color: #009900;">&#40;</span> userName, password, firstName, lastName, emailAddress <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; entityManager.<span style="color: #006633;">persist</span><span style="color: #009900;">&#40;</span> customer <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> EntityExistsException eee <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> sQuery <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select c from &quot;</span> <span style="color: #339933;">+</span> Customer.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; c where c.userName = :userName&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Query cQuery <span style="color: #339933;">=</span> entityManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span> sQuery <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cQuery.<span style="color: #006633;">setParameter</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;userName&quot;</span>, userName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; customer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Customer<span style="color: #009900;">&#41;</span> cQuery.<span style="color: #006633;">getSingleResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> customer.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Damit bekam ich aber dauernd eine Invalid Transaction Exception (ich hab mir nicht gemerkt wie die blöde Exception genau geheißen hat), wenn der Kunde bereits persistent ist.</p>
<p>Das Problem ist, dass eine EntityExistsException die aktuelle Transaction zum rollbacken markiert, und diese daher nicht mehr gültig ist. Wenn man das Ganze umdreht funktioniert’s auf wundersame Weise auf einmal:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> addCustomer<span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> userName, <span style="color: #003399;">String</span> password, <span style="color: #003399;">String</span> firstName, <span style="color: #003399;">String</span> lastName, <span style="color: #003399;">String</span> emailAddress <span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Customer customer<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> sQuery <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select c from &quot;</span> <span style="color: #339933;">+</span> Customer.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; c where c.userName = :userName&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Query cQuery <span style="color: #339933;">=</span> entityManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span> sQuery <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cQuery.<span style="color: #006633;">setParameter</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;userName&quot;</span>, userName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; customer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Customer<span style="color: #009900;">&#41;</span> cQuery.<span style="color: #006633;">getSingleResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* update fields*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; entityManager.<span style="color: #006633;">merge</span><span style="color: #009900;">&#40;</span> customer <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span> NoResultException nre <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; customer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Customer<span style="color: #009900;">&#40;</span> userName, password, firstName, lastName, emailAddress <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; entityManager.<span style="color: #006633;">persist</span><span style="color: #009900;">&#40;</span> customer <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> customer.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://markus.ocrs.at/2008/05/21/ejb-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
