<?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>Tadek's Blog &#187; Java</title>
	<atom:link href="http://tadek.pietraszek.org/blog/category/tipstricks/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://tadek.pietraszek.org/blog</link>
	<description>Some random notes about computers, security, cool links and others.</description>
	<lastBuildDate>Fri, 12 Dec 2008 22:49:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>J2SE(TM) 5.0 New Features</title>
		<link>http://tadek.pietraszek.org/blog/2005/10/18/j2setm-50-new-features/</link>
		<comments>http://tadek.pietraszek.org/blog/2005/10/18/j2setm-50-new-features/#comments</comments>
		<pubDate>Tue, 18 Oct 2005 16:34:53 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2005/10/18/j2setm-50-new-features/</guid>
		<description><![CDATA[As a reminder &#8211; now that Java 1.5 has been there for a while J2SE(TM) 5.0 New Features.
]]></description>
			<content:encoded><![CDATA[<p>As a reminder &#8211; now that Java 1.5 has been there for a while <a href="http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html">J2SE(TM) 5.0 New Features</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2005/10/18/j2setm-50-new-features/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming with DOM</title>
		<link>http://tadek.pietraszek.org/blog/2005/10/04/programming-with-dom/</link>
		<comments>http://tadek.pietraszek.org/blog/2005/10/04/programming-with-dom/#comments</comments>
		<pubDate>Tue, 04 Oct 2005 13:24:08 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2005/10/04/programming-with-dom/</guid>
		<description><![CDATA[It might once prove useful:
Programming with DOM
]]></description>
			<content:encoded><![CDATA[<p>It might once prove useful:
<a href="http://xml.apache.org/xerces2-j/faq-dom.html#faq-3">Programming with DOM</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2005/10/04/programming-with-dom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swing Tutorial: High-Quality Java Printing</title>
		<link>http://tadek.pietraszek.org/blog/2005/08/25/swing-tutorial-high-quality-java-printing/</link>
		<comments>http://tadek.pietraszek.org/blog/2005/08/25/swing-tutorial-high-quality-java-printing/#comments</comments>
		<pubDate>Thu, 25 Aug 2005 11:20:06 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2005/08/25/swing-tutorial-high-quality-java-printing/</guid>
		<description><![CDATA[A tutorial on printing in Java Swing Swing Tutorial: High-Quality Java Printing
]]></description>
			<content:encoded><![CDATA[<p>A tutorial on printing in Java Swing <a href="http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing.html">Swing Tutorial: High-Quality Java Printing</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2005/08/25/swing-tutorial-high-quality-java-printing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Generating certificates in Java</title>
		<link>http://tadek.pietraszek.org/blog/2004/10/31/generating-certificates-in-java/</link>
		<comments>http://tadek.pietraszek.org/blog/2004/10/31/generating-certificates-in-java/#comments</comments>
		<pubDate>Sun, 31 Oct 2004 13:37:44 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2004/10/31/generating-certificates-in-java/</guid>
		<description><![CDATA[Generating certificates in Java jabacats and bouncycastle
]]></description>
			<content:encoded><![CDATA[<p>Generating certificates in Java <A HREF="http://jabacats.sourceforge.net">jabacats</A> and <A HREF="http://www.bouncycastle.org/">bouncycastle</A></p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2004/10/31/generating-certificates-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java 1.5 and String operators</title>
		<link>http://tadek.pietraszek.org/blog/2004/10/28/java-15-and-string-operators/</link>
		<comments>http://tadek.pietraszek.org/blog/2004/10/28/java-15-and-string-operators/#comments</comments>
		<pubDate>Thu, 28 Oct 2004 09:34:33 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2004/10/28/java-15-and-string-operators/</guid>
		<description><![CDATA[Java 1.5 changed the implementation of StringBuffer and introduced a new StringBuilder (actually both inherit from AbstractStringBuilder).  It looks + operator can be either compiled to use StringBuffer (slower, but synchronized) or StringBuilder (faster, thread unsafe).

This sucks, as our implementation of Context Sensitive String operations relies on the predictible behaviour + (uses String and [...]]]></description>
			<content:encoded><![CDATA[<p>Java 1.5 changed the implementation of StringBuffer and introduced a new StringBuilder (actually both inherit from AbstractStringBuilder).  It looks + operator can be either compiled to use StringBuffer (slower, but synchronized) or StringBuilder (faster, thread unsafe).
<span id="more-38"></span>
This sucks, as our implementation of Context Sensitive String operations relies on the predictible behaviour + (uses String and StringBuffer).</p>

<p>Well, we&#8217;ll end up with having two aspects &#8211; one for &lt;1.5 and  >=1.5. This sucks&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2004/10/28/java-15-and-string-operators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java access modifiers</title>
		<link>http://tadek.pietraszek.org/blog/2004/10/28/java-access-modifires/</link>
		<comments>http://tadek.pietraszek.org/blog/2004/10/28/java-access-modifires/#comments</comments>
		<pubDate>Thu, 28 Oct 2004 09:32:23 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2004/10/28/java-access-modifires/</guid>
		<description><![CDATA[Just a reminder:


package protected &#8211; Scope that indicates that an instance variable is visible to other classes within its same package, or to subclasses of the class containing the instance variable. This scope is the default scope in Java, and is indicated by no scope indicator.

private &#8211; Scope indicator that hides an instance variable from [...]]]></description>
			<content:encoded><![CDATA[<p>Just a reminder:</p>

<ul>
<li>package protected &#8211; Scope that indicates that an instance variable is visible to other classes within its same package, or to subclasses of the class containing the instance variable. This scope is the default scope in Java, and is indicated by no scope indicator.</li>
<li>
private &#8211; Scope indicator that hides an instance variable from all other classes, regardless of their package or their class hierarchy relationship to the class containing the variable.</li>
<li>protected &#8211; Scope indicator that makes an instance variable visible to subclasses that inherit from the class containing the instance variable.</li>

<li>public &#8211; Scope indicator that makes an instance variable visible to any class, regardless of package or class hierarchy relationship to the class containing the instance variable.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2004/10/28/java-access-modifires/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AspectJ in ANT</title>
		<link>http://tadek.pietraszek.org/blog/2004/10/27/aspectj-in-ant/</link>
		<comments>http://tadek.pietraszek.org/blog/2004/10/27/aspectj-in-ant/#comments</comments>
		<pubDate>Wed, 27 Oct 2004 07:59:51 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2004/10/27/aspectj-in-ant/</guid>
		<description><![CDATA[Supposedly works, and there are three ways of doing it. Note that there can be a problem when using it with Javac and  source lists:

&#8220;Beware of using regular source lists with this; javac may prune unchanged files, which excludes them from the compile process for ajc, which requires that all files affected by any [...]]]></description>
			<content:encoded><![CDATA[<p>Supposedly works, and there are <A HREF="http://dev.eclipse.org/viewcvs/indextech.cgi/aspectj-home/doc/ant-tasks.html?rev=1.2">three</A> ways of doing it. Note that there can be a problem when using it with Javac and  source lists:</p>

<p>&#8220;Beware of using regular source lists with this; javac may prune unchanged files, which excludes them from the compile process for ajc, which requires that all files affected by any aspects be listed explicitly.&#8221;</p>

<p>I haven&#8217;t tried it yet, but it looks like a nice thing to know.</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2004/10/27/aspectj-in-ant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XDoclet</title>
		<link>http://tadek.pietraszek.org/blog/2004/10/27/xdoclet-2/</link>
		<comments>http://tadek.pietraszek.org/blog/2004/10/27/xdoclet-2/#comments</comments>
		<pubDate>Wed, 27 Oct 2004 07:50:19 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Progs/Tools/Libs]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2004/10/27/xdoclet/</guid>
		<description><![CDATA[Xdoclett seems to be a nice way of generating web.xml descriptor based on the JavaDOC style comments in a source code. From what Chris showed me, it looks it&#8217;s quite difficult to run though.

First, the problem is that it&#8217;s not particularly verbose (even with verbose option on). Second, it looks that due to some bug [...]]]></description>
			<content:encoded><![CDATA[<p><A HREF="xdoclet.sf.net">Xdoclet</A>t seems to be a nice way of generating web.xml descriptor based on the JavaDOC style comments in a source code. From what Chris showed me, it looks it&#8217;s quite difficult to run though.
<span id="more-33"></span>
First, the problem is that it&#8217;s not particularly verbose (even with verbose option on). Second, it looks that due to some bug in it, it has problems looking for source/detination files specified through properties &lt;property name=&#8221;bla&#8221; value=&#8221;bla&#8221;&amp;gl, but it requires it to be &lt;property name=&#8221;bla&#8221; location=&#8221;bla&#8221;&amp;gl  It doesn&#8217;t seem to make much sense to me &#8211; probably there&#8217;s some bug in it.</p>

<p>Anyway, it looks like a nice technology for developing servlets.</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2004/10/27/xdoclet-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting a class name from a static method</title>
		<link>http://tadek.pietraszek.org/blog/2004/10/25/getting-a-class-name-from-a-static-method/</link>
		<comments>http://tadek.pietraszek.org/blog/2004/10/25/getting-a-class-name-from-a-static-method/#comments</comments>
		<pubDate>Mon, 25 Oct 2004 09:59:46 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2004/10/25/getting-a-class-name-from-a-static-method/</guid>
		<description><![CDATA[public class ClassFromStatic 
{
    public static void main(java.lang.String[] args) 
    {
        someStaticMethod();
    }

public static void someStaticMethod() 
{
    System.out.println("I'm in " + new CurrentClassGetter().getClassName() 
        + " class");
}

public static class [...]]]></description>
			<content:encoded><![CDATA[<p>public class ClassFromStatic 
{
    public static void main(java.lang.String[] args) 
    {
        someStaticMethod();
    }</p>

<pre><code>public static void someStaticMethod() 
{
    System.out.println("I'm in " + new CurrentClassGetter().getClassName() 
        + " class");
}

public static class CurrentClassGetter extends SecurityManager 
{
    public String getClassName() 
    {
        return getClassContext()[1].getName();
    }
}
</code></pre>

<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2004/10/25/getting-a-class-name-from-a-static-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java non-blocking I/O</title>
		<link>http://tadek.pietraszek.org/blog/2004/10/20/java-non-blocking-io/</link>
		<comments>http://tadek.pietraszek.org/blog/2004/10/20/java-non-blocking-io/#comments</comments>
		<pubDate>Wed, 20 Oct 2004 08:57:02 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2004/10/20/java-non-blocking-io/</guid>
		<description><![CDATA[Java SUCKS! Platform independence doesn&#8217;t come with a high price. The last two days I have been trying to do asynchronous non-blocking I/O and got really frustrated. Moreover, I come to think that what I really wanted is simply not possible.

Correction &#8211; Java sucks LESS   It&#8217;s not so well documented though&#8230;

I have a [...]]]></description>
			<content:encoded><![CDATA[<p>Java SUCKS! Platform independence doesn&#8217;t come with a high price. The last two days I have been trying to do asynchronous non-blocking I/O and got really frustrated. Moreover, I come to think that what I really wanted is simply not possible.</p>

<p>Correction &#8211; Java sucks LESS <img src='http://tadek.pietraszek.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  It&#8217;s not so well documented though&#8230;</p>

<p>I have a fully functional non-blocking IO for Java 1.4. It is multithreaded and it works great.
<span id="more-27"></span>
What I tried first:</p>

<p>SOLUTION1</p>

<p>InputStream in = System.in;</p>

<p>while(wantToContinue) {</p>

<p>while (in.available() == 0) {
  try {Thread.sleep(sometime); }
  catch(InterrputerException ioe) {};
}</p>

<p>int bytesRead = in.read(buffer);</p>

<p>}</p>

<p>PROBLEM1
available() doesn&#8217;t report any data on end of file (which is reported by non-blocking read() returning -1), so there&#8217;s no way to detect this state.</p>

<p>SOLUTION2
Ok, what if we do the blocking I/O in a separate thread and simulate non-blocking I/O to the main thead (a simple producer-consumer programming exercise).</p>

<p>PROBLEM2
Once, a thread is stuck in a blocking read(), there&#8217;s NO WAY to terminate it. Closing the stream, interrupting or even terminating the thread has no effect whatsoever.</p>

<p>(PARTIAL) SOLUTION 2
The same as solution2, but assuming that we want to terminate the thread at the end of application, we can simply cat System.exit() in a finally{} statement.</p>

<p>Ugly like hell, but for our limited purposes, it works.</p>

<p>CONCLUSION
Java is a nice programming language, but it&#8217;s of limited use for writing a simple Unix-like tools processing streams asynchronously (pipes, reading from stdin, etc.). java.nio (NEW I/O) doesn&#8217;t help here at all.</p>

<p>IMPROVED AND WORKING SOLUTION:
Use Channels, but unstead of converting System.in to Channel, we use 
FileChannel fc = new FileInputStream(FileDescriptor.in).getChannel();
ByteBuffer b = ByteBuffer.wrap(tmpBuffer);</p>

<p>Now synchronous calls to FileChannes CAN be interrupted. BTW: it&#8217;s still not selectable though, which means we have to use another (ternimable this time) thread to do non-blocking ops.</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2004/10/20/java-non-blocking-io/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
