<?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>Programming tips for newbies - CodeRookie</title>
	<atom:link href="http://www.coderookie.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coderookie.com</link>
	<description>Programming tips from a rookie developer to other rookie developers</description>
	<lastBuildDate>Wed, 17 Nov 2010 07:46:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Converting a set of mts files to a single avi file with fade in/out in Linux</title>
		<link>http://www.coderookie.com/2010/tutorial/converting-a-set-of-mts-files-to-a-single-avi-file-with-fade-inout-in-linux/</link>
		<comments>http://www.coderookie.com/2010/tutorial/converting-a-set-of-mts-files-to-a-single-avi-file-with-fade-inout-in-linux/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 20:10:55 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.coderookie.com/?p=32</guid>
		<description><![CDATA[For a while I used a commercial windows software to convert a bunch of MTS files, but as a Linux user (Windows is for games mostly :) ), I finally managed to find a way to do it using ffmpeg, a patch and mencoder.

I bought Panasonic SD-9 2 years ago and since then I was [...]]]></description>
			<content:encoded><![CDATA[<p>For a while I used a commercial windows software to convert a bunch of MTS files, but as a Linux user (Windows is for games mostly :) ), I finally managed to find a way to do it using ffmpeg, a patch and mencoder.<br />
<span id="more-32"></span></p>
<p>I bought Panasonic SD-9 2 years ago and since then I was filming all my vacations, parties, etc. Usually when I film I end up with at least a 50 MTS files that are mostly unrelated, so I wanted to have some nice fade out and fade ins between the joined slices. Those fades are the only thing that was some kind hard to do in linux, but half a year ago I found a nice patch to ffmpeg that does exactly this. So here we go.</p>
<p>Requirements:<br />
1. ffmpeg source code (if you use the latest trunk then you need libx264 version >= 0.99):<br />
<code>svn co svn://svn.ffmpeg.org/ffmpeg/trunk</code><br />
2. patch file (<a href="http://www.mail-archive.com/ffmpeg-soc@mplayerhq.hu/msg08155.html">mail list post</a>, or <a href="http://bmintern.homeunix.com/~brandon/vf_fade.patch">patch authors site</a> or the file hosted on <a href="http://www.coderookie.com/ffmpeg_fade2.patch">my blog</a>)<br />
3. mencoder (it is used to count the total frames of the movie)<br />
4. avimerge (to put all the converted files back together)</p>
<p>Steps:<br />
1. Go to the directory for ffmpeg<br />
2. Apply patch (patch -p 0 < patch_file)<br />
Application of patch may fail, as ffmpeg is changing, but all you really need is <a href="http://www.coderookie.com/vf_fade.c">vf_fade.c</a> file placed in libavfilter directory, and add line:<br />
<code>OBJS-$(CONFIG_FADE_FILTER)                   += vf_fade.o</code><br />
to libavfilter/Makefile, as well a line:<br />
<code>REGISTER_FILTER (FADE,        fade,        vf);</code><br />
to libavfilter/allfilters.c</p>
<p>3. Build ffmpeg: ./configure with appropriate options, mine are:<br />
<code>--prefix=$HOME/ffmpeg --enable-libx264 --enable-libxvid --enable-libvorbis --enable-libtheora --enable-libmp3lame --enable-libfaac --enable-avfilter --enable-nonfree --enable-postproc --enable-runtime-cpudetect --enable-hardcoded-tables  --enable-hwaccel=h263_vaapi --enable-hwaccel=h264_vaapi --enable-hwaccel=mpeg2_vaapi --enable-hwaccel=mpeg4_vaapi --enable-hwaccel=vc1_vaapi --enable-hwaccel=wmv3_vaapi --enable-filter=fade --enable-encoder=libx264 --enable-encoder=libxvid --enable-encoder=libmp3lame --enable-encoder=libfaac --enable-encoder=wmv2 --enable-encoder=wmv1 --enable-encoder=vorbis --enable-encoder=mpeg4 --enable-encoder=ac3 --enable-decoder=h264_vdpau  --enable-gpl</code><br />
And make, followed by make install.</p>
<p>Now you should have working ffmpeg with fade in/outs.</p>
<p>Here&#8217;s a <a href="http://www.coderookie.com/make_avi.sh">make_avi.sh</a> script that I&#8217;ve written for this:<br />
<code><br />
#!/bin/sh<br />
BIT_RATE=2700k<br />
SIZE=720x576<br />
fade_dur=15<br />
FFMPEG=ffmpeg<br />
for FILE_IN in $*; do<br />
    echo -n "$FILE_IN...."<br />
    #last_frame=`$FRAME_COUNTER $FILE_IN`<br />
    last_frame=` mencoder -nosound -ovc frameno -vc null -o /dev/null $FILE_IN 2>/dev/null | egrep " [0-9]+ frames\$" | gawk '{print \$12}'`<br />
    echo $last_frame<br />
    filters="-vfilters fade=in:0:$fade_dur,fade=out:$[last_frame/2 - $fade_dur-5]:$fade_dur"<br />
    ${FFMPEG} -i $FILE_IN  -deinterlace -vcodec libxvid -aspect 4:3 -r 25 -s $SIZE -b $BIT_RATE $filters -acodec libmp3lame -ac 2 -ab 128k -y -pass 1 -passlogfile temp.log -f avi /dev/null &#038;&#038; \<br />
    ${FFMPEG} -i $FILE_IN -deinterlace -vcodec libxvid -aspect 4:3 -r 25 -s $SIZE -b $BIT_RATE $filters -acodec libmp3lame -ac 2 -ab 128k -y -pass 2 -passlogfile temp.log -f avi ${FILE_IN/MTS/avi}<br />
done<br />
in_file_list="$*"<br />
out_file_list=${in_file_list//MTS/avi}<br />
avimerge -o merge.avi -i $out_file_list<br />
</code></p>
<p>Just save it, change FFMPEG variable to your location of ffmpeg and run it passing a list of MTS files, it will create a merge.avi file in the current directory.<br />
You can also tweak the &#8220;fade_dur&#8221; to make the fade longer/shorter.</p>
<p>I know it&#8217;s not much of a how to, but maybe someone will find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coderookie.com/2010/tutorial/converting-a-set-of-mts-files-to-a-single-avi-file-with-fade-inout-in-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google AI Challange</title>
		<link>http://www.coderookie.com/2010/ai/google-ai-challange/</link>
		<comments>http://www.coderookie.com/2010/ai/google-ai-challange/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 19:05:00 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[python ai]]></category>

		<guid isPermaLink="false">http://www.coderookie.com/?p=29</guid>
		<description><![CDATA[Long time no see :)
I&#8217;ve been lately looking more and more into AI programming (mostly using great Artificial Intelligence: Modern Approach, it really lacks exercise answers that would be great for self study) and found Google AI Challenge I hope to at least appear in the leader boards :)
Right now I have only uploaded the [...]]]></description>
			<content:encoded><![CDATA[<p>Long time no see :)</p>
<p>I&#8217;ve been lately looking more and more into AI programming (mostly using great <a href="http://www.amazon.com/gp/product/0136042597?ie=UTF8&#038;tag=coderookie-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0136042597">Artificial Intelligence: Modern Approach</a>, it really lacks exercise answers that would be great for self study) and found <a href="http://csclub.uwaterloo.ca/contest/">Google AI Challenge</a> I hope to at least appear in the leader boards :)<br />
Right now I have only uploaded the started kit (in Python) and I&#8217;ll try to create a bot that will appear at east at 300th position :).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coderookie.com/2010/ai/google-ai-challange/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Job Interview Tips (for Software Engineers)</title>
		<link>http://www.coderookie.com/2006/job/job-interview-tips/</link>
		<comments>http://www.coderookie.com/2006/job/job-interview-tips/#comments</comments>
		<pubDate>Tue, 12 Sep 2006 07:03:41 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[job]]></category>

		<guid isPermaLink="false">http://www.coderookie.com/2006/job/job-interview-tips/</guid>
		<description><![CDATA[


 Hi,
I am having a job interview on Thursday (that&#8217;s why there are no new posts lately) and I wanted to find out what resources do readers use when they go to an interview.


Here are the links that I used so far:

How to Write a Killer Resume, for Software Engineers
Preparing for a Software Engineering Interview
50 [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-3846130357517643";
google_ad_width = 468;
google_ad_height = 15;
google_ad_format = "468x15_0ads_al";
google_ad_channel ="6817347183";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "008000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<img src="http://www.coderookie.com/wp-content/uploads/2006/09/images.jpg" alt="job interview" align="left" /> Hi,<br />
I am having a job interview on Thursday (that&#8217;s why there are no new posts lately) and I wanted to find out what resources do readers use when they go to an interview.<br />
<br/><br />
<span id="more-18"></span></p>
<p>Here are the links that I used so far:</p>
<ol>
<li><a href="http://niniane.org/resume_howto.html">How to Write a Killer Resume, for Software Engineers</a></li>
<li><a href="http://niniane.org/interview_howto.html">Preparing for a Software Engineering Interview</a></li>
<li><a href="http://bhuvans.wordpress.com/2006/08/19/50-common-interview-qa/">50 Common Interview Q&#038;A</a></li>
<li><a href="http://modisintl.com/careers/permanent/interview_tips.asp">Modis Interview Tips</a></li>
</ol>
<p>If you have some more tips on job interviews then let me know (Thursday is nearing !), thanks :)<br />
(I&#8217;ll update the short list with propositions from the comments)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coderookie.com/2006/job/job-interview-tips/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Really Easy Introduction to JSP and Servlets and . Part I</title>
		<link>http://www.coderookie.com/2006/java/a-really-easy-introduction-to-servlets-and-jsp-part-i/</link>
		<comments>http://www.coderookie.com/2006/java/a-really-easy-introduction-to-servlets-and-jsp-part-i/#comments</comments>
		<pubDate>Tue, 05 Sep 2006 07:58:55 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[j2ee]]></category>

		<guid isPermaLink="false">http://www.coderookie.com/2006/java/a-really-easy-introduction-to-servlets-and-jsp-part-i/</guid>
		<description><![CDATA[Have you ever wondered "What the hell is this J2EE thingy?", "How can someone use Java to develop web applications?" or even "Web pages in Java? Isn't this for applets only?".
If so, than we have something in common, for years I have been asking myself those questions, while not having enough time to dig into [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.coderookie.com/wp-content/uploads/2006/09/question.jpg" alt="question mark" align="left" />Have you ever wondered "What the hell is this J2EE thingy?", "How can someone use Java to develop web applications?" or even "Web pages in Java? Isn't this for applets only?".</p>
<p>If so, than we have something in common, for years I have been asking myself those questions, while not having enough time to dig into the subject and learn more about Java. This language had always seemed to me to slow and having an ugly GUI (remember all that applets floating around the web in the late 90-ties ?).</p>
<p>As I have finally found some time to study a part of J2EE consisting of Servlets and JSP (using the excellent <a href="http://www.amazon.com/gp/product/0596005407?ie=UTF8&amp;tag=coderookie-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596005407">Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam (SCWCD)</a><img src="http://www.assoc-amazon.com/e/ir?t=coderookie-20&amp;l=as2&#038;o=1&amp;a=0596005407" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> by Kathy Sierra et al.), I will present you with what I have learned. I really hope that you will benefit from the information presented below. If you have bought some kind of Tomcat hosting or some other J2EE web hosting than you can skip the first point, and go straight to the second one.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3846130357517643";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="9138240644";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "FFFFFF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<span id="more-11"></span></p>
<p><img src="http://www.coderookie.com/wp-content/uploads/2006/09/tomcat.gif" alt="Tomcat" class="alignright" /><strong>1. Getting a web container - Tomcat</strong></p>
<p>First of all, you should know that most J2EE technologies (OK, maybe not most, but few crucial ones: EJB, servlets &#038; JSP) cannot be run like normal Java applications just by invoking java executable in the command line.</p>
<p>Servlets, JSP and EJB need a... lets call it a framework and this kind of framework implementation specifically for servlets/JSP (called a Web Container) is Apache Tomcat, and it will be the basis for this tutorial. If you would like to use some other container than have a look at e.g. Jetty.</p>
<p>Now, lets start with the tutorial.</p>
<p><a href="http://www.gpsnavigatorsreview.com/garmin/garmin-nuvi-660-43-inch-widescreen-bluetooth-portable-gps-navigator/" ><strong>Garmin nüvi 660</strong> wide screen GPS review</a></p>
<p>First you need to have JDK installed, which can be downloaded from http://java.sun.com/javase/downloads/index.jsp (choose JDK 5.0 Update x), and then install the JDK (if there are any problems than let me know I'll try to clarify this).</p>
<p>Secondly we will download tomcat from <a href="http://tomcat.apache.org/download-55.cgi">here</a> and for this tutorial I use Tomcat 5.5.17. For the lazy ones, here is a <a href="http://www.apache.org/dist/tomcat/tomcat-5/v5.5.17/bin/apache-tomcat-5.5.17.zip">direct link to 5.5.17 version</a>. </p>
<p>Before running Tomcat, there should be a JAVA_HOME variable defined in environment, how to do it:</p>
<p><strong>in Windows</strong>: Go to Control Panel, double click System, select Advanced tab, and click "Environment Variables" button. Check if there is no JAVA_HOME defined in user and system variables pointing to JDK directory, if there is then double check that it points correctly to a JDK (not JRE), if there is no such variable then click New button in system, give a JAVA_HOME name, and paste in the directory where your JDK is sitting (on my system it is "C:\Program Files\Java\jdk1.5.0_06").</p>
<p><strong>in Unix</strong>: Find where you have JDK, usually "where java" or "whereis java" should give you the path to the java executable (not a symlink!), on my system it is "/opt/sun-jdk-1.5.0.07". Depending on the shell you have, setting variable will be "export JAVA_HOME=..." or "setenv JAVA_HOME ..." (replace the dots with the path to the JDK). BTW, please feel free to ask be questions if you have any problem.</p>
<p>Unzip the archive in a directory you want and start the file startup.bat. Unix users should first do "chmod u+x *.sh", and then run startup.sh. If everything works fine then you should see something like this:</p>
<div class="syntax_hilite">
<div id="code-11">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Using CATALINA_BASE:&nbsp; &nbsp;/home/krzyk/apache-tomcat-<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">17</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Using CATALINA_HOME:&nbsp; &nbsp;/home/krzyk/apache-tomcat-<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">17</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Using CATALINA_TMPDIR: /home/krzyk/apache-tomcat-<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">17</span>/temp</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Using JRE_HOME:&nbsp; &nbsp; &nbsp; &nbsp;/usr/lib/jvm/sun-jdk-<span style="color:#800000;color:#800000;">1</span>.<span style="color:#800000;color:#800000;">5</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now go to the address http://localhost:8080/ and see if it really works, you should see a page about Apache Tomcat.</p>
<p>If it is correct then....</p>
<p><img src="http://www.coderookie.com/wp-content/uploads/2006/09/566435_fourth_of_july.jpg" alt="fireworks" class="center"/></p>
<p>Congratulations! You have just made the first step into the J2EE world ;). </p>
<p><strong>2. Writing the first servlet</strong></p>
<p>Now it's time to get our hands dirty and write some code, but first we need to make some essential directories.</p>
<p>Create a directory where your project will be kept (I'll name it FirstApplication), under that directory<br />
create following dirs:</p>
<div class="syntax_hilite">
<div id="code-12">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">WEB-INF</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">WEB-INF/src</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">WEB-INF/classes </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>If you use some java IDE (e.g. Eclipse or NetBeans) for developing code, then mark the "src" directory as the one containing the source, and the "classes" as the one with binaries. For the rest of us lets make directory for com.coderookie, that is under "src" mkdir "com" and "com/coderookie".</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3846130357517643";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="9138240644";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "FFFFFF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Go into the WEB-INF/src/com/coderookie dir, and create a file called FirstServlet.java with the following code:</p>
<div class="syntax_hilite">
<div id="java-13">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">package com.<span style="color: #006600;">coderookie</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import javax.servlet.http.HttpServlet;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import javax.servlet.http.HttpServletRequest;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import javax.servlet.http.HttpServletResponse;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import java.io.PrintWriter;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import java.io.IOException;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FirstServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet <span style="color: #808080; font-style: italic;">//#1</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> doGet<span style="color: #66cc66;">&#40;</span>HttpServletRequest request,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; HttpServletResponse response<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?q=allinurl%3AIOException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">IOException</span></a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//#2</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3APrintWriter+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">PrintWriter</span></a> out = response.<span style="color: #006600;">getWriter</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//#3</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; out.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Hello world!"</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//#4</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>And now for explanations:<br />
#1 - servlet is really just a class that extends HttpServlet and implements certain methods</p>
<p>#2 - here is one of those mentioned methods doGet is responsible for handling the GET method (pretty obvious) of HTTP protocol (see <a href="http://en.wikipedia.org/wiki/HTTP#Request_methods">this wiki page for more information on HTTP methods</a>)</p>
<p>#3 - HttpServletResponse has a method that allows us to get a PrintWriter for the web page output</p>
<p>#4 - using PrintWriter methods we can write anything (using a web page) to the user that entered our servlet</p>
<p>Besides writing the code, we need to write a web descriptor for our application. Descriptor is used to inform web container about the applications ingredients. You must put there such information as: what are the names your servlets, how URLs should map to a certain servlet and much more (I'll cover more in other posts).</p>
<p>Create a web.xml file in WEB-INF directory:</p>
<div class="syntax_hilite">
<div id="xml-14">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;web</span>-app <span style="color: #000066;">xmis</span>=<span style="color: #ff0000;">"http://java.sun.com/xml/ns/j2ee"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; xmlns:<span style="color: #000066;">xsi</span>=<span style="color: #ff0000;">"http://www.w3.org/2001/XMLSchema-instance"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; xsi:<span style="color: #000066;">schemaLocation</span>=<span style="color: #ff0000;">"http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066;">version</span>=<span style="color: #ff0000;">"2.4"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;servlet<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;servlet</span>-name<span style="font-weight: bold; color: black;">&gt;</span></span>SimpleServlet<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/servlet</span>-name<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;servlet</span>-class<span style="font-weight: bold; color: black;">&gt;</span></span>com.coderookie.FirstServlet<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/servlet</span>-class<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/servlet<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;servlet</span>-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;servlet</span>-name<span style="font-weight: bold; color: black;">&gt;</span></span>SimpleServlet<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/servlet</span>-name<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;url</span>-pattern<span style="font-weight: bold; color: black;">&gt;</span></span>/first<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/url</span>-pattern<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/servlet</span>-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/web</span>-app<span style="font-weight: bold; color: black;">&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Don't worry about the long <web-app...> tag, you will copy it between different applications, you do not have to memorize it.</p>
<p>Go to the WEB-INF directory and run following command (you MUST replace TOMCAT with the exact location of your tomcat installation e.g. "/home/krzyk/apache-tomcat-5.5.17" or "d:\tomcat")</p>
<p>For <strong>Windows</strong> users (note "<strong>\</strong>" and "<strong>;</strong>"):</p>
<div class="syntax_hilite">
<div id="code-15">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">javac -cp TOMCAT\common\lib\servlet-api.<span style="">jar</span>;classes;.</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;-d classes src\com\coderookie\FirstServlet.<span style="">java</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>For <strong>Unix</strong> ones (here we have "<strong>/</strong>" and "<strong>:</strong>"):</p>
<div class="syntax_hilite">
<div id="code-16">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">javac -cp TOMCAT/common/lib/servlet-api.<span style="">jar</span>:classes:.</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;-d classes src/com/coderookie/FirstServlet.<span style="">java</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>It is time to test your servlet, copy your projects directory to TOMCAT/webapps (again change TOMCAT to the directory where you have unzipped Tomcat). Change directory to TOMCAT/bin and do shutdown.bat (or shutdown.sh) and then startup.bat (or startup.sh).</p>
<p>If there is no error then type in a browser http://localhost:8080/PROJECT_NAME/first (where PROJECT_NAME is a name of your projects directory in webapps directory). Notice that "/first" is the url-pattern from web.xml file.</p>
<p>You should see a "Hello world!" displayed on this page, if it is than we have another success!</p>
<p><a href="http://www.flickr.com/photos/67566398@N00/183579318/"><img src="http://www.coderookie.com/wp-content/uploads/2006/09/183579318_2cfc891466_m.jpg" alt="combine" align="left" /></a><br />
<strong>3. Combining servlet and JSP</strong></p>
<p>What if you would like to print a HTML page using the servlet above ? </p>
<p>Using println for the whole page would be a horror, just have a look at the example presented below:</p>
<ol>
&nbsp;
</ol>
<div class="syntax_hilite">
<div id="java-17">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">out.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"&lt;HTML&gt;"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">out.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"&lt;HEAD&gt;"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">out.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"&lt;TITLE&gt;"</span> + <span style="color: #ff0000;">"My first page"</span> + <span style="color: #ff0000;">"&lt;/TITLE&gt;"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">out.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"&lt;/HEAD&gt;"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">out.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"&lt;BODY&gt;"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">out.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"&lt;/BODY&gt;"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">out.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"&lt;/HTML&gt;"</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>To much out.println, don't you think ? But have no fear, JSP to the rescue.</p>
<p>Create a file named hi.jsp (or whatever you like) and place is either in WEB-INF or in the directory of the project (the one that is higher then WEB-INF):</p>
<div class="syntax_hilite">
<div id="xml-18">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;html<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;head<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;title<span style="font-weight: bold; color: black;">&gt;</span></span></span>${title}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/title<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/head<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;body<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; Hi World !</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/body<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/html<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This page contains an EL (Expression Language) structure ${title}, which can be set from the servlet, we will use this page as a view for our servlet.</p>
<p>Change the code of FirstServlet to this one:</p>
<div class="syntax_hilite">
<div id="java-19">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">package com.<span style="color: #006600;">coderookie</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import javax.servlet.http.HttpServlet;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import javax.servlet.http.HttpServletRequest;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import javax.servlet.http.HttpServletResponse;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import javax.servlet.RequestDispatcher;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import javax.servlet.ServletContext;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import javax.servlet.ServletException;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import java.io.IOException;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FirstServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> doGet<span style="color: #66cc66;">&#40;</span>HttpServletRequest request,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; HttpServletResponse response<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <a href="http://www.google.com/search?q=allinurl%3AIOException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">IOException</span></a></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; request.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"title"</span>, <span style="color: #ff0000;">"My first super page"</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// #1</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; ServletContext app = getServletContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; RequestDispatcher dispatcher =</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; app.<span style="color: #006600;">getRequestDispatcher</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"/hi.jsp"</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//#2</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; dispatcher.<span style="color: #006600;">forward</span><span style="color: #66cc66;">&#40;</span>request,response<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Explanations:<br />
#1 - for now, just assume, that everything dynamic that you wan to display on the JSP page, should be previously set by the setAttribute of the HttpServletRequest, first parameter is the name which you will use to display the second argument in JSP (here "title", so in JSP it will be ${title} and will be replaced by Tomcat with "My first super page")</p>
<p>#2 - we must get a ServletContext (this object keeps global configuration for the application), and from it, the RequestDispatcher for the JSP page, in the parameter you need to provide the path to the JSP, relative to the application folder (that is, one step higher than WEB-INF), OK this might be confusing, so look at the ASCII drawing below. And finally, we forward the control to the JSP page by calling forward method of the RequestDispatcher.</p>
<div class="syntax_hilite">
<div id="code-20">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">PROJECT_NAME</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|- hi.<span style="">jsp</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;-- WEB-INF</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;- classes</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;- src</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;- <span style="color:#006600; font-weight:bold;">&#40;</span>hi.<span style="">jsp</span> - you can put it even here<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now make your favorite drink ready, and go to the http://localhost:8080/PROJECT_NAME/first</p>
<p>Probably you should see a page with title "My first super page", and "Hi World!" text on it. If it works, then once again, you rule (and I haven't made any mistakes ;).</p>
<p><img src="http://www.coderookie.com/wp-content/uploads/2006/09/234620006_892d12a8b4_m.jpg" alt="234620006_892d12a8b4_m.jpg" alt="Have fun" class="alignright" />This is it for now, stay tuned for the following parts, introducing more advanced topics, you can now review material from this tutorial, play around with the JSP and servlet, <strong>have some fun</strong>. If you develop an interesting application using the very basic information above, please send me an info, a link to the application or the source code. The next part of this tutorial will be about Model-View-Controler design pattern and how to apply it to servlets and JSP.</p>
<p><script>reddit_url='http://www.coderookie.com/2006/java/a-really-easy-introduction-to-servlets-and-jsp-part-i/'</script><br />
<script language="javascript" src="http://reddit.com/button.js?t=3"></script> &nbsp;&nbsp; <script>
digg_url = 'http://digg.com/programming/A_Really_Easy_Introduction_to_JSP_and_Servlets_J2EE';
</script><script src="http://digg.com/api/diggthis.js"></script> </p>
<p><a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.coderookie.com%2F2006%2Fjava%2Fa-really-easy-introduction-to-servlets-and-jsp-part-i%2F&#038;title=A+Really+Easy+Introduction+to+Servlets+and+JSP.+Part">Add to del.icio.us <img src="http://www.coderookie.com/wp-content/themes/unsleepable/images/delicious.png" alt="delicious" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.coderookie.com/2006/java/a-really-easy-introduction-to-servlets-and-jsp-part-i/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Python versus Java</title>
		<link>http://www.coderookie.com/2006/java/python-versus-java/</link>
		<comments>http://www.coderookie.com/2006/java/python-versus-java/#comments</comments>
		<pubDate>Thu, 31 Aug 2006 09:22:01 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.coderookie.com/2006/java/python-versus-java/</guid>
		<description><![CDATA[Ever wondered why there are so many people that program in Python, although Java (along with .NET) is the main enterprise language? You can find out in this post at bitworking.org.
Joe talks about the things (technical term!) that Python has and Java misses. Here is the list of those abstractions with my comments and ways [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/ecosnake/215576226/"><img src="http://static.flickr.com/62/215576226_c60840e1df_m.jpg" alt="python" align="left" /></a>Ever wondered why there are so many people that program in Python, although Java (along with .NET) is the main enterprise language? You can find out in <a href="http://bitworking.org/news/Python_isnt_Java_without_the_compile">this post</a> at bitworking.org.<!--adsense#posts_small--></p>
<p>Joe talks about the things (technical term!) that Python has and Java misses. Here is the list of those abstractions with my comments and ways of simulating (give me a feedback with your propositions):<br />
<span id="more-10"></span></p>
<p><a href="http://www.gpsnavigatorsreview.com/garmin/garmin-nuvi-360-35-inch-bluetooth-portable-gps-navigator/" title="Garmin nuvi 360 info">Review of <strong>Garmin nüvi 360</strong> GPS with bargain price</a></p>
<p>   <strong>1.  First-class functions</strong><br />
This is known from C++, where you can define function pointer that can be passed around as e.g. a parameter to other function.</p>
<p>   <strong>2. Keyword parameters</strong><br />
OK, that's the one I would like to have in Java, it would add a better strictness to the language, now if you want to simulate this kind of behaviour you would have to create a class and add setters/getters.</p>
<p>   <strong>3. Default parameters</strong><br />
I don't know why did Sun skip this while creating Java, it is a very useful abstraction. The simulations of this can be achieved by many overloaded methods/constructors.</p>
<div class="syntax_hilite">
<div id="java-23">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> A <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> value;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #993333;">void</span> calculate<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; value = a;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #993333;">void</span> calculate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; calculate<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">10</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// this is the default</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>   <strong>4. Tuples</strong><br />
   <strong>5. Parallel assignment</strong><br />
   <strong>6. Efficient multiple return values</strong><br />
Here I can't give any proposition how to simulate this in Java (at some point arrays might be used). A very nice functionality of Python (and some other languages), especially in conjunction with the next one...<!--adsense--><br />
That is, returning a tuple out of a method. Again some may try to simulate it using arrays.</p>
<p>   <strong>7. Continuations</strong><br />
They are a way to save a function execution, and restore it at later time, it's as if you could jump out of a function during it's execution, and than, when by calling the function again, returning to the exact point where the function has been saved.</p>
<p>Here's an example to give you a better understanding of this. It is a function that will return values from the beginning to the end:</p>
<div class="syntax_hilite">
<div id="python-24">
<div class="python">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">def</span> fun<span style="color: black;">&#40;</span>begin, end<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; i = begin</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff7700;font-weight:bold;">while</span> i &lt;end:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">yield</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; i = i + <span style="color: #ff4500;color:#800000;">1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">f=fun<span style="color: black;">&#40;</span><span style="color: #ff4500;color:#800000;">10</span>,<span style="color: #ff4500;color:#800000;">100</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">f.<span style="color: black;">next</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">f.<span style="color: black;">next</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">f.<span style="color: black;">next</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Executing above code gives:<br />
<code>10<br />
11<br />
12<br />
</code></p>
<p>   <strong>8. User-defined operators</strong><br />
That one was probably a mistake, I don't know a way to add a user-defined operator to Python (give me a hint if I am wrong)</p>
<p>   <strong>9. Closures</strong><br />
In one of the <a href="http://www.coderookie.com/2006/java/closures-in-java/">previous posts</a> I mentioned about proposition to add closures to Java.</p>
<p>   <strong>10. Meta-programming</strong><br />
I haven't used much of this in Python, but it allows e.g. to assigning methods to classes on the fly. A nice functionality but I don't know how could it be used in a corporate environment, with more than 5 developers creating the code.</p>
<p><script>reddit_url='http://www.coderookie.com/2006/java/python-versus-java/'</script><br />
<script language="javascript" src="http://reddit.com/button.js?t=3"></script> &nbsp;&nbsp; <script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.coderookie.com/2006/java/python-versus-java/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>&#8220;Screenshots&#8221; of VIM Color Schemes</title>
		<link>http://www.coderookie.com/2006/vim/screenshots-of-vim-color-schemes/</link>
		<comments>http://www.coderookie.com/2006/vim/screenshots-of-vim-color-schemes/#comments</comments>
		<pubDate>Fri, 25 Aug 2006 21:37:59 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.coderookie.com/2006/vim/screenshots-of-vim-color-schemes/</guid>
		<description><![CDATA[Garmin for motorcycles - Zumo 550 reviews
Have you ever tried to choose the best color scheme in VIM ? Typing those ":colorscheme ..." and looking at your code (sometimes with disgust;) ). Those days are over, now there is a webpage with VIM color schemes html "screenshots" (for C, HTML, Java, LaTeX and Perl).  [...]]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://www.gpsnavigatorsreview.com/garmin/garmin-zumo-550-35-inch-portable-gps-motorcycle-navigator/" title="Zumo 550 review">Garmin for motorcycles - Zumo 550 reviews</a></strong></p>
<p>Have you ever tried to choose the best color scheme in VIM ? Typing those ":colorscheme ..." and looking at your code (sometimes with disgust;) ). Those days are over, now there is a <a href="http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/index.html">webpage with VIM color schemes</a> html "screenshots" (for C, HTML, Java, LaTeX and Perl).  If you didn't know this VIM command you should have a look at <a href="http://www.amazon.com/gp/product/1847190936?ie=UTF8&amp;tag=coderookie-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1847190936">Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor</a><img src="http://www.assoc-amazon.com/e/ir?t=coderookie-20&amp;l=as2&amp;o=1&amp;a=1847190936" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> which presents many commands needed in "real life" ;).</p>
<p>If you want to have a quick look at e.g. java <a href="http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/index-java.html">go here</a>. There are literally hundreds of schemes, I didn't people made so many. This page may load slowly, but after that, you can choose whatever scheme you like and download it.</p>
<p>And BTW, this page is in pure HTML with each scheme in an IFRAME, so you can increase and decrease the font size. Have fun !<br />
<!--adsense--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.coderookie.com/2006/vim/screenshots-of-vim-color-schemes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8220;Code Complete&#8221; Review &#8211; The End of Programming Stoneage?</title>
		<link>http://www.coderookie.com/2006/book-review/end-of-programming-sotoneage/</link>
		<comments>http://www.coderookie.com/2006/book-review/end-of-programming-sotoneage/#comments</comments>
		<pubDate>Tue, 22 Aug 2006 09:57:17 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[book review]]></category>

		<guid isPermaLink="false">http://www.coderookie.com/2006/book-review/end-of-programming-sotoneage/</guid>
		<description><![CDATA[
  I bought this book only because it was mentioned on the page of "The Pragmatic Programmer" at amazon as a recommendation. And I must say I was really impressed with the knowledge that is contained in it.
Whole book contains very useful tips for every programmer, not only a beginner but probably many experts [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/exec/obidos/redirect?link_code=as2&amp;path=ASIN/0735619670&amp;tag=bookreviewbyk-20&amp;camp=1789&amp;creative=9325"><br />
<img border="0" src="http://images.amazon.com/images/P/0735619670.01._AA_SCMZZZZZZZ_.jpg" align="left"/></a><img src="http://www.assoc-amazon.com/e/ir?t=bookreviewbyk-20&amp;l=as2&amp;o=1&amp;a=0735619670" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> <!--adsense#posts_small--> I bought this book only because it was mentioned on the page of "The Pragmatic Programmer" at <a href="http://www.amazon.com/gp/redirect.html?link_code=ur2&amp;tag=bookreviewbyk-20&amp;camp=1789&amp;creative=9325">amazon</a> as a recommendation. And I must say I was really impressed with the knowledge that is contained in it.</p>
<p>Whole book contains very useful tips for every programmer, not only a beginner but probably many experts will find it useful.<br />
<span id="more-7"></span>The information ranges from requirements and design to the ways a programmer should format his code (and there is also a place for religious placement of the brackets ;) ).</p>
<p><a href="http://www.hdtvsreview.com/lcd/toshiba-regza-32hl67u-32-720p-lcd-hdtv/" title="Cheap HDTV solution review - Toshiba REGZA 32HL67U">Review of the Toshiba <strong>REGZA 32HL67U</strong> 32 inch LCD HDTV</a></p>
<p>Furthermore, after every chapter there is a checklist, which helps to map your code to the information from that section. There are also a propositions for books to read on the given subject, and very useful "key points" part, which really improve understanding and keeping in the head the major points from the chapter.</p>
<p>This book should be on every programmers bookshelf, and information contained in it ought to be the subject of every computer science university course.<br />
<!--adsense--></p>
<p>For more details please check my <a href="http://krisreviews.com/2006/12/code-complete-second-edition/">Code Complete review</a> at KrisReviews.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coderookie.com/2006/book-review/end-of-programming-sotoneage/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Closures in Java?</title>
		<link>http://www.coderookie.com/2006/java/closures-in-java/</link>
		<comments>http://www.coderookie.com/2006/java/closures-in-java/#comments</comments>
		<pubDate>Sat, 19 Aug 2006 08:43:45 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.coderookie.com/2006/08/19/closures-in-java/</guid>
		<description><![CDATA[TomTom ONE XL-S - a wide screen GPS
Just a short notice, found it while browsing the digg for programming stories.
There is a proposition to include closures in Java (probably 7.0), here is a pdf file with the proposition.

I am quite new to this functional programming concept, but to give you some idea what is it [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gpsnavigatorsreview.com/tomtom/tomtom-one-xl-s-43-inch-widescreen-portable-gps-navigator/" title="A widescreen GPS from TomTom">TomTom ONE XL-S - a wide screen GPS</a></p>
<p><!--adsense#posts_small-->Just a short notice, found it while browsing the digg for programming stories.<br />
There is a proposition to include closures in Java (probably 7.0), here is a pdf file with <a href="http://blogs.sun.com/roller/resources/ahe/closures.pdf">the proposition</a>.</p>
<p><span id="more-6"></span></p>
<p>I am quite new to this functional programming concept, but to give you some idea what is it (example taken from the pdf file):</p>
<div class="syntax_hilite">
<div id="java-27">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">static</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// here is the definition of function type</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #993333;">int</span> plus2<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> x<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> x+<span style="color: #cc66cc;color:#800000;">2</span>; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// here we have an alias for the same function</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #993333;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span> plus2b = plus2;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span>plus2b<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Maybe it doesn't look so great (aliases for functions, phi), but AFAIR there should be also a way to do this:</p>
<div class="syntax_hilite">
<div id="java-28">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">static</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #993333;">int</span> power<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> x, <span style="color: #993333;">int</span> y<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <a href="http://www.google.com/search?q=allinurl%3AMath+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Math</span></a>.<span style="color: #006600;">pow</span><span style="color: #66cc66;">&#40;</span>y,x<span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// definition of x^2</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #993333;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span> power2 = power<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// should print 10^2&nbsp; = 100</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span>power2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><!--adsense--></p>
<p>But I could not find it in the pdf file, so maybe there won't be such possibility.<br />
I'll try to introduce more "functional" concepts in some of the future posts, so stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coderookie.com/2006/java/closures-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Pseudocode Programming Process</title>
		<link>http://www.coderookie.com/2006/tutorial/the-pseudocode-programming-process/</link>
		<comments>http://www.coderookie.com/2006/tutorial/the-pseudocode-programming-process/#comments</comments>
		<pubDate>Thu, 17 Aug 2006 19:19:39 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.coderookie.com/2006/08/17/the-pseudocode-programming-process/</guid>
		<description><![CDATA[  Pseudocode interesting technique that I found in Code Complete, Second Edition by Steve McConnell. 
PPP is a way of developing routines by writing pseudocode for them  in the first place (not a new topic) and after that, making the pseudocode a comment in the routine (functions, procedure, method or whatever your language [...]]]></description>
			<content:encoded><![CDATA[<p><img class="post_img" src="http://www.coderookie.com/wp-content/uploads/2006/08/code.jpg" alt="Code on a monitor" align="left" alt=""/>  Pseudocode interesting technique that I found in <a href="http://www.amazon.com/gp/product/0735619670?ie=UTF8&amp;tag=bookreviewbyk-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0735619670">Code Complete, Second Edition</a><img src="http://www.assoc-amazon.com/e/ir?t=coderookie-20&#038;l=as2&#038;o=1&#038;a=0735619670" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> by Steve McConnell. </p>
<p>PPP is a way of developing routines by writing pseudocode for them  in the first place (not a new topic) and after that, <strong>making the pseudocode a comment</strong> in the routine (functions, procedure, method or whatever your language calls them). After comments are in the empty routine, the <string>last</strong> thing to do is write the code below appropriate comment lines. </p>
<p>I know it isn't the clearest explanation, here look below at the example that I prepared.<br />
<span id="more-5"></span><br />
We'll work on a routine responsible for query searching in a search engine (based on my very simple &#038; ugly search engine.)</p>
<p><a href="http://www.gpsnavigatorsreview.com/magellan/magellan-maestro-3100-35-inch-portable-gps-navigator/" title="Magellan 3100 GPS review">Magellan Maestro 3100 a best value GPS for vehicles, review</a></p>
<p>First, let's write the header comment for the routine:</p>
<div class="syntax_hilite">
<div id="php-32">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// Searches for query in a set of pages, every word</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// is searched independently, and then results of all</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// search operations are concatenated. </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Pretty simple, but should state what the routine will do. Next I will use a simple English statements as pseudocode and write the body of the routine:</p>
<div class="syntax_hilite">
<div id="php-33">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// Searches for query in a set of pages, every word</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// is searched independently, and then results of all</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// search operations are concatenated.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// split query into separate words</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// for each word in the query</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// get pages containing the word</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// from the database</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// for each page</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// if this page is in the score table</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// add current word occurrences on the</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// page to the score table for given page</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// if this page is not in the score table</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// add the page to the score table</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// and store current word occurrences for</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// this page in the score table</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// create container for pages to return</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// for each page in the score table</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// retrieve page info from database and store it</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// in the container</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// return the container </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>It is not the most complicated routine in the word but will do.</p>
<p>Here's the code added for this routine:</p>
<div class="syntax_hilite">
<div id="php-34">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// Searches for query in a set of pages, every word</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// is searched independently, and then results of all</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#b0b0ff; font-style:italic;">// search operations are concatenated.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> search<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$query</span>, <span style="color:#0000FF;">$from</span>, <span style="color:#0000FF;">$amount</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#b0b0ff; font-style:italic;">// split query into separate words</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$text</span> = <a href="http://www.php.net/preg_replace"><span style="color:#000066;">preg_replace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"/[^a-zA-Z ]/"</span>, <span style="color:#FF0000;">""</span>, <span style="color:#0000FF;">$query</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$words</span> = <a href="http://www.php.net/preg_split"><span style="color:#000066;">preg_split</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"/ +/"</span>, <span style="color:#0000FF;">$text</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#b0b0ff; font-style:italic;">// for each word in the query</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">foreach</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$words</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$word</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#b0b0ff; font-style:italic;">// get pages containing the word from</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#b0b0ff; font-style:italic;">// the database</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#0000FF;">$pages</span> = <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">dataStore</span>-&gt;<span style="color:#006600;">getPagesWithWord</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$word</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#b0b0ff; font-style:italic;">// for each page</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#616100;">foreach</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$pages</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$id</span> =&gt; <span style="color:#0000FF;">$page</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#b0b0ff; font-style:italic;">// if this page is in the score table</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">pages</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#b0b0ff; font-style:italic;">// add current word occurances on the page</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#b0b0ff; font-style:italic;">// to the score table for given page</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">pages</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"score"</span><span style="color:#006600; font-weight:bold;">&#93;</span> +=</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$page</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"occurances"</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#b0b0ff; font-style:italic;">// if this page is not in the score table</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#616100;">else</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#b0b0ff; font-style:italic;">// add the page to the score table</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#b0b0ff; font-style:italic;">// and store current word occurrences for</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#b0b0ff; font-style:italic;">// this page in the score table</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">pages</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$id</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$page</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#b0b0ff; font-style:italic;">// create container for pages to return</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$webPages</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#b0b0ff; font-style:italic;">// for each page in the score table</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">foreach</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array_keys"><span style="color:#000066;">array_keys</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">pages</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$pageId</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// retrieve page info from database and store in</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#b0b0ff; font-style:italic;">// the container</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$webPages</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">dataStore</span>-&gt;<span style="color:#006600;">getPage</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$pageId</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#b0b0ff; font-style:italic;">// return the container</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$webPages</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The code above is in PHP but the same could be done for any other language, that's the beauty of pseudocode :) . You could give the pseudocode to some other programmer for a review and he doesn't have to know the lang in which it is written.</p>
<p>Some useful notes (once again taken from <a href="http://www.amazon.com/gp/product/0735619670?ie=UTF8&amp;tag=bookreviewbyk-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0735619670">Code Complete, Second Edition</a><img src="http://www.assoc-amazon.com/e/ir?t=coderookie-20&#038;l=as2&#038;o=1&#038;a=0735619670" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />) on how to write the pseudocode:</p>
<ol>
<li>use English-like words to describe the code</li>
<li>do not use syntactic elements of the programming language</li>
<li>the pseudocode should be written at the level of intent ("whats" not "hows")</li>
<li>it should be enough low level to enable developer to write code based on it</li>
</ol>
<p>That's it for this post, give me a hint if you liked the code, or better, try to write some more examples of the pseudocode.</p>
<p><script>reddit_url='http://www.coderookie.com/2006/tutorial/the-pseudocode-programming-process/'</script><br />
<script language="javascript" src="http://reddit.com/button.js?t=3"></script> &nbsp;&nbsp; <script></p>
<p><!--adsense--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.coderookie.com/2006/tutorial/the-pseudocode-programming-process/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 27.084 seconds -->
<!-- Cached page generated by WP-Super-Cache on 2013-05-03 04:28:48 -->
<!-- Compression = gzip -->