<?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>The Log File</title>
	<atom:link href="http://www.thelogfile.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thelogfile.com/blog</link>
	<description>Linux, Software development, Technology news,...</description>
	<lastBuildDate>Fri, 23 Mar 2012 16:11:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>student demonstration Montreal 2012</title>
		<link>http://www.thelogfile.com/blog/2012/03/23/student-demonstration-montreal-2012/</link>
		<comments>http://www.thelogfile.com/blog/2012/03/23/student-demonstration-montreal-2012/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 16:11:22 +0000</pubDate>
		<dc:creator>Pourya Shahroudi</dc:creator>
				<category><![CDATA[Daily]]></category>

		<guid isPermaLink="false">http://www.thelogfile.com/blog/?p=1633</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[
<a href='http://www.thelogfile.com/blog/2012/03/23/student-demonstration-montreal-2012/montreal_stud_demo_2012-2/' title='Montreal_Stud_Demo_2012 (2)'><img width="150" height="150" src="http://www.thelogfile.com/blog/wp-content/uploads/2012/03/Montreal_Stud_Demo_2012-2-150x150.jpg" class="attachment-thumbnail" alt="Montreal_Stud_Demo_2012 (2)" title="Montreal_Stud_Demo_2012 (2)" /></a>
<a href='http://www.thelogfile.com/blog/2012/03/23/student-demonstration-montreal-2012/montreal_stud_demo_2012-1/' title='Montreal_Stud_Demo_2012 (1)'><img width="150" height="150" src="http://www.thelogfile.com/blog/wp-content/uploads/2012/03/Montreal_Stud_Demo_2012-1-150x150.jpg" class="attachment-thumbnail" alt="Montreal_Stud_Demo_2012 (1)" title="Montreal_Stud_Demo_2012 (1)" /></a>

]]></content:encoded>
			<wfw:commentRss>http://www.thelogfile.com/blog/2012/03/23/student-demonstration-montreal-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Limiting the upload speed in rtorrent</title>
		<link>http://www.thelogfile.com/blog/2012/03/15/limiting-the-upload-speed-in-rtorrent/</link>
		<comments>http://www.thelogfile.com/blog/2012/03/15/limiting-the-upload-speed-in-rtorrent/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 20:06:35 +0000</pubDate>
		<dc:creator>Pourya Shahroudi</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.thelogfile.com/blog/?p=1602</guid>
		<description><![CDATA[I have been looking for a way to limit the upload speed on rtorrent(a terminal based torrent client in linux). This is really usefully if you have bandwidth restrictions or low upload/download limits. In Xubuntu, to do that you would need to create the following file: Once you do that you can modify the following [...]]]></description>
			<content:encoded><![CDATA[<p>I have been looking for a way to limit the upload speed on rtorrent(a terminal based torrent client in linux). This is really usefully if you have bandwidth restrictions or low upload/download limits. In Xubuntu, to do that you would need to create the following file:</p>
<pre class="brush: bash; title: ; notranslate">
$vi ~/.rtorrent.rc
</pre>
<p>Once you do that you can modify the following sample config file based on your needs. I have changed it to limit the upload speed to 10KiB:<br />
<span id="more-1602"></span></p>
<pre class="brush: bash; title: ; notranslate">
# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
min_peers = 40
max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
min_peers_seed = -1
max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
max_uploads = 5

# Global upload and download rate in KiB. &quot;0&quot; for unlimited.
download_rate = 0
upload_rate = 10

# Default directory to save the downloaded torrents.
#directory = ./

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
#session = ./session

# Watch a directory for new torrents, and stop those that have been
# deleted.
#schedule = watch_directory,5,5,load_start=./watch/*.torrent
#schedule = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low.
#schedule = low_diskspace,5,60,close_low_diskspace=100M

# Stop torrents when reaching upload ratio in percent,
# when also reaching total upload in bytes, or when
# reaching final upload ratio in percent.
# example: stop at ratio 2.0 with at least 200 MB uploaded, or else ratio 20.0
#schedule = ratio,60,60,&quot;stop_on_ratio=200,200M,2000&quot;

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
#port_range = 6890-6999

# Start opening ports at a random position within the port range.
#port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
#check_hash = no

# Set whetever the client should try to connect to UDP trackers.
#use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to &quot;disable&quot; (completely disable DHT), &quot;off&quot; (do not start DHT),
# &quot;auto&quot; (start and stop DHT as needed), or &quot;on&quot; (start DHT immediately).
# The default is &quot;off&quot;. For DHT to work, a session directory must be defined.
#
# dht = auto

# UDP port to use for DHT.
#
# dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
# peer_exchange = yes

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memor&lt;!--more--&gt;y thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thelogfile.com/blog/2012/03/15/limiting-the-upload-speed-in-rtorrent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress DeepFocus theme &#8216;readmore&#8217; issue</title>
		<link>http://www.thelogfile.com/blog/2012/03/10/wordpress-deepfocus-theme-the-readmore-issue/</link>
		<comments>http://www.thelogfile.com/blog/2012/03/10/wordpress-deepfocus-theme-the-readmore-issue/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 01:44:21 +0000</pubDate>
		<dc:creator>Pourya Shahroudi</dc:creator>
				<category><![CDATA[Daily]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.thelogfile.com/blog/?p=1583</guid>
		<description><![CDATA[I have been thinking about changing my blog’s theme for quite some time. Today I finally did it. I found a really nice theme called DeepFocus and I installed it on my blog. After customizing it I realized a small problem with the read more button. The issue was that it was being displayed on [...]]]></description>
			<content:encoded><![CDATA[<p>I have been thinking about changing my blog’s theme for quite some time. Today I finally did it. I found a really nice theme called <a href="http://www.elegantthemes.com/gallery/deepfocus/" title="DeepFocus">DeepFocus</a> and I installed it on my blog. After customizing it I realized a small problem with the read more button. The issue was that it was being displayed on every single post on the home page even if the post didn’t have more content to be displayed. If you are facing this issue you can fix it by going through the following steps.<br />
First you would have to find the following file:</p>
<pre class="brush: bash; title: ; notranslate">
DeepFocus/includes/entry.php
</pre>
<p>the folder is located under the theme folder in your wordpress directory. Then you would have to add the following if statement around the line that displays the ‘Learn more’ button to make sure that its being displayed only if there is more content in the post.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php if ($pos=strpos($post-&gt;post_content, '&lt;!--more--&gt;')): ?&gt;
                &lt;a class=&quot;readmore&quot; href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;&lt;span&gt;&lt;?php _e('Learn More','DeepFocus'); ?&gt;&lt;/span&gt;&lt;/a&gt;
&lt;?php endif; ?&gt;
</pre>
<p>once you do that it will chack the content of the post for the &#8216;<span id="more-1583"></span>&#8216; tag if it is found it will display the &#8216;Learn more&#8217; link.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelogfile.com/blog/2012/03/10/wordpress-deepfocus-theme-the-readmore-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress for Android</title>
		<link>http://www.thelogfile.com/blog/2012/03/09/wordpress-for-android/</link>
		<comments>http://www.thelogfile.com/blog/2012/03/09/wordpress-for-android/#comments</comments>
		<pubDate>Fri, 09 Mar 2012 20:33:53 +0000</pubDate>
		<dc:creator>Pourya Shahroudi</dc:creator>
				<category><![CDATA[Daily]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.thelogfile.com/blog/?p=1543</guid>
		<description><![CDATA[Testing WordPress for android. I just installed this tool from the android market. Its the official software released by the WordPress. It makes blogging much easier. You can set it up to work on your own domain or with any blog being hosted at WordPress.com. All you need to her started is your blog URL, [...]]]></description>
			<content:encoded><![CDATA[<p>Testing WordPress for android. I just installed this tool from the android market. Its the official software released by the WordPress. It makes blogging much easier. You can set it up to work on your own domain or with any blog being hosted at WordPress.com. All you need to her started is your blog URL, your username and your password.</p>
<p><a href="http://www.youtube.com/watch?v=7RBz_6Cly5s">http://www.youtube.com/watch?v=7RBz_6Cly5s</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelogfile.com/blog/2012/03/09/wordpress-for-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thank you for the support</title>
		<link>http://www.thelogfile.com/blog/2012/03/08/thanks-for-the-comments/</link>
		<comments>http://www.thelogfile.com/blog/2012/03/08/thanks-for-the-comments/#comments</comments>
		<pubDate>Thu, 08 Mar 2012 21:37:26 +0000</pubDate>
		<dc:creator>Pourya Shahroudi</dc:creator>
				<category><![CDATA[Daily]]></category>

		<guid isPermaLink="false">http://www.thelogfile.com/blog/?p=1538</guid>
		<description><![CDATA[Thanks for all your support everyone! Unfortunately I have been really busy lately that is why I couldnt go through all of them I will start adding new posts very soon. Thanks for all your support.]]></description>
			<content:encoded><![CDATA[<p>Thanks for all your support everyone! Unfortunately I have been really busy lately that is why I couldnt go through all of them I will start adding new posts very soon. Thanks for all your support.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelogfile.com/blog/2012/03/08/thanks-for-the-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Secure SQL connection &#8211; SSH Tunnel</title>
		<link>http://www.thelogfile.com/blog/2010/10/06/secure-sql-connection-ssh-tunnel/</link>
		<comments>http://www.thelogfile.com/blog/2010/10/06/secure-sql-connection-ssh-tunnel/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 17:36:12 +0000</pubDate>
		<dc:creator>Pourya Shahroudi</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Software Security]]></category>

		<guid isPermaLink="false">http://www.thelogfile.com/blog/?p=1516</guid>
		<description><![CDATA[Having a central database can be really useful for team projects, developers can develop their local code pointing directly to the same data, this way if the database is refreshed or if the schema is changed they would see the changes instantly. One problem with a central database is having a secure connection to the [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin-right: 10px;" alt="" width="300" align="left" /></p>
<p><a href="http://www.thelogfile.com/blog/wp-content/uploads/2010/10/tunnel_logo.jpg"><img class="alignleft size-medium wp-image-1555" title="3d abstract tunnel" src="http://www.thelogfile.com/blog/wp-content/uploads/2010/10/tunnel_logo-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>Having a central database can be really useful for team projects, developers can develop their local code pointing directly to the same data, this way if the database is refreshed or if the schema is changed they would see the changes instantly.<br />
One problem with a central database is having a secure connection to the clients and the server, specially when the remote database server is hosted outside the local network. To solve the security problem we can use a SSH tunnel between the clients(developer machines) and the remote database server. Another advantage of SSH tunnel is that you don’t need to allow remote access to the database which makes the database access more restricted and secure.<br />
When this is done your local development environment will access the remote database similar to accessing a local database.<br />
<span id="more-1516"></span><br />
To create a secure connection between the clients and the server, you would need to download putty from <strong><a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">here</a></strong>.<br />
To make sure that you have the sql server running on the remote host you could run the following command on the server:</p>
<pre class="brush: bash; title: ; notranslate">
$ mysql -u root -p
</pre>
<p>If the server is running it should ask you to provide a password.</p>
<ul>
<li>The first step is to set the remote hosts IP in putty. If you haven&#8217;t changed the default ssh port on the server then you should keep the port 22.<br />
<img src="http://thelogfile.com/Blog-pics/sshTunnel/1.JPG" alt="" /></li>
<li>Next we would need to setup the tunnel information. Using this information we define a local port <strong>&#8220;2122&#8243;</strong> in which putty listens to, and the remote SQL Server port (3306 by default) which mysql server listens to. Therefore <strong>all requests sent to the local port:2122 are forwarded to the port: 3306 on the Remote MySQL Server</strong><br />
<img src="http://thelogfile.com/Blog-pics/sshTunnel/2.JPG" alt="" /></li>
<li>Click on the add button to add the setting to the session.<br />
<img src="http://thelogfile.com/Blog-pics/sshTunnel/3.JPG" alt="" /></li>
<li>You could go back to the session section to save your session or you could click on <strong>&#8220;open&#8221;</strong> to start the SSH connection. The account information you enter in this window is your SSH username and password.<br />
<img src="http://thelogfile.com/Blog-pics/sshTunnel/4.JPG" alt="" /></li>
<li>Next we check the connection. To do this you could use any tool you prefer I use <strong>&#8220;mysql Query Browse&#8221;</strong>.<br />
<img src="http://thelogfile.com/Blog-pics/sshTunnel/5.JPG" alt="" /></li>
<li>One thing to notice is that the ip is the localhost ip <strong>&#8220;127.0.0.1&#8243;</strong>, same thing for the port <strong>&#8220;2122&#8243;</strong>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.thelogfile.com/blog/2010/10/06/secure-sql-connection-ssh-tunnel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modifying startup services in Ubuntu</title>
		<link>http://www.thelogfile.com/blog/2010/09/17/modifying-startup-services-in-ubuntu/</link>
		<comments>http://www.thelogfile.com/blog/2010/09/17/modifying-startup-services-in-ubuntu/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 18:36:03 +0000</pubDate>
		<dc:creator>Pourya Shahroudi</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.thelogfile.com/blog/?p=1486</guid>
		<description><![CDATA[By default when services like Mysql or Apache are installed in Ubuntu by default they are being set to autostart when the operating system starts. If you are installing the new service on a sever then you would probably want it to start on system boot, but  you may not want to start all of [...]]]></description>
			<content:encoded><![CDATA[<p>By default when services like Mysql or Apache are installed in Ubuntu by default they are being set to autostart when the operating system starts. If you are installing the new service on a sever then you would probably want it to start on system boot, but  you may not want to start all of the services when you start up your machine specially if you are using an old laptop.<br />
The way that the startup services are managed in Debian based operating systems is that during the boot system searches for the start-up scripts in the <strong>/etc/rcX.d </strong>(X is the run level number). Depending on the current run level it looks for service links in <strong>/etc/rcX.d</strong> folders. Every entry in rcX.d points to another script in the <strong>/etc/init.d</strong> which is the script starting up that service.<br />
To disable a start-up service you would have to remove the links in the <strong>/etc/rcX.d</strong> folders pointing to the <strong>/etc/init.d</strong> folder. To do this you have Two options, you can:</p>
<ol>
<li>Either do it the hard way, which is removing the links manually.</li>
<li>Use a tool called update-rc.d that does the job automatically.</li>
</ol>
<p><span id="more-1486"></span><br />
The following are few examples on how to use update-rc.d tool to add and remove start-up services.<br />
By looking at the way that rcX.d folder is structured we can determine the process run-time levels and its priories during startup and shutdown.</p>
<pre class="brush: bash; title: ; notranslate">
ls -l /etc/rc?.d/*apache2
lrwxrwxrwx 1 root root 17 2009-05-19 18:30 /etc/rc0.d/K09apache2 -&gt; ../init.d/apache2
lrwxrwxrwx 1 root root 17 2009-05-19 18:30 /etc/rc1.d/K09apache2 -&gt; ../init.d/apache2
lrwxrwxrwx 1 root root 17 2009-05-19 18:30 /etc/rc2.d/S91apache2 -&gt; ../init.d/apache2
lrwxrwxrwx 1 root root 17 2009-05-19 18:30 /etc/rc3.d/S91apache2 -&gt; ../init.d/apache2
lrwxrwxrwx 1 root root 17 2009-05-19 18:30 /etc/rc4.d/S91apache2 -&gt; ../init.d/apache2
lrwxrwxrwx 1 root root 17 2009-05-19 18:30 /etc/rc5.d/S91apache2 -&gt; ../init.d/apache2
lrwxrwxrwx 1 root root 17 2009-05-19 18:30 /etc/rc6.d/K09apache2 -&gt; ../init.d/apache2
</pre>
<p>As you can see we have apache2 entry in every run-level from 0 to 6. The prefix of every link indicates the priority assigned to this process and whether the priority is to star or kill the process.<br />
For instance: <strong>S91apache2</strong> means that the process <strong>apache2</strong> has priority <strong>91</strong> when its started. Processes with lower priorities are started before a process with higher priority. A Process with higher priority is killed before a process with lower priority number.</p>
<p>To remove apache2 from startup:</p>
<pre class="brush: bash; title: ; notranslate">
$ update-rc.d -f apache2  remove
</pre>
<p>To add apache2 to start-up:</p>
<pre class="brush: bash; title: ; notranslate">
$ update-rc.d apache2 defaults
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K20apache2 -&gt; ../init.d/apache2
/etc/rc1.d/K20apache2 -&gt; ../init.d/apache2
/etc/rc6.d/K20apache2 -&gt; ../init.d/apache2
/etc/rc2.d/S20apache2 -&gt; ../init.d/apache2
/etc/rc3.d/S20apache2 -&gt; ../init.d/apache2
/etc/rc4.d/S20apache2 -&gt; ../init.d/apache2
/etc/rc5.d/S20apache2 -&gt; ../init.d/apache2
</pre>
<p>The default priority set by this command is 20 on the new service. To customize the priorities you would need to provide them when the link is creaeted:</p>
<pre class="brush: bash; title: ; notranslate">
update-rc.d apache2 defaults 18 80
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K80apache2 -&gt; ../init.d/apache2
/etc/rc1.d/K80apache2 -&gt; ../init.d/apache2
/etc/rc6.d/K80apache2 -&gt; ../init.d/apache2
/etc/rc2.d/S20apache2 -&gt; ../init.d/apache2
/etc/rc3.d/S20apache2 -&gt; ../init.d/apache2
/etc/rc4.d/S20apache2 -&gt; ../init.d/apache2
/etc/rc5.d/S20apache2 -&gt; ../init.d/apache2
</pre>
<p>To start a process manually you would have to execute the scripts inside the /etc/init.d manually for instance to start apache2 you would have to do:</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo /etc/init.d/apache2 start
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thelogfile.com/blog/2010/09/17/modifying-startup-services-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Generics</title>
		<link>http://www.thelogfile.com/blog/2010/09/16/java-generics/</link>
		<comments>http://www.thelogfile.com/blog/2010/09/16/java-generics/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 01:22:56 +0000</pubDate>
		<dc:creator>Pourya Shahroudi</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.thelogfile.com/blog/?p=1443</guid>
		<description><![CDATA[Generics were added to Java in J2SE5.0. They allow &#8220;a type or method to operate on objects of various types while providing compile-time type safety.&#8221; The initial Idea behind Java generics was to reduce run-time type casting exceptions. The following is an example of how Generics were added to the ArrayList class to avoid such [...]]]></description>
			<content:encoded><![CDATA[<p>Generics were added to Java in J2SE5.0. They allow &#8220;a type or method to operate on objects of various types while providing compile-time type safety.&#8221;<br />
The initial Idea behind Java generics was to reduce run-time <b>type casting exceptions</b>. The following is an example of how Generics were added to the ArrayList class to avoid such exceptions.</p>
<pre class="brush: java; title: ; notranslate">
List v = new ArrayList();
v.add(&quot;test&quot;);
Integer i = (Integer)v.get(0);        // Run time error
</pre>
<p>The Class Cast Exception is thrown when this block of code is accessed during the run-time. As you can see the code declares an ArrayList, String &#8220;test&#8221; is added to the arrayList, but since the type of objects stored in the ArrayList is not declared the compiler doesn&#8217;t see any problem with it. That is why the run-time exception is thrown when the retrieved object from the list is being cast to an Integer.<br />
To avoid such such run-time exceptions Generics were added to the arrayList class. Using Generics when developers declare an ArrayList they have the option of declaring the type of objects being stored in the list.<br />
Using Java Generics the above code would become:</p>
<pre class="brush: java; title: ; notranslate">
List&lt;String&gt; v = new ArrayList&lt;String&gt;();
v.add(&quot;test&quot;);
Integer i = v.get(0); // (type error)  Compile time error
</pre>
<p>As you can see in the second example since we are clearly defining the type of objects inside the array list the compiler can detect the casting exception in the code when the code is being compiled. There are many other benefits in using generics, it simplify the code, it makes it easier to read and to understand.<br />
Today Generics are being used widely by Java developers, you may have been using them without noticing them.<br />
<span id="more-1443"></span><br />
<b>Using Generics to change object types passed to methods on run-time:</b><br />
Normally when you declare an object you would need to explicitly define its type, using Generics object type can be changed on run-time. That is exactly what the ArrayList class does in the previous example. The following is a simple example showing how you can use Java Generics in your defined classes to change object types on run-time:</p>
<pre class="brush: java; title: ; notranslate">
package tutorials.generics;

public class Container&lt;T&gt; {
	private T id;

	public Container() {

	}

	public T getId() {
		return id;
	}

	public void setId(T id) {
		this.id = id;
	}

	@Override
	public String toString() {
		return &quot;Containers Value is: &quot;+ id.toString();
	}

	public static void main(String[] args) {
		Container&lt;String&gt; mString = new Container&lt;String&gt;();
		mString.setId(&quot;Some String&quot;);
		System.out.println(mString);

		Container&lt;Integer&gt; mInteger = new Container&lt;Integer&gt;();
		mInteger.setId(2);
		System.out.println(mInteger);
	}
}
</pre>
<p>The class <b>Container</b> uses a Generic type T to define its private variable called <b>id</b>. As you can see this variable has different type depending on the object being passed to the setter method. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelogfile.com/blog/2010/09/16/java-generics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Internet Explorer 9</title>
		<link>http://www.thelogfile.com/blog/2010/09/15/internet-explorer-9/</link>
		<comments>http://www.thelogfile.com/blog/2010/09/15/internet-explorer-9/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 23:49:21 +0000</pubDate>
		<dc:creator>Pourya Shahroudi</dc:creator>
				<category><![CDATA[Daily]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://www.thelogfile.com/blog/?p=1438</guid>
		<description><![CDATA[IE9 test driver is out! I was so excited to read this new today. This is a great news for IE users, because it should provide a better security and speed comparing to previous versions of IE and because it does have more features and a better looking interface. I believe that the people who [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://thelogfile.com/Blog-pics/ie9.jpg"><br />
<a href="http://ie.microsoft.com/testdrive/">IE9 test driver</a> is out! I was so excited to read this new today. This is a great news for IE users, because it should provide a better security and speed comparing to previous versions of IE and because it does have more features and a better looking interface.</p>
<p>I believe that the people who would benefit from this most of all are developers like me! This should force more users to upgrade and hopefully get rid of damn IE6 once and for all! This would eventually mean less hacks on the front-end trying to make the pages in IE6 look like Google Chrome and Firefox.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelogfile.com/blog/2010/09/15/internet-explorer-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xubuntu &#8211; Time Synchronization</title>
		<link>http://www.thelogfile.com/blog/2010/08/21/xubuntu-time-synchronization/</link>
		<comments>http://www.thelogfile.com/blog/2010/08/21/xubuntu-time-synchronization/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 08:15:55 +0000</pubDate>
		<dc:creator>Pourya Shahroudi</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Xubuntu]]></category>

		<guid isPermaLink="false">http://kohantech.com/blog/?p=1431</guid>
		<description><![CDATA[In xubuntu (XFCE) you can run the following command to synchronize your system clock with time servers: After running this command you would get a response similar to the following:]]></description>
			<content:encoded><![CDATA[<p>In xubuntu (XFCE) you can run the following command to synchronize your system clock with time servers:</p>
<pre class="brush: bash; title: ; notranslate">
sudo ntpdate pool.ntp.org
</pre>
<p>After running this command you would get a response similar to the following:</p>
<pre class="brush: bash; title: ; notranslate">
21 Aug 04:08:20 ntpdate[4824]: adjust time server 209.167.68.100 offset 0.017300 sec
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thelogfile.com/blog/2010/08/21/xubuntu-time-synchronization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

