<?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>{Complexity} &#187; Programming</title>
	<atom:link href="http://technote.wsjoung.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://technote.wsjoung.com</link>
	<description>simple note</description>
	<lastBuildDate>Fri, 06 Aug 2010 19:03:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Replace blank space in file name</title>
		<link>http://technote.wsjoung.com/2010/07/08/replace-blank-space-in-file-name/</link>
		<comments>http://technote.wsjoung.com/2010/07/08/replace-blank-space-in-file-name/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 18:08:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Script]]></category>

		<guid isPermaLink="false">http://technote.wsjoung.com/?p=144</guid>
		<description><![CDATA[for f in *; do mv &#8220;$f&#8221; `echo $f &#124; tr &#8216; &#8216; &#8216;_&#8217;`; done]]></description>
			<content:encoded><![CDATA[<blockquote><p>
for f in *; do mv &#8220;$f&#8221; `echo $f | tr &#8216; &#8216; &#8216;_&#8217;`; done
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2010/07/08/replace-blank-space-in-file-name/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring MVC + Tiles</title>
		<link>http://technote.wsjoung.com/2009/12/13/spring-mvc-tiles/</link>
		<comments>http://technote.wsjoung.com/2009/12/13/spring-mvc-tiles/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 02:14:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tiles]]></category>

		<guid isPermaLink="false">http://technote.wsjoung.com/?p=126</guid>
		<description><![CDATA[1. create web.xml &#60;?xml version="1.0" encoding="UTF-8"?&#62; &#60;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&#62; &#60;servlet&#62; &#60;servlet-name&#62;action&#60;/servlet-name&#62; &#60;servlet-class&#62;org.springframework.web.servlet.DispatcherServlet&#60;/servlet-class&#62; &#60;load-on-startup&#62;1&#60;/load-on-startup&#62; &#60;/servlet&#62; &#60;servlet-mapping&#62; &#60;servlet-name&#62;action&#60;/servlet-name&#62; &#60;url-pattern&#62;*.do&#60;/url-pattern&#62; &#60;/servlet-mapping&#62; &#60;/web-app&#62; 2. create action-servlet.xml &#60;?xml version="1.0" encoding="UTF-8"?&#62; &#60;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&#62; &#60;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&#62; &#60;property name="basename" value="message" /&#62; &#60;/bean&#62; &#60;bean id="testController" class="com.bluewiseinc.erp.common.web.TestController"&#62; &#60;property name="methodNameResolver" ref="methodNameResolver" /&#62; &#60;/bean&#62; &#60;bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"&#62; &#60;property [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1. create web.xml</strong><br />
<code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;<br />
  &lt;servlet&gt;<br />
  	&lt;servlet-name&gt;action&lt;/servlet-name&gt;<br />
	  &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;<br />
	  &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;<br />
  &lt;/servlet&gt;<br />
  &lt;servlet-mapping&gt;<br />
    &lt;servlet-name&gt;action&lt;/servlet-name&gt;<br />
    &lt;url-pattern&gt;*.do&lt;/url-pattern&gt;<br />
  &lt;/servlet-mapping&gt;<br />
&lt;/web-app&gt;</code></p>
<p><strong>2. create action-servlet.xml</strong><br />
<code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;</p>
<p>  &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&gt;<br />
    &lt;property name="basename" value="message" /&gt;<br />
  &lt;/bean&gt;  </p>
<p>  &lt;bean id="testController" class="com.bluewiseinc.erp.common.web.TestController"&gt;<br />
	&lt;property name="methodNameResolver" ref="methodNameResolver" /&gt;<br />
  &lt;/bean&gt;  </p>
<p>  &lt;bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"&gt;<br />
    &lt;property name="paramName"&gt;<br />
      &lt;value&gt;med&lt;/value&gt;<br />
    &lt;/property&gt;<br />
    &lt;property name="defaultMethodName"&gt;<br />
      &lt;value&gt;userMain&lt;/value&gt;<br />
    &lt;/property&gt;<br />
  &lt;/bean&gt;</p>
<p>  &lt;!--<br />
  &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;<br />
	&lt;property name="viewClass"&gt;<br />
	  &lt;value&gt;org.springframework.web.servlet.view.JstlView&lt;/value&gt;<br />
	&lt;/property&gt;<br />
	&lt;property name="cache" value="false" /&gt;<br />
	&lt;property name="prefix" value="/WEB-INF/view/" /&gt;<br />
	&lt;property name="suffix" value=".jsp" /&gt;<br />
  &lt;/bean&gt;<br />
  --&gt;<br />
  &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;<br />
    &lt;property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/&gt;<br />
  &lt;/bean&gt;</p>
<p>  &lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;<br />
	&lt;property name="mappings"&gt;<br />
	  &lt;bean class="org.springframework.beans.factory.config.PropertiesFactoryBean"&gt;<br />
	    &lt;property name="location"&gt;<br />
	      &lt;value&gt;/WEB-INF/UrlMap.properties&lt;/value&gt;<br />
	    &lt;/property&gt;<br />
	  &lt;/bean&gt;<br />
    &lt;/property&gt;<br />
  &lt;/bean&gt;</p>
<p>  &lt;bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"&gt;<br />
    &lt;property name="definitions"&gt;<br />
      &lt;list&gt;<br />
        &lt;value&gt;/WEB-INF/tiles-def.xml&lt;/value&gt;<br />
      &lt;/list&gt;<br />
    &lt;/property&gt;<br />
  &lt;/bean&gt;</p>
<p>  &lt;bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;<br />
    &lt;property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/&gt;<br />
  &lt;/bean&gt;<br />
&lt;/beans&gt;</code></p>
<p><strong>3. create TestController</strong><br />
<code>package com.bluewiseinc.erp.common.web;<br />
import javax.servlet.http.HttpServletRequest;<br />
import javax.servlet.http.HttpServletResponse;<br />
import org.springframework.web.servlet.ModelAndView;<br />
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;</p>
<p>public class TestController extends MultiActionController {<br />
	public ModelAndView testMain(HttpServletRequest request, HttpServletResponse response) throws Exception {<br />
		return new ModelAndView("test/test_main", "testMain", null);<br />
	}<br />
}</code></p>
<p><strong>4. UrlMap.properties</strong><br />
<code>## test module mapping<br />
/test/index.do=testController</code></p>
<p><strong>5. tiles-def.xml</strong><br />
<code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;<br />
&lt;!DOCTYPE tiles-definitions PUBLIC<br />
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"<br />
       "http://tiles.apache.org/dtds/tiles-config_2_0.dtd"&gt;</p>
<p>&lt;tiles-definitions&gt;<br />
  &lt;definition name="defaultTemplate" template="/WEB-INF/view/tiles/default.jsp"&gt;<br />
    &lt;put-attribute name="header" value="/WEB-INF/view/tiles/def_header.jsp" /&gt;<br />
    &lt;put-attribute name="menu" value="/WEB-INF/view/tiles/def_menu.jsp" /&gt;<br />
    &lt;put-attribute name="footer" value="/WEB-INF/view/tiles/def_footer.jsp" /&gt;<br />
  &lt;/definition&gt;<br />
  &lt;definition name="test_main" extends="defaultTemplate"&gt;<br />
    &lt;put-attribute name="content"   value="/WEB-INF/view/test/test_main.jsp"/&gt;<br />
  &lt;/definition&gt;<br />
&lt;/tiles-definitions&gt;</code></p>
<p><strong>6. message.properties</strong><br />
<code># Page titles<br />
index.title=Test Spring MVC + Tiles</code></p>
<p><strong>7. default.jsp</strong><br />
<code>&lt;%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %&gt;<br />
&lt;%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %&gt;<br />
&lt;%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %&gt;<br />
&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"<br />
    pageEncoding="ISO-8859-1"%&gt;<br />
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;<br />
&lt;title&gt;&lt;fmt:message key="index.title"/&gt;&lt;/title&gt;<br />
&lt;link rel=stylesheet href="${pageContext.request.contextPath}/css/global.css" type="text/css"&gt;<br />
&lt;script type="text/javascript" src="${pageContext.request.contextPath}/scripts/global.js"&gt;&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div id="header"&gt;<br />
    &lt;div id="headerTitle"&gt;&lt;tiles:insertAttribute name="header" /&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;div id="menu"&gt;<br />
    &lt;tiles:insertAttribute name="menu" /&gt;<br />
&lt;/div&gt;<br />
&lt;div id="content"&gt;<br />
    &lt;tiles:insertAttribute name="content" /&gt;<br />
&lt;/div&gt;<br />
&lt;div id="footer"&gt;<br />
    &lt;tiles:insertAttribute name="footer" /&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2009/12/13/spring-mvc-tiles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Pear Image_Graph</title>
		<link>http://technote.wsjoung.com/2009/09/01/php-pear-image_graph/</link>
		<comments>http://technote.wsjoung.com/2009/09/01/php-pear-image_graph/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 20:36:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Graph]]></category>
		<category><![CDATA[Pear]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://technote.wsjoung.com/?p=110</guid>
		<description><![CDATA[#apt-get install php-pear #pear install Numbers_Words-0.16.1 #pear install Numbers_Roman-1.0.2 #pear install Image_Canvas-0.3.1 #pear install Image_Graph-0.7.2 (Download TrueType core fonts from http://corefonts.sourceforge.net/) cp *.ttf /usr/share/php/Image/Canvas/Fonts &#60;?php require_once '../../includes/include.php'; require_once 'Image/Graph.php'; require_once 'Image/Canvas.php'; date_default_timezone_set('America/New_York'); $customer_id = $_REQUEST[customer_id]; if (!$customer_id) exit(); $customer_data = get_order_customer_report_xy($customer_id); if (!$customer_data) exit(); $Canvas =&#38; Image_Canvas::factory('png', array('width' =&#62; 575, 'height' =&#62; 280)); // create [...]]]></description>
			<content:encoded><![CDATA[<p>#apt-get install php-pear</p>
<p>#pear install Numbers_Words-0.16.1<br />
#pear install Numbers_Roman-1.0.2<br />
#pear install Image_Canvas-0.3.1<br />
#pear install Image_Graph-0.7.2</p>
<p>(Download TrueType core fonts from http://corefonts.sourceforge.net/)<br />
cp *.ttf /usr/share/php/Image/Canvas/Fonts</p>
<p><img class="alignnone size-full wp-image-111" title="Image_Graph" src="http://technote.wsjoung.com/wp-content/uploads/2009/09/graph.jpg" alt="Image_Graph" width="575" height="280" /></p>
<p><code>&lt;?php<br />
require_once '../../includes/include.php';<br />
require_once 'Image/Graph.php';<br />
require_once 'Image/Canvas.php';<br />
date_default_timezone_set('America/New_York');</p>
<p>$customer_id = $_REQUEST[customer_id];<br />
if (!$customer_id) exit();<br />
$customer_data = get_order_customer_report_xy($customer_id);<br />
if (!$customer_data) exit();</p>
<p>$Canvas =&amp; Image_Canvas::factory('png', array('width' =&gt; 575, 'height' =&gt; 280));</p>
<p>// create the graph<br />
$Graph =&amp; Image_Graph::factory('graph', $Canvas);<br />
// add a TrueType font<br />
$Font =&amp; $Graph-&gt;addNew('font', 'DejaVuSans');<br />
$Font-&gt;setSize(8); </p>
<p>$Graph-&gt;setFont($Font); </p>
<p>// create the plotarea layout<br />
$Graph-&gt;add(<br />
    Image_Graph::vertical(<br />
        Image_Graph::factory('title', array('', 11)),<br />
        Image_Graph::vertical(<br />
            $Plotarea = Image_Graph::factory('plotarea'),<br />
            $Legend = Image_Graph::factory('legend'),<br />
            90<br />
        ),<br />
        5<br />
    )<br />
);          </p>
<p>$Legend-&gt;setPlotarea($Plotarea);    </p>
<p>// create a grid and assign it to the secondary Y axis<br />
$GridY2 =&amp; $Plotarea-&gt;addNew('bar_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY);<br />
$GridY2-&gt;setFillStyle(<br />
    Image_Graph::factory(<br />
        'gradient',<br />
        array(IMAGE_GRAPH_GRAD_VERTICAL, 'white', 'lightgrey')<br />
    )<br />
);     </p>
<p>list($year, $month) = split('[-.-]', $customer_data[0][1]);<br />
$start=mktime(0,0,0,$month,1,$year);<br />
$today=mktime(0,0,0,date('m'),1,date('Y'));<br />
$interv=12-$month+(12*(date('Y')-$year-1))+date('m')+1;</p>
<p>// create a line plot<br />
$Dataset1 =&amp; Image_Graph::factory('dataset');<br />
$Dataset2 =&amp; Image_Graph::factory('dataset'); </p>
<p>$max = 0;<br />
for ($i=0; $i&lt;count($customer_data); $i++) {<br />
        if ($max&lt;$customer_data[$i][0]) $max=$customer_data[$i][0];<br />
}<br />
for ($i=0; $i&lt;$interv; $i++) {<br />
        $Dataset2-&gt;addPoint(date('m/y', mktime(0,0,0,$month,1,$year)), 0);<br />
        $month++;<br />
}<br />
for ($i=0; $i&lt;count($customer_data); $i++) {<br />
        list($year, $month) = split('[-.-]', $customer_data[$i][1]);<br />
        $Dataset1-&gt;addPoint(date('m/y', mktime(0,0,0,$month,1,$year)), $customer_data[$i][0]);<br />
}</p>
<p>$Plot1 =&amp; $Plotarea-&gt;addNew('bar', array(&amp;$Dataset1));<br />
$Plot1-&gt;setLineColor('red'); </p>
<p>$Plot2 =&amp; $Plotarea-&gt;addNew(<br />
    'Image_Graph_Plot_Area',<br />
    $Dataset2,<br />
    IMAGE_GRAPH_AXIS_Y_SECONDARY<br />
); </p>
<p>$Plot2-&gt;setLineColor('gray');<br />
$Plot2-&gt;setFillColor('white@0.2'); </p>
<p>$AxisX =&amp; $Plotarea-&gt;getAxis(IMAGE_GRAPH_AXIS_X);<br />
$labInterv = floor($interv / 13);<br />
$AxisX-&gt;setLabelInterval($labInterv);<br />
$AxisY =&amp; $Plotarea-&gt;getAxis(IMAGE_GRAPH_AXIS_Y);<br />
$AxisY-&gt;setTitle('Orders', 'vertical');<br />
$AxisYsecondary =&amp; $Plotarea-&gt;getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY); </p>
<p>// output the Graph<br />
$Graph-&gt;done();<br />
db_close()<br />
?&gt; </code></p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2009/09/01/php-pear-image_graph/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SwingWorker not on Java 6.0</title>
		<link>http://technote.wsjoung.com/2008/04/24/swingworker-not-on-java-60/</link>
		<comments>http://technote.wsjoung.com/2008/04/24/swingworker-not-on-java-60/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 14:15:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SwingWorker]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/?p=84</guid>
		<description><![CDATA[SwingWorker is useful when a time-consuming task has to be performed following a user-interaction event (for example, parsing a huge XML File, on pressing a Button). The most straightforward way to do it is : [sourcecode language='java'] private Document doc; &#8230; JButton button = new JButton(&#8220;Open XML&#8221;); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { [...]]]></description>
			<content:encoded><![CDATA[<p>SwingWorker is useful when a time-consuming task has to be performed following a user-interaction event (for example, parsing a huge XML File, on pressing a Button). The most straightforward way to do it is :</p>
<p>[sourcecode language='java']<br />
 private Document doc;<br />
 &#8230;<br />
 JButton button = new JButton(&#8220;Open XML&#8221;);<br />
 button.addActionListener(new ActionListener() {<br />
    public void actionPerformed(ActionEvent e) {<br />
       doc = loadXML();<br />
    }<br />
 });<br />
[/sourcecode]</p>
<p>This will work, but unfortunately, the loadXML() method will be called in the same thread as the main Swing thread, so if the method needs time to perform, the GUI will freeze during this time.</p>
<p>[sourcecode language='java']<br />
package com.wsjoung.demo;<br />
import javax.swing.SwingUtilities;</p>
<p>public abstract class SwingWorker {<br />
    // see getValue(), setValue()<br />
    private Object value;<br />
    private Thread thread;</p>
<p>    private static class ThreadVar {<br />
        private Thread thread;<br />
        ThreadVar(Thread t) { thread = t; }<br />
        synchronized Thread get() { return thread; }<br />
        synchronized void clear() { thread = null; }<br />
    }</p>
<p>    private ThreadVar threadVar;</p>
<p>    protected synchronized Object getValue() {<br />
        return value;<br />
    }</p>
<p>    private synchronized void setValue(Object x) {<br />
        value = x;<br />
    }</p>
<p>    public abstract Object construct();</p>
<p>    public void finished() {<br />
    }</p>
<p>    public void interrupt() {<br />
        Thread t = threadVar.get();<br />
        if (t != null) {<br />
            t.interrupt();<br />
        }<br />
        threadVar.clear();<br />
    }</p>
<p>    public Object get() {<br />
        while (true) {<br />
            Thread t = threadVar.get();<br />
            if (t == null) {<br />
                return getValue();<br />
            }<br />
            try {<br />
                t.join();<br />
            }<br />
            catch (InterruptedException e) {<br />
                // propagate<br />
                Thread.currentThread().interrupt();<br />
                return null;<br />
            }<br />
        }<br />
    }</p>
<p>    public SwingWorker() {<br />
        final Runnable doFinished = new Runnable() {<br />
           public void run() { finished(); }<br />
        };</p>
<p>        Runnable doConstruct = new Runnable() {<br />
            public void run() {<br />
                try {<br />
                    setValue(construct());<br />
                }<br />
                finally {<br />
                    threadVar.clear();<br />
                }</p>
<p>              SwingUtilities.invokeLater(doFinished);<br />
            }<br />
        };</p>
<p>        Thread t = new Thread(doConstruct);<br />
        threadVar = new ThreadVar(t);<br />
        t.start();<br />
    }<br />
}<br />
[/sourcecode]</p>
<p><a href="http://java.sun.com/products/jfc/tsc/articles/threads/src/SwingWorker.java">SwingWorker.java</a></p>
<p>[sourcecode language='java']<br />
public class Task{<br />
  public void go() {<br />
      current = 0;<br />
      final SwingWorker worker = new SwingWorker() {<br />
          public Object construct() {<br />
              return new ActualTask();<br />
          }<br />
      };<br />
  }</p>
<p>  class ActualTask {<br />
      ActualTask() {<br />
          try {<br />
              Thread.sleep(1000);<br />
          } catch (InterruptedException e) {}<br />
      }<br />
  }<br />
}<br />
[/sourcecode]</p>
<p>Task.java</p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2008/04/24/swingworker-not-on-java-60/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>what&#039;s static?</title>
		<link>http://technote.wsjoung.com/2008/04/14/whats-static/</link>
		<comments>http://technote.wsjoung.com/2008/04/14/whats-static/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 19:31:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Static]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/?p=79</guid>
		<description><![CDATA[First of all, the meaning of static in java is embedded or belong to a specific class not to its instance, and therefore there is no such static class. There is no such static class Embedded or belong to a specific class Global variable No need to load and create its instance Most of methods [...]]]></description>
			<content:encoded><![CDATA[<p>First of all, the meaning of static in java is embedded or belong to a specific class not to its instance, and therefore there is no such static class.</p>
<ul>
<li>There is no such static class</li>
<li>Embedded or belong to a specific class</li>
<li>Global variable</li>
<li>No need to load and create its instance</li>
</ul>
<p>Most of methods and variables in Math class are static, because those are not need to be instanced in most of cases. we just use return value of PI or max(int a, int b).</p>
<p>class  Bicycle {</p>
<p>private static int numberOfBicycles = 0;<br />
private int id;</p>
<p>public Bicycle() {<br />
id = ++numberOfBicycles;<br />
}</p>
<p>public static int getNumberOfBicycles() {<br />
return numberOfBicycles;<br />
}<br />
public int getID() {<br />
return id;<br />
}</p>
<p>public static void main(String[] args) {<br />
Bicycle b1 = new Bicycle();<br />
Bicycle b2 = new Bicycle();</p>
<p>System.out.println(&#8220;static result    : &#8220;+getNumberOfBicycles());<br />
System.out.println(&#8220;static result : &#8220;+numberOfBicycles);<br />
System.out.println(&#8220;instance result  : &#8220;+b1.getID());<br />
System.out.println(&#8220;instance result  : &#8220;+b2.getID());<br />
}<br />
}</p>
<p>Another characteristic of static is that even if we create instance of a class, jvm does not create instance variables for static resources. in above source code, there is no difference calling b1.getNumberOfBicycles(), b2.getNumberOfBicycles() and just getNumberOfBicycles() or directly numberOfBicycles<br />
that mean we should call static variable with its class name because it&#8217;s belong to it. just like Bicycle.numberOfBicycles or in this example, getNumberOfBicycles() because we have a getter.<br />
otherwise get confused.</p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2008/04/14/whats-static/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>javamail smtp with Gmail</title>
		<link>http://technote.wsjoung.com/2007/08/03/javamail-smtp-with-gmail/</link>
		<comments>http://technote.wsjoung.com/2007/08/03/javamail-smtp-with-gmail/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 18:29:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[Javamail]]></category>
		<category><![CDATA[Servlet]]></category>
		<category><![CDATA[SMTP]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2007/08/03/javamail-smtp-with-gmail/</guid>
		<description><![CDATA[package com.mycompany.emailsender; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.security.Security; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; /** * Servlet implementation class for Servlet: GmailSender * */ public class GmailSender extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { /* (non-Java-doc) * @see javax.servlet.http.HttpServlet#HttpServlet() */ public GmailSender() { super(); } [...]]]></description>
			<content:encoded><![CDATA[<p>package com.mycompany.emailsender;</p>
<p>import java.io.IOException;<br />
import javax.servlet.ServletException;<br />
import javax.servlet.http.HttpServletRequest;<br />
import javax.servlet.http.HttpServletResponse;</p>
<p>import java.security.Security;<br />
import java.util.Properties;</p>
<p>import javax.mail.Message;<br />
import javax.mail.MessagingException;<br />
import javax.mail.Session;<br />
import javax.mail.Transport;<br />
import javax.mail.internet.InternetAddress;<br />
import javax.mail.internet.MimeMessage;</p>
<p>/**<br />
* Servlet implementation class for Servlet: GmailSender<br />
*<br />
*/<br />
public class GmailSender extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {<br />
/* (non-Java-doc)<br />
* @see javax.servlet.http.HttpServlet#HttpServlet()<br />
*/<br />
public GmailSender() {<br />
super();<br />
}</p>
<p>/* (non-Java-doc)<br />
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)<br />
*/<br />
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {<br />
// TODO Auto-generated method stub<br />
}</p>
<p>/* (non-Java-doc)<br />
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)<br />
*/<br />
final String SMTP_HOST_NAME = &#8220;smtp.gmail.com&#8221;;<br />
final int SMTP_HOST_PORT = 465;<br />
final String SMTP_AUTH_USER = &#8220;XXXXXX@gmail.com&#8221;;<br />
final String SMTP_AUTH_PWD  = &#8220;XXXXXX&#8221;;<br />
final String SSL_FACTORY = &#8220;javax.net.ssl.SSLSocketFactory&#8221;;</p>
<p>String emailFromAddress = null;<br />
String[] sendTo = null;<br />
String subject = null;<br />
String content = null;</p>
<p>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {</p>
<p>Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());</p>
<p>String address = request.getParameter(&#8220;address&#8221;);<br />
sendTo = address.split(&#8220;;&#8221;);</p>
<p>emailFromAddress = request.getParameter(&#8220;sender&#8221;);<br />
this.subject = request.getParameter(&#8220;title&#8221;);<br />
this.content = request.getParameter(&#8220;content&#8221;);</p>
<p>try {<br />
for (int i=0; i&lt;sendTo.length; i++) {<br />
sendSSLMessage(sendTo[i]);<br />
}<br />
System.out.println(&#8220;Sucessfully Sent mail to All Users&#8221;);</p>
<p>} catch (Exception e) {System.out.println(e);}<br />
}</p>
<p>public void sendSSLMessage(String dest) throws MessagingException {</p>
<p>Properties props = new Properties();</p>
<p>props.put(&#8220;mail.transport.protocol&#8221;, &#8220;smtps&#8221;);<br />
props.put(&#8220;mail.smtps.host&#8221;, SMTP_HOST_NAME);<br />
props.put(&#8220;mail.smtps.auth&#8221;, &#8220;true&#8221;);<br />
props.put(&#8220;mail.smtps.quitwait&#8221;, &#8220;false&#8221;);</p>
<p>Session mailSession = Session.getDefaultInstance(props);<br />
mailSession.setDebug(false);<br />
Transport transport = mailSession.getTransport();</p>
<p>MimeMessage message = new MimeMessage(mailSession);<br />
message.setSubject(subject);<br />
InternetAddress addressFrom = new InternetAddress(emailFromAddress);<br />
message.setFrom(addressFrom);<br />
message.setContent(content, &#8220;text/html&#8221;);</p>
<p>message.addRecipient(Message.RecipientType.TO,new InternetAddress(dest));</p>
<p>transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);</p>
<p>transport.sendMessage(message,message.getRecipients(Message.RecipientType.TO));<br />
transport.close();<br />
}<br />
}</p>
<p>reference: http://www.rgagnon.com/javadetails/java-0083.html</p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2007/08/03/javamail-smtp-with-gmail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Signed java applet</title>
		<link>http://technote.wsjoung.com/2007/05/15/signed-java-applet/</link>
		<comments>http://technote.wsjoung.com/2007/05/15/signed-java-applet/#comments</comments>
		<pubDate>Tue, 15 May 2007 17:43:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Applet]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2007/05/15/signed-java-applet/</guid>
		<description><![CDATA[Applet Security Basics Below are the basic facts regarding applet security and Java Plug-in. More detail can be found in the next chapter, How RSA Signed Applet Verification Works in Java Plug-in. All unsigned applets are run under the standard applet security model. If usePolicy IS NOT DEFINED in the java.policy file, then a signed [...]]]></description>
			<content:encoded><![CDATA[<h2>Applet Security Basics</h2>
<p>Below are the basic facts regarding applet security and Java Plug-in. More    detail can be found in the next chapter, <a href="http://java.sun.com/j2se/1.5.0/docs/guide/plugin/developer_guide/rsa_how.html">How RSA Signed    Applet Verification Works in Java Plug-in</a>.</p>
<ul>
<li>All <span style="text-decoration:underline;">unsigned applets</span> are run under the standard applet security model.</li>
<li>If <a href="http://java.sun.com/j2se/1.5.0/docs/guide/plugin/developer_guide/rsa_how.html#use">usePolicy</a> IS NOT DEFINED in the java.policy file, then a <span style="text-decoration:underline;">signed applet</span> has the AllPermission permission if:<br />
Java Plug-in can verify the signers, and the user, when prompted, agrees to granting the AllPermission permission.</li>
<li>If usePolicy IS DEFINED, then a <span style="text-decoration:underline;">signed applet</span> has only the permissions defined in java.policy and no prompting occurs.</li>
</ul>
<p>Moreover, note that Java Plug-in now handles certificate management; i.e.,    the certificate verification task is no longer passed off to the browser.</p>
<p>keytool -genkey -keyalg rsa -alias MyCert<br />
keytool -certreq -alias MyCert<br />
keytool -import -alias MyCert -file VSSStanleyNew.cer</p>
<p>or</p>
<p>keytool -selfcert</p>
<p>and</p>
<p>jarsigner AppletName.jar MyCert<br />
jarsigner -verify -verbose -certs AppletName.jar</p>
<ul>
<li><a href="http://java.sun.com/j2se/1.5.0/docs/guide/plugin/developer_guide/contents.html">Java Plugin guide</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2007/05/15/signed-java-applet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is the most popular programming language?</title>
		<link>http://technote.wsjoung.com/2006/12/28/what-is-the-most-popular-programming-language/</link>
		<comments>http://technote.wsjoung.com/2006/12/28/what-is-the-most-popular-programming-language/#comments</comments>
		<pubDate>Thu, 28 Dec 2006 05:44:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Features]]></category>
		<category><![CDATA[Language]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/12/28/what-is-the-most-popular-programming-language/</guid>
		<description><![CDATA[According to TIOBE, currently Java is the most popular language and C/ C++ are second, third placed. They update top 20 languages every month, based on their rating method. And they use couple of webs searching engines to count on its resources like availability of skilled engineers, courses and third party vendors. I think accuracy [...]]]></description>
			<content:encoded><![CDATA[<p>According to <a href="http://www.tiobe.com/tpci.htm">TIOBE</a>, currently Java is the most popular language and C/ C++ are second, third placed.</p>
<p class="MsoNormal">They update top 20 languages every month, based on their rating method. And they use couple of webs searching engines to count on its resources like availability of skilled engineers, courses and third party vendors.</p>
<p class="MsoNormal">I think accuracy of this result is not important. It should be just for fun especially if you are the programmer who is using one of top 5. And personally I would like to suggest them that those programming languages should be categorized, because to compare Java with SAS or PL/SQL is not make sense. It’s just like comparing orange with apple.</p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/12/28/what-is-the-most-popular-programming-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String constant pool</title>
		<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/</link>
		<comments>http://technote.wsjoung.com/2006/11/26/string-constant-pool/#comments</comments>
		<pubDate>Sun, 26 Nov 2006 23:50:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/string-constant-pool/</guid>
		<description><![CDATA[Everybody knows about String constant pool which is for efficient memory management in java. Basically most of objects are managed on heap area but String object. In most of ordinary application, programmers use String object quite often and this String object quite frequently need to be changed or it occupies large amounts of memory. Therefore [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">Everybody knows about String constant pool which is for efficient memory management in java. Basically most of objects are managed on heap area but String object. In most of ordinary application, programmers use String object quite often and this String object quite frequently need to be changed or it occupies large amounts of memory. Therefore instead of managing String object on heap area, they introduced String constant pool.</p>
<p class="MsoNormal">One of important characteristic of String constant pool is that it doesn’t create same String object if there is already String constant in the pool.</p>
<p class="MsoNormal"><code>String var1 = “This is String Literal”;<br />
String var2 = “This is String Literal”;</code></p>
<p class="MsoNormal">For above two String objects, JVM creates only one object in the String constant pool and for the second string reference variable (var2), it points the string object which is created for var1. In this case, (var1 == var2) is true.</p>
<p class="MsoNormal">But one thing, people make confused is that. It works only when it encounter on String Literal with double quote.</p>
<p class="MsoNormal"><code>String var3 = new String(“This is String Literal”);</code></p>
<p class="MsoNormal">In this case, a regular object will be created by new keyword on heap area and it will be placed in the String constant pool. Finally it will be assigned to the reference variable, var3. This process is just by passing from String constant pool management. Therefore, (var1 == var3) is false.</p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/11/26/string-constant-pool/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Read all files in a directory</title>
		<link>http://technote.wsjoung.com/2006/11/17/read-all-files-in-a-directory/</link>
		<comments>http://technote.wsjoung.com/2006/11/17/read-all-files-in-a-directory/#comments</comments>
		<pubDate>Fri, 17 Nov 2006 01:09:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Directory]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/17/read-all-files-in-a-directory/</guid>
		<description><![CDATA[int fileCount = 0; File dir = new File(inputDirName); File[] strFilesDirs = dir.listFiles(); if (strFilesDirs == null) { System.err.println(inputDirName +&#8221; is not valid directory name or there is no pdb file&#8221;); System.exit(1); } for (int i=0; i if (strFilesDirs[i].isDirectory()) { //System.out.println(&#8220;Directory: &#8220;+strFilesDirs[i]); } else if (strFilesDirs[i].isFile()) { //System.out.println(&#8220;File: &#8220;+strFilesDirs[i]+&#8221;(&#8220;+strFilesDirs[i].length()+&#8221;)&#8221;); fileCount = fileCount + 1; } [...]]]></description>
			<content:encoded><![CDATA[<p>int fileCount = 0;<br />
File dir = new File(inputDirName);<br />
File[] strFilesDirs = dir.listFiles();</p>
<p>if (strFilesDirs == null) {<br />
System.err.println(inputDirName +&#8221; is not valid directory name or there is no pdb file&#8221;);<br />
System.exit(1);<br />
}<br />
for (int i=0; i<br />
if (strFilesDirs[i].isDirectory()) {<br />
//System.out.println(&#8220;Directory: &#8220;+strFilesDirs[i]);<br />
} else if (strFilesDirs[i].isFile()) {<br />
//System.out.println(&#8220;File: &#8220;+strFilesDirs[i]+&#8221;(&#8220;+strFilesDirs[i].length()+&#8221;)&#8221;);<br />
fileCount = fileCount + 1;<br />
}<br />
}</p>
<p>beside, there is no such method which is changing directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/11/17/read-all-files-in-a-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
