<?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>Think In Geek &#187; Java</title>
	<atom:link href="http://thinkingeek.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://thinkingeek.com</link>
	<description>In geek we trust</description>
	<lastBuildDate>Wed, 01 Feb 2012 14:45:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Fix Java GUI applications in xmonad</title>
		<link>http://thinkingeek.com/2012/01/24/fix-java-gui-applications-xmonad/</link>
		<comments>http://thinkingeek.com/2012/01/24/fix-java-gui-applications-xmonad/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 15:00:12 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[rubymine]]></category>
		<category><![CDATA[xmonad]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=228</guid>
		<description><![CDATA[If you ever try to run a GUI Java application when using xmonad as the Window Manager, you&#8217;ll probably end up with a nice flat grey window where your buttons, toolbars and other desktop GUI goodies should be. I ran into that problem the other day when trying to evaluate the RubyMine Ruby on Rails [...]]]></description>
			<content:encoded><![CDATA[<p>
If you ever try to run a GUI Java application when using <a href="http://www.xmonad.org" onclick="pageTracker._trackPageview('/outgoing/www.xmonad.org?referer=');">xmonad</a> as the Window Manager, you&#8217;ll probably end up with a nice flat grey window where your buttons, toolbars and other desktop GUI goodies should be. I ran into that problem the other day when trying to evaluate the <a href="http://www.jetbrains.com/ruby/" onclick="pageTracker._trackPageview('/outgoing/www.jetbrains.com/ruby/?referer=');">RubyMine Ruby on Rails IDE</a> from which I heard such good things. After a rather painful installation of the official Java 6 JDK from Oracle in Ubuntu Lucid Lynx (which I&#8217;ll write about in some other time), I managed to start up RubyMine just to find out I was seeing absolutely nothing on the screen.
</p>
<p>
I Googled a bit and essentially I found out that the problem was with the Java GUI Toolkit rather than RubyMine, because <a href="http://www.haskell.org/haskellwiki/Xmonad/Frequently_asked_questions#Problems_with_Java_applications.2C_Applet_java_console" onclick="pageTracker._trackPageview('/outgoing/www.haskell.org/haskellwiki/Xmonad/Frequently_asked_questions_Problems_with_Java_applications.2C_Applet_java_console?referer=');">the framework relies on a list of window managers to handle some things, and xmonad is not in that list</a>.
</p>
<p>
So since I was not using OpenJDK, I opted for the <code>setWMName</code> option and added this final line into my <code>xmonad.hs</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">    xmonad <span style="color: #339933; font-weight: bold;">$</span> defaultConfig
      <span style="color: green;">&#123;</span> terminal            <span style="color: #339933; font-weight: bold;">=</span> myTerminal
      <span style="color: #339933; font-weight: bold;">,</span> workspaces          <span style="color: #339933; font-weight: bold;">=</span> myWorkspaces
      <span style="color: #339933; font-weight: bold;">,</span> keys                <span style="color: #339933; font-weight: bold;">=</span> keys'
      <span style="color: #339933; font-weight: bold;">,</span> modMask             <span style="color: #339933; font-weight: bold;">=</span> modMask'
      <span style="color: #339933; font-weight: bold;">,</span> layoutHook          <span style="color: #339933; font-weight: bold;">=</span> layoutHook'
      <span style="color: #339933; font-weight: bold;">,</span> manageHook          <span style="color: #339933; font-weight: bold;">=</span> manageHook'
      <span style="color: #339933; font-weight: bold;">,</span> logHook             <span style="color: #339933; font-weight: bold;">=</span> myLogHook dzenLeftBar <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> fadeInactiveLogHook 0xdddddddd
      <span style="color: #339933; font-weight: bold;">,</span> normalBorderColor   <span style="color: #339933; font-weight: bold;">=</span> colorNormalBorder
      <span style="color: #339933; font-weight: bold;">,</span> focusedBorderColor  <span style="color: #339933; font-weight: bold;">=</span> colorFocusedBorder
      <span style="color: #339933; font-weight: bold;">,</span> borderWidth         <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">2</span>
      <span style="color: #339933; font-weight: bold;">,</span> startupHook         <span style="color: #339933; font-weight: bold;">=</span> setWMName <span style="background-color: #3cb371;">&quot;LG3D&quot;</span>
<span style="color: green;">&#125;</span></pre></div></div>

</p>
<p>
Setting the window manager name to <em>LG3D</em> will trick the Java GUI Toolkit and the application will be painted correctly.
</p>
<p>
Enjoy your Java applications with the power of xmonad!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2012%2F01%2F24%2Ffix-java-gui-applications-xmonad%2F&amp;title=Fix%20Java%20GUI%20applications%20in%20xmonad" id="wpa2a_2" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2012_2F01_2F24_2Ffix-java-gui-applications-xmonad_2F_amp_title=Fix_20Java_20GUI_20applications_20in_20xmonad?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2012/01/24/fix-java-gui-applications-xmonad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# and the StringBuilder class</title>
		<link>http://thinkingeek.com/2008/07/16/c-and-the-stringbuilder-class/</link>
		<comments>http://thinkingeek.com/2008/07/16/c-and-the-stringbuilder-class/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 17:07:37 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[programming tips]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=67</guid>
		<description><![CDATA[This morning I was working on a project at work. It&#8217;s a Web Application using the ASP .NET 2.0 framework and C# as a code behind language. My friend Ioannis came over to see what was I doing and when he saw I was appending some strings together he asked me this question: &#8220;are you [...]]]></description>
			<content:encoded><![CDATA[<p>This morning I was working on a project at work. It&#8217;s a Web Application using the ASP .NET 2.0 framework and C# as a code behind language. My friend Ioannis came over to see what was I doing and when he saw I was appending some strings together he asked me this question: &#8220;<em>are you using a StringBuilder to use those strings?</em>&#8220;. And I replied with this answer: &#8220;<em>no, I am not</em>&#8220;. This kind of stupid dialog came over because last week we were discussing about using StringBuilders instead of the default String class operators to append strings each other in Java. It seemed using the StringBuilder class resulted in an overall performance gain. It was then when I asked: &#8220;<em>don&#8217;t tell me this happens with C#, too?</em>&#8220;. And he answered: &#8220;<em>yes, it does!</em>&#8220;.</p>
<p>So, what&#8217;s the matter with StringBuilders in C#?</p>
<p><span id="more-67"></span></p>
<p>It seems the same thing happens with Strings, C# and Java. Here is a copy paste from the <a href="http://msdn2.microsoft.com/en-us/library/2839d5h5%28vs.80%29.aspx" onclick="pageTracker._trackPageview('/outgoing/msdn2.microsoft.com/en-us/library/2839d5h5_28vs.80_29.aspx?referer=');">MSDN web page</a> about the StringBuilder usage:</p>
<blockquote><p>
The <strong>String</strong> object is immutable. Every time you use one of the methods in the <strong>System.String</strong> class, you create a new string object in memory, which requires a new allocation of space for that new object. In situations where you need to perform repeated modifications to a string, the overhead associated with creating a new <strong>String</strong> object can be costly. The <a href="http://msdn2.microsoft.com/en-us/library/system.text.stringbuilder%28VS.80%29.aspx" onclick="pageTracker._trackPageview('/outgoing/msdn2.microsoft.com/en-us/library/system.text.stringbuilder_28VS.80_29.aspx?referer=');">System.Text.StringBuilder</a> class can be used when you want to modify a string without creating a new object. For example, using the <strong>StringBuilder</strong> class can boost performance when concatenating many strings together in a loop.
</p></blockquote>
<p>
So I decided to run some tests to see how much it was worth to change my code to use the StringBuilder class, because I use the string &#8216;+&#8217; operator a lot in my program, and the results are simply amazing. Here you can find a chart comparing the times it took to concatenate a given number of strings using both methods. See for yourself and then&#8230; use StringBuilders from now on!
</p>
<div id="attachment_68" class="wp-caption aligncenter" style="width: 310px"><a href="http://thinkingeek.com/wp-content/uploads/2008/11/string.png"  rel="lightbox[roadtrip]"><img src="http://thinkingeek.com/wp-content/uploads/2008/11/string-300x180.png" alt="String usage" title="String usage" width="300" height="180" class="size-medium wp-image-68" /></a><p class="wp-caption-text">String usage</p></div>
<div id="attachment_69" class="wp-caption aligncenter" style="width: 310px"><a href="http://thinkingeek.com/wp-content/uploads/2008/11/stringbuilder.png"  rel="lightbox[roadtrip]"><img src="http://thinkingeek.com/wp-content/uploads/2008/11/stringbuilder-300x180.png" alt="StringBuilder usage" title="StringBuilder usage" width="300" height="180" class="size-medium wp-image-69" /></a><p class="wp-caption-text">StringBuilder usage</p></div>
<p>
Here&#8217;s the source code i used if you want to try it for yourself:
</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Adapdev.Diagnostics</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> SBuilder
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">class</span> Program
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            HiPerfTimer timer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HiPerfTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">100</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                StringBuilder sb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1000</span> <span style="color: #008000;">&lt;</span>strong<span style="color: #008000;">&gt;</span> i<span style="color: #008000;">;</span> j<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    sb<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span>j<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">double</span> timeStringBuilder <span style="color: #008000;">=</span> timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #6666cc; font-weight: bold;">string</span> s <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
                timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1000</span> <span style="color: #008000;">&lt;/</span>strong<span style="color: #008000;">&gt;</span> i<span style="color: #008000;">;</span> j<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    s <span style="color: #008000;">+=</span> j<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">double</span> timeString <span style="color: #008000;">=</span> timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">;</span>
&nbsp;
                StringBuilder line <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                line<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1000</span> <span style="color: #008000;">*</span> i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                line<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                line<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span>timeStringBuilder<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                line<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                line<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span>timeString<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Console</span><span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>
You can download the external timer classes from <a href="http://www.codeproject.com/csharp/highperformancetimercshar.asp" onclick="pageTracker._trackPageview('/outgoing/www.codeproject.com/csharp/highperformancetimercshar.asp?referer=');">The Code Project</a>.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2008%2F07%2F16%2Fc-and-the-stringbuilder-class%2F&amp;title=C%23%20and%20the%20StringBuilder%20class" id="wpa2a_4" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2008_2F07_2F16_2Fc-and-the-stringbuilder-class_2F_amp_title=C_23_20and_20the_20StringBuilder_20class?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2008/07/16/c-and-the-stringbuilder-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

