<?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>Kiss Note &#187; java</title>
	<atom:link href="http://kissnote.com/tags/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://kissnote.com</link>
	<description>Keep IT Simple and Stupid</description>
	<lastBuildDate>Mon, 17 May 2010 17:19:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Jave Regular Expression study guide</title>
		<link>http://kissnote.com/2010/04/26/jave-regular-expression-study-guide/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://kissnote.com/2010/04/26/jave-regular-expression-study-guide/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 21:50:07 +0000</pubDate>
		<dc:creator>shengjie</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[scjp]]></category>

		<guid isPermaLink="false">http://kissnote.com/?p=226</guid>
		<description><![CDATA[Metacharacters: \d : A digit \w : A word char \s : A white space char [] : match one of the char contained in the square bracket Quantifiers: * Zero or more occurrences ? Zero or one occurrence + 1 or more occurrence The Predefined Dot: . any char NOTE: conversion type is used [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Metacharacters</strong></em>:</p>
<p>\d : A digit</p>
<p>\w : A word char</p>
<p>\s : A white space char</p>
<p>[] : match one of the char contained in the square bracket</p>
<p><em><strong>Quantifiers:</strong></em></p>
<p>* Zero or more occurrences</p>
<p>? Zero or one occurrence</p>
<p>+ 1 or more occurrence</p>
<p><em><strong>The Predefined Dot</strong></em>:</p>
<p>. any char</p>
<p><strong>NOTE:</strong></p>
<p><strong>conversion type </strong>is used for formatting <strong>NOT</strong> for regex.</p>
<p>eg. printf(), format() &#8230;</p>
<p>bcdfs</p>
<p>b-boolean, c-char, d-integer, f-float,s-string</p>
<p><strong>escape sequence</strong>:</p>
<p>\n = line feed</p>
<p>\b = backspace</p>
<p>\t = tab</p>
]]></content:encoded>
			<wfw:commentRss>http://kissnote.com/2010/04/26/jave-regular-expression-study-guide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Assertion Study note</title>
		<link>http://kissnote.com/2010/04/24/java-assertion-study-note/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://kissnote.com/2010/04/24/java-assertion-study-note/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 23:44:56 +0000</pubDate>
		<dc:creator>shengjie</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[scjp]]></category>

		<guid isPermaLink="false">http://kissnote.com/?p=220</guid>
		<description><![CDATA[In SCJP exam, You are expected to know appropriate and inappropriate assertions appropriate: 1. Do check private method 2. check code never should be reached inappropriate: 1. check public method 2. check command-line arguments 3. assertion check will bring side affects eg.assert a=a+1 // a&#8217;s value will be varied depending on whether assertion is enabled [...]]]></description>
			<content:encoded><![CDATA[<p>In SCJP exam, You are expected to know <strong>appropriate </strong>and <strong>inappropriate </strong>assertions</p>
<p><strong>appropriate:</strong></p>
<p>1. Do check private method</p>
<p>2. check code never should be reached</p>
<p><strong>inappropriate:</strong></p>
<p>1. check public method</p>
<p>2. check command-line arguments</p>
<p>3. assertion check will bring side affects</p>
<p><span style="color: #888888;">eg.assert a=a+1 // a&#8217;s value will be varied depending on whether assertion is enabled or not. </span></p>
]]></content:encoded>
			<wfw:commentRss>http://kissnote.com/2010/04/24/java-assertion-study-note/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Interface Study note</title>
		<link>http://kissnote.com/2010/04/24/java-interface-study-note/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://kissnote.com/2010/04/24/java-interface-study-note/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 22:18:49 +0000</pubDate>
		<dc:creator>shengjie</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[scjp]]></category>

		<guid isPermaLink="false">http://kissnote.com/?p=212</guid>
		<description><![CDATA[1. All methods are implicitly public abstract. 2.All variables are implicitly final static constants. 3.Interface CAN NOT have static method. WHY : Java allows mult-interface implementation, what the child should inherit if two interfaces have the same static method? 4. casting a class to interface is always legal in Java during compile. eg. for A [...]]]></description>
			<content:encoded><![CDATA[<p>1. All methods are implicitly<strong> public abstract.</strong></p>
<p>2.All variables are implicitly <strong>final static</strong> constants.</p>
<p>3.Interface <strong>CAN NOT</strong> have static method.</p>
<p><em>WHY</em> :<span style="color: #888888;"> <span style="color: #0000ff;">Java allows mult-interface implementation, what the child should inherit if two interfaces have the same static method?</span></span></p>
<p>4. casting a class to interface is always legal in Java during compile.</p>
<p><em>eg.</em></p>
<p>for A class, you can cast it to an interface, this rule apply to instanceof as well.</p>
<p><span style="color: #0000ff;">eg1.Runnable r = (Runnable)new A(); </span></p>
<p><span style="color: #0000ff;">note: </span></p>
<p><span style="color: #0000ff;">but runtime if A has no relationship with Runnable, will throw Runtime Exception(ClassCastExcetption)</span></p>
<p><span style="color: #0000ff;">if A is a final class and has no relationship with Runnable, it will fail compile.<br />
</span></p>
<p><span style="color: #0000ff;">eg2.A a = (A)r; // this is legal as well.</span></p>
<p><span style="color: #0000ff;">eg3.$Left instaceof $Right, Left can be any objects,but no interface(fail the build), right can be interfaces</span></p>
<p><span style="color: #0000ff;">note:</span></p>
<p><span style="color: #0000ff;">again, compile will fail when $left is an ojbect of a final class, $right is an interface having no relationship with $left.<br />
</span></p>
<p><span style="color: #0000ff;"><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://kissnote.com/2010/04/24/java-interface-study-note/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Thread Study note</title>
		<link>http://kissnote.com/2010/04/24/java-thread-study-note/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://kissnote.com/2010/04/24/java-thread-study-note/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 22:01:17 +0000</pubDate>
		<dc:creator>shengjie</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://kissnote.com/?p=207</guid>
		<description><![CDATA[1.A new Thread gets started means a new stack gets kicked off apart from the main stack 2. InterruptedException(checked exception) will be thrown when a thread is waiting, sleeping and pausing for long time. (sleep(), wait() and join()) note: yield() is not throwing this exception. 3.A thread can&#8217;t be started again once it&#8217;s started. Trying [...]]]></description>
			<content:encoded><![CDATA[<p>1.A new Thread gets started means a new stack gets kicked off apart from the main stack</p>
<p>2. InterruptedException(checked exception) will be thrown when a thread is waiting, sleeping and pausing for long time. (sleep(), wait() and join())</p>
<p>note:</p>
<p><span style="color: #0000ff;">yield() is not throwing this exception.</span></p>
<p>3.A thread can&#8217;t be started again once it&#8217;s started. Trying to start a thread more than once will throw IllegalThreadStateException(Runtime Exception)</p>
<p>4.wait(),notify(),notifyAll() are inherited from Object class. They have to be surrounded by the synchorized context. Otherwise it throws IllegalThreadMonitorException(Runtime Excpetion).</p>
<p><span style="color: #666699;">eg. sychronized(a) {</span></p>
<p><span style="color: #666699;">&#8230;.</span></p>
<p><span style="color: #666699;">a.wait()<br />
</span></p>
<p><span style="color: #666699;">&#8230;.<br />
</span></p>
<p><span style="color: #666699;">}</span></p>
<p>5. only thread can be started, not runnable.</p>
<p>6.Thread constructor can take  Runnable or <em><strong>String</strong></em>(name of the thread).</p>
<p><em><strong>Test Tips:</strong></em></p>
<p><em><strong>before you go any further, check the following!!!</strong></em></p>
<p><em><strong>Compile </strong></em></p>
<p>1. start() &#8211; check if it is against Runnable &#8211; compile error</p>
<p>2. wait(),join(),sleep() &#8211; InterruptedException is handled or not &#8211; compile error</p>
<p><em> </em></p>
<p>3.Thread.sleep() is ok, sleep() it self can be only called in the subclass of Thread. so class implements Runnable has to call Thread.sleep() not sleep() directly.</p>
<p><em><strong>Runtime<br />
</strong></em></p>
<p>1. wait(),notify(),notifyAll() needs to be in synchronized context &#8211;  runtime exception <em>IllegalMonitorStateException</em></p>
<p><em>2. </em>the same thread gets called start() twice &#8211; runtime exception &#8211; <em>IllegalThreadStateException</em></p>
]]></content:encoded>
			<wfw:commentRss>http://kissnote.com/2010/04/24/java-thread-study-note/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Inner Class Study note</title>
		<link>http://kissnote.com/2010/04/24/java-inner-class/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://kissnote.com/2010/04/24/java-inner-class/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 13:13:09 +0000</pubDate>
		<dc:creator>shengjie</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[scjp]]></category>

		<guid isPermaLink="false">http://kissnote.com/?p=200</guid>
		<description><![CDATA[Just quick sum-up what we should be careful during the SCJP exam when you see inner class questions. CAN 1. inner class can be defined in method, in class, as arugments as well. 2.Method local inner class can only have modifier abstract and final. CAN NOT 1. inner class CAN NOT have static methods. Neither [...]]]></description>
			<content:encoded><![CDATA[<p>Just quick sum-up what we should be careful during the SCJP exam when you see inner class questions.</p>
<h2>CAN</h2>
<p>1. inner class can be defined in method, in class, as arugments as well.</p>
<p>2.Method local inner class can only have modifier abstract and final.</p>
<h2>CAN NOT</h2>
<p>1. inner class CAN NOT have static methods. Neither static variable unless they are public static final constants</p>
<p>WHY</p>
<p><span style="color: #666699;">Because an inner class is implicitly associated with an instance of it&#8217;s  outer class, it cannot define any static methods itself.  Since a  static nested class cannot refer directly to instance variables or  methods defined in its enclosing class, it can use them only through an  object reference, it&#8217;s safe to declare static methods in a static nested  class.</span></p>
<p>2. method local inner class CAN NOT access method local variables unless they are Marked as final.</p>
<p>WHY</p>
<p><span style="color: #666699;">Simply because, the method local inner class is like an local variable. When the method completes, the object might still be passed by reference on the heap refered and used by some other code. The method local variable just can&#8217;t live as long as the method-local inner class object .</span></p>
<p>3.static inner class (this is not actually considered as regular inner class) CAN NOT have access to outer class&#8217;s instance members (non-static methods + instance variables)</p>
<p>4.static inner class can not extend a non-static inner class(Just burn this in mind)</p>
<p>WHY</p>
<p><span style="color: #666699;">Just like static method can&#8217;t directly access instace method, it has to be via object of the class. Static class can&#8217;t have the access to instance members.</span></p>
<p>4.inner class can be private+abstract, but CAN NOT be final+abstract.</p>
<p>WHY</p>
<p><span style="color: #666699;">it&#8217;s easy to tell , rite? hehe, just think about it.</span></p>
<h2><span style="color: #666699;"><br />
</span></h2>
]]></content:encoded>
			<wfw:commentRss>http://kissnote.com/2010/04/24/java-inner-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SCJP &#8211; scenarios you won&#8217;t get java compiled</title>
		<link>http://kissnote.com/2010/04/19/scjp-scenarios-you-wont-get-java-compiled/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://kissnote.com/2010/04/19/scjp-scenarios-you-wont-get-java-compiled/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 16:02:50 +0000</pubDate>
		<dc:creator>shengjie</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[scjp]]></category>

		<guid isPermaLink="false">http://kissnote.com/?p=188</guid>
		<description><![CDATA[Arrays.length VS String.length() Most of the test tricks you by eg. args.length(), it will fail the compile. So don&#8217;t bother to figure out what results will be after execute. It won&#8217;t compile. Ambiguous This is a trick one, we will hit more ambiguous compile error in this article. One class implements/extends more than one parents. [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li>
<h4>Arrays.length VS String.length()</h4>
</li>
</ul>
<p style="text-align: justify; padding-left: 30px;">Most of the test tricks you by eg. args.length(), it will fail the compile. So don&#8217;t bother to figure out what results will be after execute. It won&#8217;t compile.</p>
<ul>
<li>
<h4>Ambiguous</h4>
</li>
</ul>
<p style="padding-left: 30px;">This is a trick one, we will hit more ambiguous compile error in this article. One class implements/extends more than one parents. The parents have a same variable, the child has no idea which one gets inherited from what parent. Compile is confused and has no idea what to do. It gives you compile error(ambiguous).</p>
<p style="padding-left: 30px;">eg. class A{int a;}</p>
<p style="padding-left: 30px;">Inteface B{int a;}</p>
<p style="padding-left: 30px;">FAIL: class C extends A implements B{ compiler has no idea which a to inherit}</p>
<p style="padding-left: 30px;">eg.public void test(int&#8230; i) VS public void test(Integer&#8230; i)</p>
<p style="padding-left: 30px;">both in the same class, when we make a call like test(4), compile fails as ambiguous call is made</p>
<ul>
<li>
<h4>instanceof</h4>
</li>
</ul>
<p style="padding-left: 30px;">instanceof takes object on the left and interface/class on the right.So primitive will fail instanceof</p>
<p style="padding-left: 30px;">eg. FAIL: int i=1;</p>
<p style="padding-left: 30px;">i instanceof Integer is not legal, compile error.</p>
<ul>
<li>
<h4>binarySearch takes(List,key)</h4>
</li>
</ul>
<p style="padding-left: 30px;">eg. Collection c = new ArrayList();</p>
<p style="padding-left: 30px;">c.add(&#8220;shengjie&#8221;);</p>
<p style="padding-left: 30px;">&#8230;..</p>
<p style="padding-left: 30px;">Collections.binarySearch(c, &#8220;shengjie&#8221;); // compile error, c needs to have a explicit downcasting (List)c</p>
<ul>
<li>
<h4>Assignment</h4>
</li>
</ul>
<p style="padding-left: 30px;">List &lt;&#8211; ArrayList  OK &#8211; Polymorphism</p>
<p style="padding-left: 30px;">Integer &lt;&#8211; int OK &#8211; Auto-boxing</p>
<p style="padding-left: 30px;">Integer[] &lt;&#8211; int[] FAIL -  type is fixed when array initialised</p>
<ul>
<li>
<h4>passing param to method without explicit downcasting if downcasting is needed</h4>
</li>
<li>
<h4>Calendar.getInstance(Locale), SCJP test always tries to pass a date or smth else to Calendar.getInstance(Date) Compile Fail</h4>
</li>
<li>
<h4>When Overriding &#8211; It&#8217;s Public String toString(){} NOT <span style="text-decoration: line-through;">Public void toString(){}</span></h4>
</li>
<li>
<h4>Catch Exception Sequence</h4>
</li>
</ul>
<p style="padding-left: 30px;">sub-exception has to be caught before the super-exception, so the below will have compile error</p>
<p style="padding-left: 30px;">eg.try{</p>
<p style="padding-left: 30px;">}catch(RuntimeException){</p>
<p style="padding-left: 30px;">}catch(IllegalStateException){ // this can be thrown by calling matcher.group() when matcher.find() is not true</p>
<h4 style="padding-left: 30px;">}</h4>
<ul>
<li>
<h4>Private Inner Class can&#8217;t be called/accessed by other classes</h4>
</li>
</ul>
<p style="padding-left: 30px;">unlike the private fields can be accessed by getter/setter by other classes, inner class can&#8217;t be accessed by other classes. If the code snippet is trying to access the private inner class object, it fails the compile</p>
<ul>
<li>
<h4>Casting a class to anther class type which is not in the same hierarchy tree</h4>
</li>
</ul>
<ul>
<li>
<h4>static method tries to access Instance Member/Static class tries to access Instance Member</h4>
</li>
</ul>
<p style="padding-left: 30px;">Answer to WHY is pretty simply, because static goes with class other than instance. So&#8230;bear it in mind. Static class can be thought as static member of the enclosing class.</p>
<ul>
<li>
<h4>Final field is declared and no initialization</h4>
</li>
</ul>
<p style="padding-left: 30px;">public final int i; Compile Error</p>
<p style="padding-left: 30px;">public final int i=0; OK</p>
<ul>
<li>
<h4><span style="text-decoration: line-through;">Arrays.reverse()</span> doesn&#8217;t exist</h4>
</li>
</ul>
<p style="padding-left: 30px;">Arrays : sort() binarySearch()</p>
<p style="padding-left: 30px;">Collections: sort() binarySearch() reverse() reverseOrder()</p>
<p style="padding-left: 30px;">Don&#8217;t let the test play you like a fool!!!</p>
<ul>
<li>
<h4>wait(),notify(),notifyAll() throws InterruptedException which is not handled</h4>
</li>
</ul>
<p style="padding-left: 30px;">either catch it or throw it, doing nothing will fail the compile</p>
<ul>
<li>
<h4 style="padding-left: 30px;">Having unreachable code</h4>
</li>
</ul>
<p style="padding-left: 30px;">eg.</p>
<p style="padding-left: 30px;">&#8230;</p>
<p style="padding-left: 30px;">public void test() throws Exception{</p>
<p style="padding-left: 30px;">throw new RuntimeException();</p>
<p style="padding-left: 30px;">throw new anotherException(); // this is ok, i am not sure why, just burn into your mind</p>
<p style="padding-left: 30px;">int i = 0; // this never gets reached, so it fails the compile, tricky, yeah <img src='http://kissnote.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  LOL</p>
<p style="padding-left: 30px;">}</p>
<p style="padding-left: 30px;">
<p style="padding-left: 30px;">
]]></content:encoded>
			<wfw:commentRss>http://kissnote.com/2010/04/19/scjp-scenarios-you-wont-get-java-compiled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jar command</title>
		<link>http://kissnote.com/2009/06/29/jar-command/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://kissnote.com/2009/06/29/jar-command/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 15:05:21 +0000</pubDate>
		<dc:creator>shengjie</dc:creator>
				<category><![CDATA[Tips Everyday]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://kissnote.com/?p=151</guid>
		<description><![CDATA[//create Jar file jar -cmf c:create f:file m:manifast eg. jar -cmf -C ./workspace/jar-test/classes myJarTest.jar *.class //Extract Jar file jar -xf x:extract f:file eg. jar -xf myJarTest.jar // update jar file jar -uf u: update eg. jar uf foo.jar foo.class //list jar file content as a table jar -tf t:table eg. jar -tf myJarTest.jar]]></description>
			<content:encoded><![CDATA[<p>//create Jar file</p>
<p><strong>jar -cmf </strong></p>
<p>c:create</p>
<p>f:file</p>
<p>m:manifast</p>
<p>eg. jar -cmf -C ./workspace/jar-test/classes myJarTest.jar *.class</p>
<p>//Extract Jar file</p>
<p><strong>jar -xf</strong></p>
<p>x:extract</p>
<p>f:file</p>
<p>eg. jar -xf myJarTest.jar</p>
<p>// update jar file</p>
<p><strong>jar -uf</strong></p>
<p>u: update<strong><br />
</strong></p>
<p>eg. jar uf foo.jar foo.class</p>
<p>//list jar file content as a table</p>
<p><strong>jar -tf</strong></p>
<p>t:table</p>
<p>eg. jar -tf myJarTest.jar</p>
]]></content:encoded>
			<wfw:commentRss>http://kissnote.com/2009/06/29/jar-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
