<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5313762687362102870</id><updated>2011-12-24T21:10:03.874-08:00</updated><category term='SNMP'/><category term='snmp tool'/><category term='Twitter'/><category term='network sniffer'/><category term='OOP explanation'/><category term='Download'/><category term='Connect'/><category term='Regular Expressions'/><category term='java Twitter'/><category term='file download'/><category term='FolderBrowseDialog'/><category term='Send email'/><category term='java runtime'/><category term='Browse Folder'/><category term='sort array'/><category term='validator'/><category term='build snmp tool'/><category term='J2ME mail'/><category term='splitting csv'/><category term='WebClient'/><category term='tribute Janaka Perera'/><category term='File'/><category term='Formatter'/><category term='favicon'/><category term='sql array'/><category term='java snmp'/><category term='Encrypt image'/><category term='network traffic analyzer'/><category term='browser icon'/><category term='Build your own Network sniffer'/><category term='sort'/><category term='C Sharp'/><category term='flush method'/><category term='MySQL'/><category term='run application from java'/><category term='run executable java programme'/><category term='arrays'/><category term='Janaka Perera'/><category term='IO'/><category term='Mobile E-Mail'/><category term='Java Encryption'/><category term='URL'/><category term='Encrypt picture'/><category term='ASP'/><category term='System.out.println'/><category term='My Server'/><category term='addressbar icon'/><category term='new line'/><category term='Java'/><category term='NetBeans'/><category term='sql server'/><category term='C#'/><category term='Twitter API'/><category term='Regex'/><category term='Browser'/><category term='Protocol'/><category term='System.out.println()'/><category term='Java Buffered Writer issues'/><category term='OTR'/><category term='sniffer'/><category term='icon'/><category term='snmp monitor tool'/><category term='Connect MySQL NetBeans'/><category term='Chat Application'/><category term='Date Format'/><category term='comparable'/><category term='DOT NET'/><category term='writing output to file'/><category term='build network monitoring tool'/><category term='custom sort'/><category term='url validator'/><category term='.NET'/><category term='Off The Record'/><title type='text'>Ruchira's Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>29</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-8621837488174086483</id><published>2009-12-24T01:19:00.000-08:00</published><updated>2009-12-25T01:05:20.528-08:00</updated><title type='text'>Send Gmail using Dot NET</title><content type='html'>Hi, in my previous posts, I have posted how to send mail using the Java API. In this section, I would like to demonstrate on how to send mail using Dot NET.&lt;br /&gt;Using Dot NET, it is equally easy to send mail. In this post I would use my Dot NET application to connect with Google's outgoing mail server (Google's SMTP server) and use that to forward my mail. (In my previous post, I've demonstrated on sending mail using my own SMTP server which ran on my machine. In this scenario, it will directly put the outgoing message into the Gmail's SMTP server)&lt;br /&gt;&lt;br /&gt;You will  be using mainly few Classes to get the job done.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;System.Net.Mail.MailMessage&lt;/span&gt; &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;System.Net.NetworkCredential&lt;/span&gt; &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;System.Net.Security.SmtpClient&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;These classes will provide the basic methods to get the job done.&lt;br /&gt;You will also be using &lt;span style="color: rgb(51, 51, 255);"&gt;System.Net.Mail.MailAddress&lt;/span&gt; class. (Though there is a way to get the job done without actually needing this.)&lt;br /&gt;&lt;br /&gt;First of all, you need to import the namespaces.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using System.Net.Mail;&lt;/span&gt; &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;using System.Net;&lt;/span&gt; &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;using System.Net.Security;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, create a &lt;span style="color: rgb(51, 51, 255);"&gt;MailMessage &lt;span style="color: rgb(0, 0, 0);"&gt;object using the following LOC.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;MailMessage mail = new MailMessage();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, lets set the sender's address and receiver's address. We create a MailAddress object and set the value directly from its constructor.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;mail.From = new MailAddress("from&lt;your gmail="" username=""&gt;@gmail.com","&lt;alias name=""&gt;Any name to appear as alias");&lt;br /&gt;&lt;br /&gt;&lt;/alias&gt;&lt;/your&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Now set the receiver.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;mail.To.Add(new MailAddress("&lt;receiver's username=""&gt;toaddress&lt;anydomain&gt;", "&lt;/anydomain&gt;&lt;/receiver's&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Any name to appear as alias&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;receiver's username=""&gt;&lt;anydomain&gt;"));&lt;/anydomain&gt;&lt;/receiver's&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;NOTE&lt;/span&gt;: You cannot simply set the To Address in a similar way as setting from address. ie: You cannot set &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;mail.To=new MailAddress("&lt;receiver's username=""&gt;yourffiend&lt;anydomain&gt;", "Alias name");&lt;br /&gt;&lt;/anydomain&gt;&lt;/receiver's&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;This is because, you can send a mail to multiple people at once. Hence, the To property of a mail object contains a collection of &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;MailAddress&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; objects&lt;/span&gt;&lt;/span&gt;. You can add a new mail address to the collection in the above manner.&lt;br /&gt;&lt;br /&gt;Now create an &lt;span style="color: rgb(51, 51, 255);"&gt;SmtpClient &lt;/span&gt;object. This can be done using.&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;SmtpClient smtp = new SmtpClient();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Next, we will set the host address of the smtp server.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;smtp.Host = "smtp.gmail.com";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(51, 0, 51);"&gt;And the port.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;smtp.Port = 587;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(51, 0, 51);"&gt;NOTE: If you are using your own SMTP mail server, then the port would be port 25.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(51, 0, 51);"&gt;We will use our own credentials. Thus disable the default credentials.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;smtp.UseDefaultCredentials = false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(51, 0, 51);"&gt;&lt;br /&gt;We&lt;/span&gt;&lt;/span&gt; must enable SSL.&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;smtp.EnableSsl = true;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(51, 0, 51);"&gt;Now we will create our own credentials using the following LOC.&lt;br /&gt;First create a NetworkCredential object.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;NetworkCredential cred = new NetworkCredential();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And now set the required usename and password.&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;cred.UserName = "username";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;cred.Password="password";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;br /&gt;And now , set the credentials of the smtp object to the credentials we created.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt; smtp.Credentials = cred;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, you can send the main using the follwing LOC.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;smtp.Send(mail);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I have taught you the basic procedure, now you can extend it to get the job done your way. Have fun Folks !!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-8621837488174086483?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/8621837488174086483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=8621837488174086483' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/8621837488174086483'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/8621837488174086483'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/12/send-gmail-using-dot-net.html' title='Send Gmail using Dot NET'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-8149052767931163362</id><published>2009-12-09T02:34:00.000-08:00</published><updated>2009-12-09T02:44:44.721-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DOT NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Download'/><category scheme='http://www.blogger.com/atom/ns#' term='WebClient'/><category scheme='http://www.blogger.com/atom/ns#' term='file download'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>Download File using Dot Net</title><content type='html'>In this post, I will demonstrate how easy it is to download a file from a web server to your local hard drive. In most scenarios, you may browse the net using your web browser and click on a hyperlink to start a downloading of a file from a remote site.&lt;br /&gt;Some of you may be interested in how to download this using their application code using Dot Net.&lt;br /&gt;This can be very easily achieved using the &lt;span style="color: rgb(51, 102, 255);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;WebClient&lt;/span&gt; &lt;/span&gt;class under &lt;span style="color: rgb(51, 51, 255);"&gt;System.Net&lt;/span&gt; namespace.&lt;br /&gt;&lt;br /&gt;First, import the System.Net namespace.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using System.IO;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The above LOC will do so.&lt;br /&gt;&lt;br /&gt;Now, create an instance of WebCleient class.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;WebClient client = new WebClient();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, call the DownloadFile method&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;client.DownloadFile(&amp;lt;url&amp;gt;, @"&amp;lt;fileDestinationName&amp;gt;.&amp;lt;filetype&amp;gt;");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Have fun. Cheers !!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-8149052767931163362?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/8149052767931163362/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=8149052767931163362' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/8149052767931163362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/8149052767931163362'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/12/download-file-using-dot-net.html' title='Download File using Dot Net'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-8002826962813941935</id><published>2009-11-20T04:04:00.000-08:00</published><updated>2009-11-20T04:11:42.685-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DOT NET'/><category scheme='http://www.blogger.com/atom/ns#' term='new line'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C Sharp'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>ASP Response.Write newline</title><content type='html'>Hi, all of you who have used ASP may have encountered situations where you require to write a text output to the screen. It can be easily done by using&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Response.Write("Hello world");&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;However, if you wish to append some more text to a newline, it would not work in the following ways.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Response.Write("Hello world \n");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Response.Write("Good day.");&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;The output of the above lines would be &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Hello world Good day.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;and NOT &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Hello world&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Good day.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;In order to overcome this, you can very simple place an html break tag inside the code.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Response.Write("Hello world");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Response.Write("&amp;lt;br/&amp;gt;");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Response.Write("Good day.");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The output would be the following.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Hello world&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Good day.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Cheers !!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-8002826962813941935?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/8002826962813941935/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=8002826962813941935' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/8002826962813941935'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/8002826962813941935'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/11/asp-responsewrite-newline.html' title='ASP Response.Write newline'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-7182733442286690733</id><published>2009-11-18T10:49:00.000-08:00</published><updated>2009-11-18T11:44:24.160-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='favicon'/><category scheme='http://www.blogger.com/atom/ns#' term='browser icon'/><category scheme='http://www.blogger.com/atom/ns#' term='addressbar icon'/><category scheme='http://www.blogger.com/atom/ns#' term='icon'/><category scheme='http://www.blogger.com/atom/ns#' term='Browser'/><title type='text'>Browser addressbar icon (favicon)</title><content type='html'>Hi, all of you must have noticed that when you visit a website with your browser, the image on the left of the addressbar changes. First of all lets define its correct term. It is known as the 'favIcon'.&lt;br /&gt;&lt;br /&gt;In this post, I wish to demonstrate how to add such a favicon to your website. To try this out, you would need a web server such as IIS, Apache or Tomcat. I'm using WAMP's Apache server for the demonstration.&lt;br /&gt;&lt;br /&gt;First of all, you'll need an image of dimension 16x16. You can use windows paint to do this. Save it in Windows 16 colors. If you need to do this quickly, you can use the following &lt;a href="http://www.html-kit.com/favicon/"&gt;website&lt;/a&gt;, which will generate a favicon from a given image.&lt;br /&gt; Save the image as favicon.ico. Now, copy and paste this on your web server root directory of the application.&lt;br /&gt;&lt;br /&gt;The folder structure of WAMP is based in a way such that the web applications need to be deployed in the folder named "www". (The complete path for this is "C:\wamp\www") Now, create a separate folder for your application inside the root folder.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_NACWt_PFgLM/SwRMQT9Qy2I/AAAAAAAAAGI/-lHAqNbVRXE/s1600/2.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_NACWt_PFgLM/SwRMQT9Qy2I/AAAAAAAAAGI/-lHAqNbVRXE/s320/2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5405529295870282594" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For the demonstration, I will use a simple web site with just one web page. It would display the simple Hello World message. Just copy the following code segment into a text editor and save it as "index.html". Now, place this html code in your web server's application root folder.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    &amp;lt;head&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;   &lt;span style="color: rgb(255, 0, 0);"&gt;      &amp;lt;link rel="shortcut icon" href="favicon.ico"&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;     &amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    &amp;lt;body&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;         &amp;lt;table&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;              &amp;lt;tr&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                   &amp;lt;td&amp;gt;Hello World!&amp;lt;/td&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;              &amp;lt;/tr&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;         &amp;lt;/table&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    &amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, make sure that you place the code in red in the header. It is needed if you need to change the image location other than the root folder. So, if you need to save the image in a folder named images, then you could simply locate the file using the path to the directory.&lt;br /&gt;&lt;br /&gt;Now, the folder structure should be similar to the following.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_NACWt_PFgLM/SwRM9VzJ2FI/AAAAAAAAAGQ/KjRo2Hk2ZZ4/s1600/1.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_NACWt_PFgLM/SwRM9VzJ2FI/AAAAAAAAAGQ/KjRo2Hk2ZZ4/s320/1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5405530069458868306" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now, start your web server. In my case, I would start WAMP's Apache service. Then view it through a browser. When you view it, it should be automatically displayed on the left of the addressbar. &lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_NACWt_PFgLM/SwROS2DNsEI/AAAAAAAAAGY/fYvgyDZeGSM/s1600/3.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 208px;" src="http://3.bp.blogspot.com/_NACWt_PFgLM/SwROS2DNsEI/AAAAAAAAAGY/fYvgyDZeGSM/s320/3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5405531538405044290" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;NOTE: You may sometimes need to clear the browser cash for the image to be displayed and restart the Web Server. &lt;br /&gt;&lt;br /&gt;Cheers&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-7182733442286690733?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/7182733442286690733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=7182733442286690733' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/7182733442286690733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/7182733442286690733'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/11/browser-addressbar-icon-favicon.html' title='Browser addressbar icon (favicon)'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_NACWt_PFgLM/SwRMQT9Qy2I/AAAAAAAAAGI/-lHAqNbVRXE/s72-c/2.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-1127020263905958059</id><published>2009-10-29T23:58:00.000-07:00</published><updated>2009-10-30T00:12:56.321-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='validator'/><category scheme='http://www.blogger.com/atom/ns#' term='DOT NET'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP'/><category scheme='http://www.blogger.com/atom/ns#' term='Regular Expressions'/><category scheme='http://www.blogger.com/atom/ns#' term='Regex'/><title type='text'>ASP Regular expression to check length of textbox value</title><content type='html'>Hi, here is a regular expression validator in ASP which you can use to check if a certain textbox has less than a certain number of characters.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&amp;lt;asp:regularexpressionvalidator runat="server" id="lengthRegex" controltovalidate=""&amp;gt;" validationexpression=".{1,&amp;lt;n&amp;gt;}" errormessage="Please note that there should be less than &amp;lt;n&amp;gt; number of characters in the textbox"&amp;gt; &amp;lt;/asp:regularexpressionvalidator&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So, if you intend to make the textbox accept a number of characters in a range(say between 5 to 10) then the following changes would work&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&amp;lt;asp:regularexpressionvalidator runat="server" id="lengthRegex" controltovalidate=""&amp;gt;" validationexpression=".{5,10}" errormessage="Please note that there should be between 5 to 10 characters in the textbox"&amp;lt;/asp:regularexpressionvalidator&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Suppose you need to limit the characters to only alphanumerics, then use the following regular expression for the validator.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;"[A-Za-z0-9]{5,10}"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, suppose you only wish to have a certain number of special characters only. Say you need to accept the space( ) period(.) , comma(,) and dash(-) only with the alphanumerics. Then use the following regex.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;"[A-Za-z0-9.-,\s]{5,10}"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can modify the above code for your custom needs.&lt;br /&gt;Have fun.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-1127020263905958059?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/1127020263905958059/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=1127020263905958059' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1127020263905958059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1127020263905958059'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/10/asp-regular-expression-to-check-length.html' title='ASP Regular expression to check length of textbox value'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-1147715358100012276</id><published>2009-10-20T02:26:00.000-07:00</published><updated>2009-10-20T02:29:26.693-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Regular Expressions'/><category scheme='http://www.blogger.com/atom/ns#' term='Regex'/><category scheme='http://www.blogger.com/atom/ns#' term='url validator'/><category scheme='http://www.blogger.com/atom/ns#' term='URL'/><title type='text'>URL Regular Expression</title><content type='html'>Here is a good Regular Expression for evaluating a URL&lt;br /&gt;&lt;br /&gt;(http(s)?\:\/\/)?([\w_-]{2,}\.)+([\w_-]{2,})((\/)(\~)[\w_-]+)?((\/)[\w_-]+)*((\/)¦(\/)[\w_-]+\.[\w]{2,})?((\?[\w_-]+\=([^\#]+)){0,1}(\&amp;[\w_-]+\=([^\#]+))*)?(#[\w_-]+)?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-1147715358100012276?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/1147715358100012276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=1147715358100012276' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1147715358100012276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1147715358100012276'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/10/url-regular-expression.html' title='URL Regular Expression'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-6113566198001582847</id><published>2009-10-18T05:13:00.000-07:00</published><updated>2009-10-18T05:32:53.955-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='comparable'/><category scheme='http://www.blogger.com/atom/ns#' term='custom sort'/><category scheme='http://www.blogger.com/atom/ns#' term='sort array'/><category scheme='http://www.blogger.com/atom/ns#' term='sort'/><title type='text'>Java Sorting Arrays</title><content type='html'>Hi,&lt;br /&gt;&lt;br /&gt;All you Java folks must have faced a situation where you require to sort an array of custom objects using Java. Sorting a string array is easy with Java. But, what happens when you have a custom object array, say an array od Person objects to sort. You need to sort them according to a specific custom condition. With java interfaces, this becomes easily doable.&lt;br /&gt;&lt;br /&gt;In this example I will use the custom object as 'Car' &lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public class Car&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;int age;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;string id;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;string color;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I need to sort them according to the age. Thus, according to the ascending order.&lt;br /&gt;&lt;br /&gt;First, you need to implemet Comparable interface of java.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public class Car&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;implements Comparable&lt;car&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;int age;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;string id;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;string color;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So, add the above code in Red. This tells that this class implements the Comparable interface and accepts Car objects only.&lt;br /&gt;&lt;br /&gt;Now, you need to actually implement the methods regarding the interface.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;public int compareTo(Car o)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You must implement the above method signature and write the relevant code/ logic associated with it.&lt;br /&gt;&lt;br /&gt;Note that this method returns an integer. The values which we will use are in the set of {-1,1,0} . So, when we want to sort an array of cars, the JVM will decide on which should be first by looking at the return value. If it is -1, it implies that the second value is larger, if the value returned is 0, it implies both should have the same value.&lt;br /&gt;Since we want to sort them according to the age, we will write the following LOC.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;public int compareTo(Car o) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        if (this.age&lt;o.age)&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            return -1;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        else if(o.age==this.age){&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            return 0;                  &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        else{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            return 1;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        }                   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    } &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, we have done the necessary work to sort. Lets give it a try by using a demo.&lt;br /&gt;&lt;br /&gt;First create an array of Car objects and put them in a randomn order.&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(51, 102, 255);"&gt;Car[] carArray= new Car[5];&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        Car c1 = new Car();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        Car c2 = new Car();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        Car c3 = new Car();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        Car c4 = new Car();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        Car c5 = new Car();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c1.setAge(1);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c1.setColor("blue");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c1.setId("");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c2.setAge(2);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c2.setColor("black");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c2.setId("");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c3.setAge(3);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c3.setColor("red");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c3.setId("");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c4.setAge(4);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c4.setColor("green");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c4.setId("");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c5.setAge(5);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c5.setColor("purple");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        c5.setId("");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        carArray[0]= c4;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        carArray[1]= c1;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        carArray[2]= c3;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        carArray[3]= c5;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        carArray[4]= c2;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        System.out.println("----------------------------------------------------");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        System.out.println("----------------------------------------------------");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        System.out.println("Before Sorting");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        System.out.println("");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As we observe, the Car objects are not in the correct order. They are in the order of [C4, C1, C3, C5, C2]&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;NOTE: After the sort, they should be in the order of [C1,C2,C3,C4,C5]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, lets print the array to see how they are before we order.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;print(carArray);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, lets call the sort.&lt;br /&gt;&lt;br /&gt;We can call a sort using the Arrays.sort(); method. It belongs to the class Arrays declared in java.utils package. This class has a static method sort, which accepts an array of objects which must implement the comparable interface.&lt;br /&gt;(Since our Car class implemented the interface, we can pass an array of Car objects to this method)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;Arrays.sort(carArray);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, lets try to print this and see what we get.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;print(carArray);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Presto !!!!!! We get an array which is according to the correct order as we required. Thus, by using the Comparable interface in java, we can write almost any custom ordering rule for our classes.&lt;br /&gt;Hope you enjoyed this !!!!!!&lt;br /&gt;Happy coding !!!!&lt;br /&gt;&lt;br /&gt;:)&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-6113566198001582847?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/6113566198001582847/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=6113566198001582847' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/6113566198001582847'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/6113566198001582847'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/10/java-sorting-arrays.html' title='Java Sorting Arrays'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-7589943448511303476</id><published>2009-09-04T02:35:00.000-07:00</published><updated>2009-09-04T21:33:26.250-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java Twitter'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Twitter'/><category scheme='http://www.blogger.com/atom/ns#' term='Twitter API'/><title type='text'>Twitter API with Java</title><content type='html'>Hi, Since Twitter is one of the most widely used ways to share your status with others, I will use this post to display how to use Java to access the Twitter API.&lt;br /&gt;&lt;br /&gt;I used a Java library named "jtwitter" which can be freely downloaded from&lt;br /&gt;"http://www.winterwell.com/software/jtwitter/jtwitter.jar"&lt;br /&gt;&lt;br /&gt;Once you download the jar file, add it to your project. Then, it becomes very simple to use the API.&lt;br /&gt;&lt;br /&gt;First build a new Twitter object&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Twitter twitter = new Twitter("&amp;lt;username&amp;gt;","&amp;lt;password&amp;gt;");&lt;/password&gt;&lt;/username&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Then set your status to whatever you want&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;twitter.setStatus("Twittering");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To get a list of your friends, simply use the following LOC&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;List&lt;twitter.user&gt; followers = twitter.getFriends();&lt;/twitter.user&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you need to get the user's image, you can do it in the following manner.&lt;br /&gt;1. Get the URL of the image using Twitter API&lt;br /&gt;2. Use Java Classes to download the image and display it&lt;br /&gt;&lt;br /&gt;NOTE: The user variable is of type '&lt;span style="color: rgb(51, 51, 255);"&gt;Twitter.User&lt;/span&gt;'&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;URL imgURL = user.getProfileImageUrl().toURL();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Using Java methods, you can download the image.&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;BufferedImage img = ImageIO.read(imgURL);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, you can set it to the iconImage property of a label.&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;label.setIcon(new ImageIcon(img));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;See, it's that simple.&lt;br /&gt;&lt;br /&gt;Have fun !!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-7589943448511303476?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/7589943448511303476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=7589943448511303476' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/7589943448511303476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/7589943448511303476'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/09/twitter-api-with-java.html' title='Twitter API with Java'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-2214485774386059430</id><published>2009-08-18T23:56:00.000-07:00</published><updated>2009-08-19T00:10:43.067-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DOT NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C Sharp'/><category scheme='http://www.blogger.com/atom/ns#' term='Regular Expressions'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Regex'/><title type='text'>Dot NET Regular Expression</title><content type='html'>Hi, in this post, I will demonstrate how to use a Regular Expression using the Dot NET Framework. If you are new to Regular Expressions, this post would not be of much use. This is intended for an audience who knows regular expressions and need to implement a regular expression in their Dot NET code.&lt;br /&gt;There may be scenarios where you need to match a certain string with a Regular Expression. Using the Dot NET Framework, this becomes relatively easy.&lt;br /&gt;&lt;br /&gt;First, you need to import the namespace by defining&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using System.Text.RegularExpressions;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Then, you can create a &lt;span style="color: rgb(51, 51, 255);"&gt;Regex &lt;/span&gt;object by calling its constructor. This is an overloaded constructor. I will show only one use of it. (You can explore the other!!!)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Regex regularExpression = new Regex("&lt;your&gt;");&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;This would create a Regex object. &lt;span style="color: rgb(0, 0, 0);"&gt;Once created, you can call several methods to get the job done.&lt;br /&gt;I will show how the &lt;span style="color: rgb(204, 102, 204);"&gt;Replace&lt;/span&gt; method can be used to identify a character pattern and replace it with a character set of your own. (A good example is when you want to replace offensive words entered by a user with asterisks in a social networking site)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Regex regularExpression = new Regex("ruchira[a-z]*");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;string filteredWords = regularExpression.Replace("ruchira", "*");&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;After performing the above, the result would be a single asterix. ie: "ruchira" would be replaced by "*"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;I believe this is a good point to start with Regular Expressions, you can continue exploring its other functionalities.&lt;br /&gt;&lt;br /&gt;Cheers !!!!!!!!&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-2214485774386059430?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/2214485774386059430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=2214485774386059430' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/2214485774386059430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/2214485774386059430'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/08/dot-net-regular-expression.html' title='Dot NET Regular Expression'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-952200770581747189</id><published>2009-08-10T00:33:00.000-07:00</published><updated>2009-08-10T00:52:54.597-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DOT NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Date Format'/><category scheme='http://www.blogger.com/atom/ns#' term='Formatter'/><title type='text'>Dot Net Date Formatting</title><content type='html'>Hi, all of you people may have encountered situation where you wish to format your date for a specific format. This becomes very simple with Dot NET Framework.&lt;br /&gt;&lt;br /&gt;Suppose you have a date to be displayed. Let the date be 1st January 2009&lt;br /&gt;Now, this can be displayed in various formats. The respective date-format-string is displayed alongside Eg:&lt;br /&gt;&lt;br /&gt;Displaying these can be done using the following LOC.&lt;br /&gt;&lt;br /&gt;DateTime today=DateTime.Now;&lt;br /&gt;string formattedDate=today.ToString(&lt;your-date-format-string&gt;);&lt;br /&gt;&lt;br /&gt;Eg:&lt;br /&gt;string formattedDate=today.ToString("dd-MM-yyyy");&lt;br /&gt;=&gt;01-Jan-2009&lt;br /&gt;&lt;br /&gt;string formattedDate=today.ToString("dd/MM/yyyy");&lt;br /&gt;=&gt;01-Jan/2009&lt;br /&gt;&lt;br /&gt;string formattedDate=today.ToString("d-MMM-yy");&lt;br /&gt;=&gt;1-January-2009&lt;br /&gt;&lt;br /&gt;Try out other combinations of your own and experience the power!!!!!!!&lt;/your-date-format-string&gt;&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;b&gt;Format&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Respective date-format-string&lt;/b&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;01/01/09&lt;/td&gt;&lt;td&gt;'dd/MM/yy'&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;01 Jan 09&lt;/td&gt;&lt;td&gt;'dd MM yy'&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;01 Jan 2009&lt;/td&gt;&lt;td&gt;'dd MM yyyy'&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;1 January 2009&lt;/td&gt;&lt;td&gt;'d MMM yyyy'&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-952200770581747189?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/952200770581747189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=952200770581747189' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/952200770581747189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/952200770581747189'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/08/dot-net-date-formatting.html' title='Dot Net Date Formatting'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-2805691998089919761</id><published>2009-07-27T23:11:00.000-07:00</published><updated>2009-07-27T23:13:45.620-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DOT NET'/><category scheme='http://www.blogger.com/atom/ns#' term='writing output to file'/><category scheme='http://www.blogger.com/atom/ns#' term='IO'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>Dot Net Writing to a File</title><content type='html'>A very simple LOC which may become very useful.&lt;br /&gt;&lt;br /&gt; File.WriteAllText("C:\\a.txt","Hello World");&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-2805691998089919761?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/2805691998089919761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=2805691998089919761' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/2805691998089919761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/2805691998089919761'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/07/dot-net-writing-to-file.html' title='Dot Net Writing to a File'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-4818812124788727478</id><published>2009-05-23T01:14:00.000-07:00</published><updated>2009-08-24T23:25:20.799-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OOP explanation'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='System.out.println()'/><category scheme='http://www.blogger.com/atom/ns#' term='System.out.println'/><title type='text'>Java System.out.println() explained in OOP</title><content type='html'>Hi, all Java programmers must have used the "&lt;span style="color: rgb(51, 51, 255);"&gt;System.out.println()&lt;/span&gt;" method many times during their programming careers. It is used even in the HelloWorld Java code.&lt;br /&gt;The most interesting part of it is that how it complies with the OOP (Object Oriented Programming) concepts. Many of us have used it, and are using it over and over again without any consideration on how this fits on with the OOP concepts. In this post I expect to give my clarification on how it is implemented.&lt;br /&gt;&lt;br /&gt;Obviously "&lt;span style="color: rgb(51, 51, 255);"&gt;System&lt;/span&gt;" is a public class. And at first, it seems as if we were accessing a static method of the "&lt;span style="color: rgb(51, 51, 255);"&gt;System&lt;/span&gt;" class by calling &lt;span style="color: rgb(51, 51, 255);"&gt;System.out&lt;/span&gt;.  But, if it was a method, we would basically call  a method in the following manner.&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;System.out();&lt;/span&gt; where we would be using parenthesis, and we do not use it in this case.&lt;br /&gt;Hence the concept regarding a static method call of a "&lt;span style="color: rgb(51, 51, 255);"&gt;System&lt;/span&gt;" class fails.&lt;br /&gt;&lt;br /&gt;We can access class variables by calling  &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;classname&gt;.&lt;public&gt;&lt;/public&gt;&lt;/classname&gt;&lt;/span&gt; . Given that the class variables are declared static. Consider the following example which further explains this.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public Class Car{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public static String CAR_MODEL;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;/*Methods of class car*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In this scenario, we can safely access the static variable from an outside class by simply calling&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Car.CAR_MODEL&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is the case we use in &lt;span style="color: rgb(51, 51, 255);"&gt;System.out&lt;/span&gt; part.  We are actually using a public static variable by the name "&lt;span style="color: rgb(51, 51, 255);"&gt;out&lt;/span&gt;" declared in the System class.&lt;br /&gt;&lt;br /&gt;So, &lt;span style="color: rgb(51, 51, 255);"&gt;System &lt;/span&gt;class must be of the form;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public class System{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public static &lt;classnameoftheobject&gt; &lt;class&gt; &lt;classname&gt; out;&lt;/class&gt;&lt;/classnameoftheobject&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/*The methods of System class*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We do not know the exact type of the object "&lt;span style="color: rgb(51, 51, 255);"&gt;out&lt;/span&gt;". In other words, we do not know whether out is a &lt;span style="color: rgb(51, 51, 255);"&gt;String&lt;/span&gt;, an &lt;span style="color: rgb(51, 51, 255);"&gt;ArrayList &lt;/span&gt;or simply an &lt;span style="color: rgb(51, 51, 255);"&gt;Integer&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;It may be of the form.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public class System{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public static &lt;classnameoftheobject&gt;&lt;class&gt;String out;&lt;/class&gt;&lt;/classnameoftheobject&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/*The methods of System class*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;We cannot tell for sure.&lt;br /&gt;&lt;br /&gt;So, now we are clear with what &lt;span style="color: rgb(51, 51, 255);"&gt;System.out&lt;/span&gt; means. The other part becomes quite obvious. We would be calling the method &lt;span style="color: rgb(51, 51, 255);"&gt;println()&lt;/span&gt; of the &lt;span style="color: rgb(51, 51, 255);"&gt;out&lt;/span&gt; object.&lt;br /&gt;&lt;br /&gt;This is how far as we can guess on the OOP concepts. We do not know the exact type of the &lt;span style="color: rgb(51, 51, 255);"&gt;out&lt;/span&gt; object. All, we can say is that it has a method named &lt;span style="color: rgb(51, 51, 255);"&gt;println()&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;However, if we inspect the code of the System class, we may observe that the class type of &lt;span style="color: rgb(51, 51, 255);"&gt;out &lt;/span&gt;is actually  "&lt;span style="color: rgb(51, 51, 255);"&gt;PrintStream&lt;/span&gt;" declared in the &lt;span style="color: rgb(204, 51, 204);"&gt;java.io&lt;/span&gt; package. We may also observe that it is declared as &lt;span style="color: rgb(51, 51, 255);"&gt;final&lt;/span&gt; in the actual implementation.&lt;br /&gt;&lt;br /&gt;So, I believe this explains the OOP concepts behind the most common method we use to write something on the console. Please feel free to post your comments.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-4818812124788727478?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/4818812124788727478/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=4818812124788727478' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/4818812124788727478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/4818812124788727478'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/05/java-systemoutprintln-explained-in-oop.html' title='Java System.out.println() explained in OOP'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-3506458951569249727</id><published>2009-05-16T00:30:00.000-07:00</published><updated>2009-05-16T03:00:15.559-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Mobile E-Mail'/><category scheme='http://www.blogger.com/atom/ns#' term='J2ME mail'/><category scheme='http://www.blogger.com/atom/ns#' term='Send email'/><title type='text'>Send J2ME Mail</title><content type='html'>Hi, most of you may have wondered how to send mail using J2Me. With the support of J2ME and J2SE, it becomes simple. If you have developed Standalone/Desktop mail sending applications before, this may be even easier. If not please reffer to the following article before&lt;br /&gt;http://ruchiram4.blogspot.com/2008/12/sending-mail-using-java.html&lt;br /&gt;&lt;br /&gt;I assume that you are familiar with J2ME basics (Sun Wireless Toolkit, Midlets) and have the basic knowledge in deploying an application in Tomcat Server.&lt;br /&gt;&lt;br /&gt;The architecture for sending J2ME is slightly restricted. You cannot have your own SMTP Server. So, the J2ME application works by first establishing a connecting with a website/service and passing the relevant values(Eg: Message Subject, To Address, Message Text) to it.&lt;br /&gt;In my case, I used Tomcat and created a Servlet to handle such requests.&lt;br /&gt;&lt;br /&gt;So, we have two applications running seperately.&lt;br /&gt;&lt;br /&gt;1. The J2ME Mobile application&lt;br /&gt;2. The J2SE Server Application&lt;br /&gt;&lt;br /&gt;On receiving the request, the Servlet would process and make the connections with the SMTP server and push the mail to the SMTP Server. In my example I have used the very simple scenario and removed all the complexities regarding code. The user does not get any chance to alter the E-Mail options. The E-Mail addresses are hardcoded. However, the E-Mail Subject and Text are sent from the application(Even though the user doesn't get any opportunity to type the message or subject. This has been done to reduce the complexities in understanding the code)&lt;br /&gt;&lt;br /&gt;First, we must write a Servlet (which can handle HTTP requests) and make it such that it can send a mail.&lt;br /&gt;We use the HTTP POST method in sending the E-Mail from the Mobile Application to the Servlet. So, we need to Override "doPost" method of the Servlet(Since our Servlet extends HttpServlet).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Our Server Application reads two values from the Mobile Application(Even though the end user does not get an opportunity to alter these values, they have been hardcoded in the J2ME application). So first, we must retrieve them.&lt;br /&gt;&lt;br /&gt;They can be received by the following way;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;BufferedReader rdr = request.getReader();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;String subject= rdr.readLine();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;String text= rdr.readLine();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;rdr.close();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;We can get a BufferedReader object using the request object passed to the Servlet. (A HttpServletRequest object is passed to the Servlet by its Container. You do not need to worry about this. It is done by Tomcat)&lt;br /&gt;We read line by line which was sent by the Mobile Application. Then we close the Reader.&lt;br /&gt;&lt;br /&gt;Now, we call the &lt;span style="color: rgb(51, 51, 255);"&gt;private void testMail(String subject, String text)&lt;/span&gt; method which I have written. This is responsible for sending the mail.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Properties prop= new Properties();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;prop.setProperty("mail.smtp.host", "localhost");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Session session = Session.getDefaultInstance(prop);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;InternetAddress from = new InternetAddress("&lt;anything@anydomain.com&gt;");&lt;/anything@anydomain.com&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;InternetAddress to = new InternetAddress("&lt;anything@anydomain.com&gt;");&lt;/anything@anydomain.com&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;MimeMessage msg= new MimeMessage(session);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;msg.setFrom(from);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;msg.addRecipient(RecipientType.TO, to);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt; msg.setSubject(subject);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt; msg.setText(text);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Transport.send(msg);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;Now, build this application and deploy it in Tomcat Sever. Also remember to add the Servlet mapping and URL pattern to the web.xml file located inside Tomcat.&lt;br /&gt;&lt;br /&gt;Start Tomcat. Now, you should have your Web Application running. Next, start the SMTP server. WindowsXP, by default has a SMTP server inbuilt. But you may need to install it as an option when installing windows. It appears under the IIS facility. Or there are some other open source SMTP servers such as Apache James Server.&lt;br /&gt;&lt;br /&gt;The next part deals with developing the J2ME application which is intended to run on a mobile device. Since, it is difficult to test an application on a real device without having the hardware, Sun has developed a device simulator which can be downloaded from&lt;br /&gt;&lt;br /&gt;http://java.sun.com/products/sjwtoolkit/download.html&lt;br /&gt;&lt;br /&gt;We will create a Midlet to start our J2ME application. We will create a method for establishing the connection and sending the mail parameters to the Servlet.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public void sendPOST_Message() throws IOException{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;String url="http://localhost:8080/MailApplication/MailServlet";     &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;HttpConnection conn= (HttpConnection) Connector.open(url);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;conn.setRequestMethod(HttpConnection.POST);       &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;conn.setRequestProperty("Content-Type", "text/plain");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;OutputStream out= conn.openOutputStream();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;PrintStream pout = new PrintStream(out);&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;pout.println("Subject");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;pout.println("My Message");&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;pout.close();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;out.close();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;This method is the method responsible for sending the mail parameters to the Servlet.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;HttpConnection conn= (HttpConnection) Connector.open(url);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We first, instantiate a HttpConnection type object by calling the static open method of &lt;span style="color: rgb(51, 51, 255);"&gt;Connector &lt;/span&gt;object.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;conn.setRequestMethod(HttpConnection.POST);       &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;conn.setRequestProperty("Content-Type", "text/plain");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We set the method of the http connection by Setting it to Post. The next is a compulsary line needed to send a Post request to the Server. You must tell the type of what you send via the request.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;OutputStream out= conn.openOutputStream();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;PrintStream pout = new PrintStream(out);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We instantiate an &lt;span style="color: rgb(51, 51, 255);"&gt;OutputStream &lt;/span&gt;object by calling the &lt;span style="color: rgb(51, 51, 255);"&gt;openOutputStream() &lt;/span&gt;method of the HttpConnection type object. We can create a PrintStream object by passing this OutputStream into it.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;pout.println("Hello World");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;pout.println("Sample Message");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;pout.close();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;out.close();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;Next, we print the values which needs to be sent from the J2ME application to the Servlet. We have hardcoded these values. In real, there should be Textboxes to get the input from the user and then send these parameters into the the Servlet by this method. But for simplicity, we will only demonstrate this case.&lt;br /&gt;&lt;br /&gt;Make sure to call the close methods of these stream objects, as it may not work otherwise.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public void commandAction(Command cmd, Displayable arg1) {&lt;/span&gt;&lt;br /&gt;     &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        if(cmd==cmdSend){   &lt;/span&gt;&lt;br /&gt;                 &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            Thread t = new Thread(new Runnable() {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                public void run() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                    try {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                        sendPOST_Message();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                    } catch (IOException ex) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                        ex.printStackTrace();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                    }&lt;/span&gt;&lt;br /&gt;                 &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            });           &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            t.start();           &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;Next, we call our &lt;span style="color: rgb(51, 51, 255);"&gt;sendPOST_Message() &lt;/span&gt;method as the event when a button click occurs in our J2ME application.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(51, 0, 51);"&gt;In the&lt;/span&gt; commandAction (Command,Displayable)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;method, we do three things.&lt;br /&gt;&lt;br /&gt;1. Check which button called the event &lt;span style="color: rgb(51, 51, 255);"&gt;commandAction (Command,Displayable)&lt;/span&gt; to trigger. (This method is invoked in a button click event. If we have multiple buttons, we need to find out what button was clicked. But, in our application, since we have only one button, the &lt;span style="color: rgb(51, 51, 255);"&gt;if()&lt;/span&gt; clause would not make a difference)&lt;br /&gt;&lt;br /&gt;2. Create a Thread&lt;br /&gt;&lt;br /&gt;3. Call the &lt;span style="color: rgb(51, 51, 255);"&gt;sendPOST_Message()&lt;/span&gt; method, from inside the thread and start the thread&lt;br /&gt;&lt;br /&gt;NOTE: We MUST use Threads when trying to do time consuming operations as Network connecting operations. Otherwise, it may get into a deadlock and not proceed.&lt;br /&gt;&lt;br /&gt;Here is the complete code for the J2ME mail application. It includes just one button to send the mail.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/*&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; * To change this template, choose Tools | Templates&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; * and open the template in the editor.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;package net.ruch.j2me.mail;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;import java.io.IOException;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;import java.io.OutputStream;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;import java.io.PrintStream;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;import javax.microedition.io.Connector;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;import javax.microedition.io.HttpConnection;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;import javax.microedition.midlet.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;import javax.microedition.lcdui.*;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; * @author Ruchira&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public class MailMidlet extends MIDlet implements CommandListener{&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    Form form;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    Command cmdSend;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public MailMidlet() {&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        form= new Form("Main Form");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        cmdSend= new Command("Send mail", Command.OK, 0);        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }      &lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public void startApp() {&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        form.addCommand(cmdSend);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        Display.getDisplay(this).setCurrent(form);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        form.setCommandListener(this);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public void pauseApp() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public void destroyApp(boolean unconditional) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public void sendPOST_Message() throws IOException{&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        String url="http://localhost:8080/MailApplication/&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;MailServlet&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;";      &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        HttpConnection conn= (HttpConnection) Connector.open(url);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        conn.setRequestMethod(HttpConnection.POST);        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        conn.setRequestProperty("Content-Type", "text/plain");&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        OutputStream out= conn.openOutputStream();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        PrintStream pout = new PrintStream(out);&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        pout.println("HelloWorld");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        pout.println("This is a sample message ");&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        pout.close();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        out.close();      &lt;/span&gt;&lt;br /&gt;       &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    public void commandAction(Command cmd, Displayable arg1) {&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        if(cmd==cmdSend){    &lt;/span&gt;&lt;br /&gt;                    &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            Thread t = new Thread(new Runnable() {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                public void run() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                    try {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                        sendPOST_Message();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                    } catch (IOException ex) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                        ex.printStackTrace();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                    }&lt;/span&gt;&lt;br /&gt;                    &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            });            &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            t.start();            &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }  &lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;So, now, compile and run the application. Hopefully, you should get the mail.&lt;br /&gt;&lt;br /&gt;I referred to the following site in building the application. This site displays a complete code segment for a mobile J2ME E-Mail application. I just filtered out the most necessary steps required to make it easier to understand. For a complete application please reffer to this.&lt;br /&gt;&lt;br /&gt;http://www.java-tips.org/java-me-tips/midp/sending-email-from-j2me-devices.html&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-3506458951569249727?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/3506458951569249727/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=3506458951569249727' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/3506458951569249727'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/3506458951569249727'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/05/send-j2me-mail.html' title='Send J2ME Mail'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-4371059788306144431</id><published>2009-05-14T02:39:00.000-07:00</published><updated>2009-05-14T02:45:00.241-07:00</updated><title type='text'>J2ME Split String code segment</title><content type='html'>Most of you who are used to the split() functionality may miss it a lot when moving on to J2ME. So, here is a code segment which I had used to acchive similar functionality using J2ME methods.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public String[] split(String str, String delimiter){&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;      &lt;span style="color: rgb(0, 153, 0);"&gt;//Iterate through the text to get the count of occurences&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;       //This is done since we do not know how many times the&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;       //delimitter occurs in the given string&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;       //--------------------------------------------------//&lt;/span&gt;&lt;br /&gt;     &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;int delimiterCount=0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       int index;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       String tmpStr=str;&lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       String[] splittedList;&lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       while((index=tmpStr.indexOf(delimiter))!=-1){&lt;/span&gt;&lt;br /&gt;          &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;           tmpStr=tmpStr.substring(index+delimiter.length());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;           delimiterCount++;           &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       }       &lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       splittedList=new String[delimiterCount];&lt;/span&gt;&lt;br /&gt;            &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/*-----------------------------------------------*/&lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;      &lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;       /*-----------------------------------------------*/       &lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;      &lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;       //-----------------------------------------------//&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(51, 51, 255);"&gt;index=0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       int counter=0;       &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       tmpStr=str;&lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;      &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       while((index=tmpStr.indexOf(delimiter))!=-1){&lt;/span&gt;&lt;br /&gt;          &lt;br /&gt;         &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;           int nextIndex=tmpStr.indexOf(delimiter, index+1);&lt;/span&gt;&lt;br /&gt;          &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;           if(nextIndex!=-1){&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;               splittedList[counter++]=tmpStr.substring(index+delimiter.length(), nextIndex);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;               tmpStr=tmpStr.substring(nextIndex);&lt;/span&gt;&lt;br /&gt;              &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;           }else{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;               splittedList[counter++]=tmpStr.substring(index+delimiter.length());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;               tmpStr=tmpStr.substring(index+1);               &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;           }                                   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       }&lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       return splittedList;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Happy coding !!!!&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-4371059788306144431?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/4371059788306144431/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=4371059788306144431' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/4371059788306144431'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/4371059788306144431'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/05/j2me-split-string-code-segment.html' title='J2ME Split String code segment'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-7213515308006115385</id><published>2009-05-13T11:34:00.000-07:00</published><updated>2009-05-13T12:12:28.251-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Connect MySQL NetBeans'/><category scheme='http://www.blogger.com/atom/ns#' term='My Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Connect'/><category scheme='http://www.blogger.com/atom/ns#' term='NetBeans'/><title type='text'>Connect MySQL with NetBeans</title><content type='html'>A very common problem which recurrs through software development is on how to connect to MySQL Database server using NetBeans IDE. In this post, I intend to present a very clear description on how to do so.&lt;br /&gt;&lt;br /&gt;I have used NetBeans 6.1 with MySQL DB Server. But connecting with other versions of the IDE would be similar.&lt;br /&gt;&lt;br /&gt;1. Open your IDE and click on the "Services" Tab as shown. If it is not shown, click on Windows-&gt;Services to display it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/SgsUgdwXXlI/AAAAAAAAAEw/aEC4GwQixLA/s1600-h/pic1.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/SgsUgdwXXlI/AAAAAAAAAEw/aEC4GwQixLA/s320/pic1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335380731526340178" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You can see the Driver for MySQL is already added to NetBeans. Otherwise, right click on "Drivers" and click 'New Driver'. Then show the location of the New Driver.&lt;br /&gt;&lt;br /&gt;Right Click on MySQL and Click "Connect Using". Then you should get the following dialog.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/SgsUglraHAI/AAAAAAAAAFI/pvNix_lRQvc/s1600-h/pic4.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 221px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/SgsUglraHAI/AAAAAAAAAFI/pvNix_lRQvc/s320/pic4.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335380733653031938" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;2. This dialog requests the relevant configuration details of the Database server.&lt;br /&gt;You can observe a TextBox displaying the "Database URL". This is the connection String used to connect to the database.&lt;br /&gt;&lt;br /&gt;There are three main fields which you must supply&lt;br /&gt;&lt;br /&gt;a) &amp;lt;Host&amp;gt; : This refers to the IP address of the computer where the Database server is running. If the Database Server is running on your machine, replace &lt;Host&gt; with localhost or 127.0.0.1&lt;br /&gt;&lt;br /&gt;b) &amp;lt;Port&amp;gt; : Ports are used to differentiate services on the same machine. In most general cases of MySQL installations(ie: If you have not changed the default values), the port where MySQL runs is 3306. You can safely replace &lt;Port&gt; by 3306&lt;br /&gt;&lt;br /&gt;c) &amp;lt;DB&amp;gt; : DB refers to the Database which you need to connect to. Since a Database Server can host multiple Databases at once, you need to specify which Database you need to connect with. In my case I have a Database named "Drupal"&lt;br /&gt;&lt;br /&gt;Then fill in the username for the database and the password. By default, the root user has password root or none(blank).&lt;br /&gt;&lt;br /&gt;After filling the configurations, it should look something similar as the following.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_NACWt_PFgLM/SgsUgrbjslI/AAAAAAAAAFA/pioQF3QFwfA/s1600-h/pic3.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 221px;" src="http://3.bp.blogspot.com/_NACWt_PFgLM/SgsUgrbjslI/AAAAAAAAAFA/pioQF3QFwfA/s320/pic3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335380735197164114" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After entering the data, click on the "Advanced" tab and click on the "Get Schemas" button. If successful, you should get a message saying "Connection Established" as shown below.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/SgsUgiau3PI/AAAAAAAAAE4/_0bhH0WXWyQ/s1600-h/pic2.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 222px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/SgsUgiau3PI/AAAAAAAAAE4/_0bhH0WXWyQ/s320/pic2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335380732777782514" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;3. After successful configuration, you should observe the following under services tab.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_NACWt_PFgLM/SgsUg_m6n7I/AAAAAAAAAFQ/I691uXRwzgI/s1600-h/pic5.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://3.bp.blogspot.com/_NACWt_PFgLM/SgsUg_m6n7I/AAAAAAAAAFQ/I691uXRwzgI/s320/pic5.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335380740613513138" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;NOTE: You may not be able to view anything under tables is you do not have any tables. Also observe the icon for displaying the connection is slightly different now, showing that a connection has been made.&lt;br /&gt;&lt;br /&gt;4. Once you have done that, you may need to try and execute some SQL commands. To do so, right click on the connection icon and select "Execute Command" as follows.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_NACWt_PFgLM/SgsZN7_4h-I/AAAAAAAAAFY/9gwtxvmGDQs/s1600-h/pic6.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_NACWt_PFgLM/SgsZN7_4h-I/AAAAAAAAAFY/9gwtxvmGDQs/s320/pic6.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335385910785116130" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You would be taken to a new window as shown below.(The results would be visible only after execution of the command)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_NACWt_PFgLM/SgsZN07SMtI/AAAAAAAAAFg/W_f2vYCJRv4/s1600-h/pic7.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://3.bp.blogspot.com/_NACWt_PFgLM/SgsZN07SMtI/AAAAAAAAAFg/W_f2vYCJRv4/s320/pic7.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335385908886778578" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5. Now, type 'select * from &lt;table_name&gt;' and click on the Execute button which is circled in red.&lt;br /&gt;If you have data in your table, you should be able to view them in your bottom left corner of the screen.&lt;br /&gt;&lt;br /&gt;Have fun guys&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-7213515308006115385?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/7213515308006115385/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=7213515308006115385' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/7213515308006115385'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/7213515308006115385'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/05/connect-mysql-with-netbeans.html' title='Connect MySQL with NetBeans'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_NACWt_PFgLM/SgsUgdwXXlI/AAAAAAAAAEw/aEC4GwQixLA/s72-c/pic1.JPG' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-5391290101994374202</id><published>2009-05-10T01:21:00.000-07:00</published><updated>2009-09-09T01:00:18.687-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DOT NET'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='FolderBrowseDialog'/><category scheme='http://www.blogger.com/atom/ns#' term='Browse Folder'/><title type='text'>How to Browse Folders using Dot NET</title><content type='html'>Most of you may have come up with scenarios where you wish to let the user browse for a specific folder or file. This is most commonly occured when you are requested to open a specific file in Word or Power Point.&lt;br /&gt;I would be using Visual Studio 2005 and DOT NET Framework 2.0&lt;br /&gt;&lt;br /&gt; DOT NET 2.0 Framework supports several useful dialogs. In this, we will use the "FolderBrowseDialog" class for the example.&lt;br /&gt;&lt;br /&gt; It can be very easily found in the "ToolBox" under "Dialogs" category. Simply drag and drop one on to your Form. Add a Button also for the demo.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/SgaYQkvHQpI/AAAAAAAAAEQ/4WzyhQzZT54/s1600-h/pic1.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/SgaYQkvHQpI/AAAAAAAAAEQ/4WzyhQzZT54/s320/pic1.JPG" alt="" id="BLOGGER_PHOTO_ID_5334118219173544594" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt; Then, double click on the Search Button and it would take you to the Click Event of the Button.&lt;br /&gt;&lt;br /&gt;Inside that, place the following LOC.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(51, 51, 255);"&gt;DialogResult result;&lt;/span&gt;  &lt;span style="color: rgb(51, 51, 255);"&gt;            result = folderBrowserDialog1.ShowDialog();&lt;/span&gt;  &lt;span style="color: rgb(51, 51, 255);"&gt;           &lt;br /&gt; &lt;br /&gt;if (result == DialogResult.OK)&lt;/span&gt; &lt;span style="colorjavascript:void(0): rgb(51, 51, 255);"&gt;            &lt;br /&gt;{&lt;/span&gt; &lt;span style="color: rgb(51, 51, 255);"&gt;                &lt;br /&gt;&lt;br /&gt;MessageBox.Show("Selected Path :" +folderBrowserDialog1.SelectedPath);&lt;/span&gt; &lt;span style="color: rgb(51, 51, 255);"&gt;  javascript:void(0)&lt;br /&gt;          &lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;Lets analyse each of the LOC.&lt;br /&gt;&lt;br /&gt; DOT NET uses a Class named DialogResult. It can be used to access the result of various types of Dialog Boxes.&lt;br /&gt;&lt;br /&gt;NOTE: There are different types of Dialogs available such as "OpenFileDialog", "SaveFileDialog".&lt;br /&gt;&lt;br /&gt; The DialogResult can be used to get the type of result entered by the user. Such as pressing the "OK" button, Pressing the "Yes" button etc.&lt;br /&gt;&lt;br /&gt; Then we display the &lt;span style="color: rgb(51, 51, 255);"&gt;folderBrowserDialog1 &lt;span style="color: rgb(51, 0, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;and set its result to the DialogResult reference.&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;Then, we check for the event which is triggered by the use&lt;/span&gt;r. In the "if" clause, we check whether the user clicked "OK" button. In that case, we would simply display the selected path in a Message Box. We get the selected path of the folder using the &lt;span style="color: rgb(51, 51, 255);"&gt;folderBrowserDialog1&lt;/span&gt; ' s &lt;span style="color: rgb(51, 51, 255);"&gt;SelectedPath&lt;/span&gt; property.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_NACWt_PFgLM/SgaauiqlDhI/AAAAAAAAAEY/2tlWOdtLjD8/s1600-h/pic2.JPG"&gt;&lt;img style="cursor: pointer; width: 274px; height: 123px;" src="http://4.bp.blogspot.com/_NACWt_PFgLM/SgaauiqlDhI/AAAAAAAAAEY/2tlWOdtLjD8/s320/pic2.JPG" alt="" id="BLOGGER_PHOTO_ID_5334120933036985874" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_NACWt_PFgLM/SgaayC4LHCI/AAAAAAAAAEg/WUDAHy9qLmw/s1600-h/pic3.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 316px;" src="http://4.bp.blogspot.com/_NACWt_PFgLM/SgaayC4LHCI/AAAAAAAAAEg/WUDAHy9qLmw/s320/pic3.JPG" alt="" id="BLOGGER_PHOTO_ID_5334120993223547938" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_NACWt_PFgLM/Sgaa1EUu9hI/AAAAAAAAAEo/kw40xVUIAFo/s1600-h/pic4.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 89px;" src="http://3.bp.blogspot.com/_NACWt_PFgLM/Sgaa1EUu9hI/AAAAAAAAAEo/kw40xVUIAFo/s320/pic4.JPG" alt="" id="BLOGGER_PHOTO_ID_5334121045151381010" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-5391290101994374202?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/5391290101994374202/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=5391290101994374202' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/5391290101994374202'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/5391290101994374202'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/05/how-to-browse-folders-using-dot-net.html' title='How to Browse Folders using Dot NET'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_NACWt_PFgLM/SgaYQkvHQpI/AAAAAAAAAEQ/4WzyhQzZT54/s72-c/pic1.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-6255714360292686895</id><published>2009-04-26T12:16:00.000-07:00</published><updated>2009-04-26T13:22:52.375-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Encrypt picture'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Encryption'/><category scheme='http://www.blogger.com/atom/ns#' term='Encrypt image'/><title type='text'>Encrypt and Decrypt Images Using Java</title><content type='html'>Hi, Most of you would find it useful to Encrypt a special picture of yours such that only you can view it. By using JCE(Java Cryptography Extension) classes, this becomes very simple. As I have already done before using Java to encrypt a String is very simple. If you are new to this, please read the article which I had already posted named "Java Encryption and Decryption"&lt;br /&gt;at  "http://ruchiram4.blogspot.com/2009/04/java-encryption-and-decryption.html"&lt;br /&gt;Also, you need to have a basic understanding of Java IO. If you are new, it is better to read the Sun Java tutorial on IO.&lt;br /&gt;&lt;br /&gt;Before we move on, lets recall the basic steps in Encrypting plaintext.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 51, 153);"&gt;1. Creating an instance of "Cipher" object and setting the mode of Encryption (Eg: AES, DES)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 51, 153);"&gt;2. Generating a key by using a KeyGenerator object.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 51, 153);"&gt;3. Setting the mode of Cipher operation on the Cipher object. As we intent to Encrypt, we simply  set it by setting a property of Cipher object by calling its "init" method.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 51, 153);"&gt;4.  Calling the "doFinal" method of the Cipher object&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;  Now, Encrypting an image is pretty much similar except, we first need to read the image from the hard disk as a File Input. Initializing steps are the same for the Cipher object and Key.&lt;br /&gt;We first initialize a Cipher object for Encrypting as we have done. We pass the Cipher object with the necessary key used for Encryption. This can be done by calling the "init" method of the Cipher object and passing the necessary parameters.&lt;br /&gt;Once we initialize a Cipher Object, we pass the initialized Cipher object to a "CipherInputStream" object.  (A CipherInputStream object is an object provided by JCE. We need to show which file to read from and which cipher object to use). Then we can simply read through the CipherInputStream object and Encryption is done while reading from the CipherInputStream object.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Creating a Cipher object and a Key&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Cipher cipher=Cipher.getInstance("AES");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;KeyGenerator keyGen=KeyGenerator.getInstance("AES");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Key key=keyGen.generateKey();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Now, we initialize the Cipher object&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;cipher.init(Cipher.ENCRYPT_MODE, key);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Create a CipherInputStream object by passing the realavent image to be Encrypted along with the Cipher object which we initilalized&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;cipherIn=new CipherInputStream(new FileInputStream(new File("./image.jpg")), cipher);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Now, we create an output stream for writing back the Encrypted image to disk&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;FileOutputStream fos=new FileOutputStream(new File("./filename.jpg"));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Now, we read from the CipherInputStream object just like reading from a FileInputStream.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;We simply write back the Encrypted file to the Disk&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;int i;      &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;while((i=cipherIn.read())!=-1){&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;           fos.write(i);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;NOTE: It is more efficient to use Buffer objects when doing file IO. But, in order to make things clear and simple, I ommited them.&lt;br /&gt;&lt;br /&gt;    Decrypting is very similar. You first need to call make another Cipher object and call init method with parameter for Decryption. This can be done as follows&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;cipher.init(Cipher.DECRYPT_MODE, key);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;NOTE: YOU MUST USE THE &lt;span style="font-weight: bold;"&gt;SAME KEY GENERATED &lt;/span&gt;WHICH WAS USED FOR ENCRYPTING. OTHERWISE, YOU MAY NOT BE ABLE TO DECRYPT IT BACK.&lt;br /&gt;&lt;br /&gt;    Now, we can use a &lt;span style="color: rgb(51, 51, 51);"&gt;CipherInputStream object to read the Encrypted image. Since, we have set the mode to decryption, the &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;CipherInputStream would basically decrypt as it reads from the Encrypted image.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-6255714360292686895?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/6255714360292686895/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=6255714360292686895' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/6255714360292686895'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/6255714360292686895'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/04/encrypt-and-decrypt-images-using-java.html' title='Encrypt and Decrypt Images Using Java'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-8251093420996830515</id><published>2009-04-25T04:05:00.000-07:00</published><updated>2009-04-25T04:43:22.462-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OTR'/><category scheme='http://www.blogger.com/atom/ns#' term='Chat Application'/><category scheme='http://www.blogger.com/atom/ns#' term='Off The Record'/><category scheme='http://www.blogger.com/atom/ns#' term='Protocol'/><title type='text'>Off The Record Protocol (OTR)</title><content type='html'>Off The Record Protocol (OTR) is one of the emerging protocols today. It is becoming more and more popular amongst Internet Messenger Services by providing a service similar to a conversation by two people. Internet Messenger Applications such as Pidgin has already implemented such a plugin fo the application and other messenger services are already on the move with implementing the feature.&lt;br /&gt;OTR provides the two parties to have a conversation between them by providing the following features.&lt;br /&gt;&lt;br /&gt;i) Encryption : Messages can be read by only the two parties involved.&lt;br /&gt;&lt;br /&gt;ii) Authentication : Lets each parties know that they are chatting with the person who they think they are. In simpler terms, this features prevents forging by a third party by imitating the other person.&lt;br /&gt;&lt;br /&gt;iii) Deniability(Repudiability) : This is a controversial term. We are very much used with the term 'Non Repudiability' when we talk about Computer Security. But here, we specifically allow repudiability to occur.&lt;br /&gt;&lt;br /&gt;iv) Perfect Forward Secrecy: This assures that even though one party is compromised, the attacker would not be able to read old conversations of the victim.&lt;br /&gt;&lt;br /&gt;   All of these features make sense except the third. So, I would only elaborate on this feature and show how Deniability or Repudiability is needed.&lt;br /&gt;Deniability gives us the liberty to say something to a person using a Messenger Service and then later decline saying that.&lt;br /&gt;&lt;br /&gt;   Suppose a verbal conversation between Alice and Bob. Alice says to Bob to meet her at 5 o'clock and Bob agrees. However, Bob doesn't turn up at 5. When Alice asks why he didn't come, Bob would simply lie and say that he never spoke with Alice about meeting at 5 and there would be no way of proving thay.  There would be no means of verifying that Bob is lying. No third party can verify that Bob actually lied. No one else other than Alice and Bob knows what they discussed. No one would later be able to know what they talked about. This is the nature of a verbal conversation.&lt;br /&gt;&lt;br /&gt;   In E-Commerce, this has been one of the major issues which needs to be dealt. Therefore, we use Signatures and sign a document before sending. This way neither of the parties can lie. If this Signature system was used in Internet Messenger sevices, we would not have faced the scenario above and Bob would be caught for lying.&lt;br /&gt;&lt;br /&gt;   However, it is to be noted that the intention of a chat application is to make it as close to a verbal conversation between two people. Chat applications are NOT to be used for E-Commerce related applications or conversations which need to be reproduced. Therefore, in order to maintain the chat application as close as to a real world verbal conversation, we need to build it in such a way deniability is possible. Therefore Repudiability is necessary.&lt;br /&gt;&lt;br /&gt;   Perfect Forward Secrecy is also another need of a chat application. If Alice and Bob had a private verbal conversation with each other, no one else would be able to hear what went on among them. No one would be able to know what actually took place between them. If someone else would be able to know what went on, it would not be secure. Now, suppose that they recorded the chat which took place and keep it secretly. However, if the recorder tape is compromised by Eve, then Eve would be able to know what Alice and Bob had been talking. This should not be the case. Therefore, in OTR protocol, we make sure a compromise of any party would not reveal old data.&lt;br /&gt;&lt;br /&gt;For further information please reffer to the website&lt;br /&gt;http://www.cypherpunks.ca/otr/&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-8251093420996830515?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/8251093420996830515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=8251093420996830515' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/8251093420996830515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/8251093420996830515'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/04/off-record-protocol-otr.html' title='Off The Record Protocol (OTR)'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-50771100764264511</id><published>2009-04-11T13:15:00.000-07:00</published><updated>2009-04-26T13:26:53.093-07:00</updated><title type='text'>Java Encryption and Decryption</title><content type='html'>Hi Folks,&lt;br /&gt;&lt;br /&gt;Most of you would be very much interested to know how to use java to do crypto work.&lt;br /&gt;In this post, I would demonstrate how to use JCE(Java Cryptography Extension) Classes and methods to very simply Encrypt and Decrypt a PlainText.&lt;br /&gt;&lt;br /&gt;This article is intended for an audience who is familiar with cryptography concepts and is looking for an implementation of such an algorithm in Java. If you are looking to learn Cryptography concepts, this post may not be helpful.&lt;br /&gt;&lt;br /&gt;JCE provides us with a bunch of useful classes to accomplish this. I would demonstrate how to do so using Cipher class. Cipher class is handy to handle such task. You can get an instance of a Cipher Class by calling its static method&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;ENCRYPTION&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Cipher cipher=Cipher.getDefaultInstance("DES");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This accepts a string indicating the encrypting algorithm. For now, we will use DES(Data Encryption Standard)&lt;br /&gt;&lt;br /&gt;In order to Encrypt, we need a key. A key can be easily generated by using the KeyGenerator Class provided.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;KeyGenerator&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt; keyGen=KeyGenerator.getInstance("DES");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;Key key=keyGen.generateKey();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Once we have a key, Encryption is simple.&lt;br /&gt;&lt;br /&gt;We first need an array of bytes for encryption.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;byte[] encryptedStream="HelloWorld".getBytes();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Then, we need to set the Encryption mode of Cipher object we have for Encryption.&lt;br /&gt;The Cipher object can be used for decryption also by setting the mode.&lt;br /&gt;It can be done as follows.&lt;br /&gt;As you may further observe, the init() method requires the key also.&lt;br /&gt;     &lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;cipher.init(Cipher.ENCRYPT_MODE, key);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Once, we have done the init(), we can Encrypt using the doFinal() method of Cipher Object.&lt;br /&gt;This returns a byte array.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;encryptedStream = cipher.doFinal(inputStream);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;DECRYPTION&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Decryption is also very similar.&lt;br /&gt;Make sure, you use the same key for decryption(If you call KeyGenerator.getInstance("DES") once more, you would get a different key and you would not be able to decrypt the ciphertext back to the same input )&lt;br /&gt;&lt;br /&gt;We just need to change the mode of the Cipher object to Decrypt.&lt;br /&gt;It is done very similarly.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;cipher.init(Cipher.DECRYPT_MODE, key);        &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;decryptedStream=cipher.doFinal(inputStream);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Have FUN!!!!!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-50771100764264511?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/50771100764264511/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=50771100764264511' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/50771100764264511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/50771100764264511'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/04/java-encryption-and-decryption.html' title='Java Encryption and Decryption'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-1565111807664183585</id><published>2009-04-06T08:48:00.000-07:00</published><updated>2009-04-14T10:44:07.059-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='build snmp tool'/><category scheme='http://www.blogger.com/atom/ns#' term='SNMP'/><category scheme='http://www.blogger.com/atom/ns#' term='java snmp'/><category scheme='http://www.blogger.com/atom/ns#' term='snmp tool'/><category scheme='http://www.blogger.com/atom/ns#' term='snmp monitor tool'/><title type='text'>Build your own SNMP Monitoring Tool</title><content type='html'>SNMP is a protocol used widely for monitoring and extracting status information of a working device. Using SNMP protocol, you can extract the present information about a certain device. It is widely used for monitoring network devices such as Routers. But, practically any device which supports SNMP protocol can be used. As an example consider a SNMP enabled network printer inside an organization. The Network admin can issue necessary commands to the SNMP enabled device to get the status of the printer to check the status of the printer to see whether it is working as it should. Furthermore, the SNMP enabled device can be configured to issue an alert once a condition is met. As an example, there may be a Network printer which can be configured to make an alert once the ink level drops below a certain level. The breadth of SNMP is determined by the capabilities embedded into the device itself.&lt;br /&gt;Another very useful scenario is where a JVM(Java Virtual Machine) can be SNMP enabled to be monitored by the admin. Suppose, there is a server with an instance of JVM running. Then the JVM can be configures to issue a notification when the JVM crashes. Thus, the admin can take necessary action to restore the Server soon.&lt;br /&gt;&lt;br /&gt;This post is intended for an audience with fundamental knowledge in Java and SNMP to build a tool for SNMP Monitoring.&lt;br /&gt;&lt;br /&gt;I used the snmp.jar available for download with NetBeans IDE for the development purposes.&lt;br /&gt;(You can also use snmp4j.jar which is very much similar to this)&lt;br /&gt;There is not much of initialization stuff to do. You just need to add the Jar file to your project. It is very easy!!!&lt;br /&gt;&lt;br /&gt;Once added, you can begin using the Classes provided by the API to get the job done.&lt;br /&gt;&lt;br /&gt;Before we move on, lets get an idea of OID(Object Identifiers) related to SNMP. OID s are very much used in SNMP to give a specific ID for an attribute available by the device. It is arranged in a tree structure and is subjected to a specific layout. There are lots of documents available to get an in depth view of OIDs. As far as we are concerned, we would be using a set of OIDs which all SNMP enabled devices will support which happen to be the basics. Some of these OIDs include the Name of the device, Uploaded Bytes, Downloaded Bytes, Total Up time etc. We would be using these OIDs for the demo.&lt;br /&gt;&lt;br /&gt;snmp.jar provides a way of querying an SNMP enabled device for such OIDs. We can do it in the following manner.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;/*****************************************************************/&lt;/span&gt;&lt;br /&gt;int version=0;  &lt;br /&gt;String communityString="public";&lt;br /&gt;InetAddress host=InetAddress.getByName("192.168.1.1');&lt;br /&gt;SNMPv1CommunicationInterface comInterface=new SNMPv1CommunicationInterface(version,host,communityString);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;        //This correspods to the OID =1.3.6.1.2.1.5.0 which gives the name of the device&lt;/span&gt;&lt;br /&gt;String identifier="1.3.6.1.2.1.1.5.0";&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SNMPVarBindList list=comInterface.getMIBEntry(identifier);&lt;br /&gt;SNMPSequence pair=(SNMPSequence)list.getSNMPObjectAt(0);&lt;br /&gt;&lt;br /&gt;SNMPObject obj=pair.getSNMPObjectAt(1);&lt;br /&gt;SNMPOctetString octet=(SNMPOctetString)obj;&lt;br /&gt;&lt;br /&gt;octet.toString();&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;/***************************************************************/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First consider the LOC&lt;br /&gt;&lt;br /&gt;int version=0;&lt;br /&gt;&lt;br /&gt;This is used to indicate that we intend to use SNMP version 1 (There are version 2 supporting devices. In such case, it is said to use 1 instead of 0.)&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;Next consider the following LOC&lt;br /&gt;&lt;br /&gt;String communityString="public";&lt;br /&gt;&lt;br /&gt;This indicates to use the values which are accesed by public. If you do not intend to change them, then this is fine.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;The following LOC is used to reffer to the device IP.&lt;br /&gt;InetAddress host=InetAddress.getByName("192.168.1.1');&lt;br /&gt;&lt;br /&gt;InetAddress Class is really useful for representing an IP address. It provides a static method 'getByName' which accepts a String of the IP. Thus, we use it for handling IP addresses.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;What we actually do is to first establish a Communication channel between us and the device and we pass the necessary OIDs through it. This is clearly exhibited through the following LOC.&lt;br /&gt;&lt;br /&gt;SNMPv1CommunicationInterface comInterface=new SNMPv1CommunicationInterface(version,host,communityString);&lt;br /&gt;&lt;br /&gt;The SNMPv1CommunicationInterface class's constructor accepts three parameters.&lt;br /&gt;i) Version&lt;br /&gt;ii) Host&lt;br /&gt;ii) Communication String&lt;br /&gt;&lt;br /&gt;We simply pass the relevant values which we produced earlier.&lt;br /&gt;&lt;br /&gt;NOTE: Actually I cannot understand why the class's constructor SNMPv1CommunicationInterface(version,host,communityString) has the parameter version. Since this class's name states SNMP Version 1, then it should NOT be used for making connections with SNMP version 2 devices. There should be a seperate class for that. If the class can be used to make connections with several versions of SNMP, then the class name should be more abstract, say SNMPCommunicationInterface, where the version is not included in the Class's name. Anyway, I feel there is a slight mismatch in the naming convention used. Regardless of that, this is a very handy library to use and if anyone can clarify the issue, I'd be highly grateful.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;This is the OID representing the name of the device.&lt;br /&gt;String identifier="1.3.6.1.2.1.1.5.0";&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;Communication interface object has a method 'getMIBEntry' which we use to send the necessary OID. We use this to send the necessary OID to the device.&lt;br /&gt;&lt;br /&gt;SNMPVarBindList list=comInterface.getMIBEntry(identifier);&lt;br /&gt;&lt;br /&gt;This method returns an Object of type SNMPVarBindList. This is very much like an array of objects.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SNMPSequence pair=(SNMPSequence)list.getSNMPObjectAt(0);&lt;br /&gt;According to our request, we would get an array with only one object located at 0th position. Thus, we get the SNMP object at location zero by the above LOC. This object happens to be an Object of type SNMPSequence. Thus, we can safely cast it to that.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;SNMPObject obj=pair.getSNMPObjectAt(1);&lt;br /&gt;&lt;br /&gt;The SNMPSequence Object we receive has basically two values(I'm not certain whether this object can have values similar to an array). The OID, and the respective value. The OID is positioned at oth position and the respective value is at 1st index. Since we are only interested in the value, we use the object at location 1 only.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;SNMPOctetString octet=(SNMPOctetString)obj;&lt;br /&gt;octet.toString();&lt;br /&gt;&lt;br /&gt;The object located at index 1 is of type SNMPOctedString. We can safely use the toString() method to get the value of the object.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;By using such OID values, we can get the necessary values of the Device.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Calculating the Upload/Download speed&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Calculating the up/down speed can be done as follows.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Get the downloaded bytes.&lt;/li&gt;&lt;li&gt;After an interval again get the downloaded bytes.&lt;/li&gt;&lt;li&gt;Divide the difference by time.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;This is the same for upload speed.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;So, by using some imagination, you can come up with a really good software which you can use to monitor the state of a SNMP enabled device.&lt;br /&gt;&lt;br /&gt;Here are some of the screenshots of mine.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_NACWt_PFgLM/SdtPLq8kI2I/AAAAAAAAADQ/EWb-L1GP49I/s1600-h/pic0.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_NACWt_PFgLM/SdtPLq8kI2I/AAAAAAAAADQ/EWb-L1GP49I/s320/pic0.JPG" alt="" id="BLOGGER_PHOTO_ID_5321934446593844066" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_NACWt_PFgLM/SdtPoZ7WuUI/AAAAAAAAADg/QSDwL99dKi8/s1600-h/pic2.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_NACWt_PFgLM/SdtPoZ7WuUI/AAAAAAAAADg/QSDwL99dKi8/s320/pic2.JPG" alt="" id="BLOGGER_PHOTO_ID_5321934940241574210" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_NACWt_PFgLM/SdtPePdxV6I/AAAAAAAAADY/iQXBnlHsLCU/s1600-h/pic1.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://3.bp.blogspot.com/_NACWt_PFgLM/SdtPePdxV6I/AAAAAAAAADY/iQXBnlHsLCU/s320/pic1.JPG" alt="" id="BLOGGER_PHOTO_ID_5321934765634443170" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_NACWt_PFgLM/SdtRBuIMmaI/AAAAAAAAADo/LeB3pcUiO_U/s1600-h/pic3.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_NACWt_PFgLM/SdtRBuIMmaI/AAAAAAAAADo/LeB3pcUiO_U/s320/pic3.JPG" alt="" id="BLOGGER_PHOTO_ID_5321936474672503202" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-1565111807664183585?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/1565111807664183585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=1565111807664183585' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1565111807664183585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1565111807664183585'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/04/buil-your-own-snmp-monitoring-tool.html' title='Build your own SNMP Monitoring Tool'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_NACWt_PFgLM/SdtPLq8kI2I/AAAAAAAAADQ/EWb-L1GP49I/s72-c/pic0.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-7711964006944701609</id><published>2009-01-20T05:16:00.000-08:00</published><updated>2009-04-14T10:46:48.165-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='sql array'/><category scheme='http://www.blogger.com/atom/ns#' term='splitting csv'/><category scheme='http://www.blogger.com/atom/ns#' term='arrays'/><title type='text'>How to pass a collection of data to SQL Server</title><content type='html'>Hi all. If you are faced with a situation where you wish to send an array of strings(say) to the Server, then you have stumbled to the correct page :-)&lt;br /&gt;To start off with, SQL server up to 2005 does not support Arrays. So, it becomes a bit difficult for Java,C#,C++ programmers who are very fond of arrays to get their job done.&lt;br /&gt;&lt;br /&gt;Fortunately there is a detour which enables us to get the job done.&lt;br /&gt;Instead of sending the list as an array, we can append a delimiter(here I used the comma) and send the complete string to the server side.&lt;br /&gt;At the server side, it splits the separate strings by the delimiter and inserts them into a table(her I used it as a single column table of the form&lt;br /&gt;tmpTable(_name varchar(50)))&lt;br /&gt;You can use the values inserted into this table and use the results similar to having an array.&lt;br /&gt;&lt;br /&gt;NOTE: It does not support the sophisticated array functions you are used to, but it will let you get the job done.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/*&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; PROCEDURE NAME   : readCSV&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; AUTHOR     : Ruchira Randana&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; PROCEDURE DESCRIPTION : Used to seperate a Comma Seperated List and input the values to a table&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; INPUT     : Comma Seperated string&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; OUTPUT     : Seperated values as the comma for the delimitter&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;----------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;----------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;create procedure&lt;/span&gt; readCSV&lt;br /&gt;&lt;br /&gt;@CSValueString varchar(2500)&lt;br /&gt;&lt;br /&gt;as begin&lt;br /&gt;&lt;br /&gt;declare @index int&lt;br /&gt;declare @length int&lt;br /&gt;declare @nextCommaIndex int&lt;br /&gt;declare @value varchar(50)&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;----------------------------------------------------------------------------------------&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;----------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;set @length=len(@CSValueString)&lt;br /&gt;set @nextCommaIndex=charindex(',',@CSValueString,1)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;----------------------------------------------------------------------------------------&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;----------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;/span&gt;&lt;br /&gt;while((@nextCommaIndex&gt;0) or (len(@CSValueString)&gt;0))&lt;br /&gt;begin&lt;br /&gt;&lt;br /&gt; if(len(@CSValueString)&gt;0 and @nextCommaIndex=0)&lt;br /&gt;  begin&lt;br /&gt;   set @value=ltrim(rtrim(@CSValueString))&lt;br /&gt;   set @nextCommaIndex=-1&lt;br /&gt;   set @CSValueString=''&lt;br /&gt;  end&lt;br /&gt; else&lt;br /&gt;  begin&lt;br /&gt;   set @value=substring(@CSValueString,1,@nextCommaIndex-1)&lt;br /&gt;   set @value=ltrim(rtrim(@value)) &lt;br /&gt;   set @CSValueString=substring(@CSValueString,@nextCommaIndex+1,len(@CSValueString))&lt;br /&gt;   set @nextCommaIndex=charindex(',',@CSValueString,1)&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt; insert into tmpTable values(@value)&lt;br /&gt;end &lt;br /&gt;&lt;br /&gt;end&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;----------------------------------------------------------------------------------------&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;----------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--exec readCSV 'Ruchira,randana,galappaththi,ruch'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;----------------------------------------------------------------------------------------&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;----------------------------------------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;/span&gt;&lt;br /&gt;To run this code, first create a table named 'tmpTable' schema(_name varchar(50))  on your Data Base. This can be done by the following.&lt;br /&gt;&lt;br /&gt;create table tmpTable(_name varchar(50))&lt;br /&gt;&lt;br /&gt;After creating the table, run the above code on your database. To test the procedure, uncomment the bottom line '&lt;span style="color: rgb(0, 153, 0);"&gt;exec readCSV 'Ruchira,randana,galappaththi,ruch'&lt;/span&gt;' and execute.&lt;br /&gt;&lt;br /&gt;With a little bit of effort, you can get this up and running.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-7711964006944701609?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/7711964006944701609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=7711964006944701609' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/7711964006944701609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/7711964006944701609'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/01/how-to-pass-collection-of-data-to-sql.html' title='How to pass a collection of data to SQL Server'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-1666889121030369250</id><published>2009-01-16T12:02:00.000-08:00</published><updated>2009-01-16T12:37:23.517-08:00</updated><title type='text'>Connect SQL Server Express 2005 with NetBeans IDE</title><content type='html'>Hi, Most of you Java Folks may have encountered situations where you wish to code using Java but need to connect to a Microsoft SQL Server Database. To an experienced person, this may seem trivial, but for newbies, this can be a troublesome task.&lt;br /&gt;&lt;br /&gt;Through this post, I would briefly describe how to connect to Microsoft SQL Server 2005 Express Edition using NetBeans 6.0.1 IDE.&lt;br /&gt;&lt;br /&gt;STEP 1: Download the relevant JDBC driver from the microsoft site.&lt;br /&gt;(A search on the internet will more than suffice)&lt;br /&gt;&lt;br /&gt;STEP 2: Add the driver to NetBeans IDE. This can be done as follows.&lt;br /&gt;&lt;br /&gt;On the services tab, under Databases under Drivers, you can add a new driver as follows&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_NACWt_PFgLM/SXDpzG69H9I/AAAAAAAAACY/seDzkK-vE4k/s1600-h/AddDriver1.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_NACWt_PFgLM/SXDpzG69H9I/AAAAAAAAACY/seDzkK-vE4k/s320/AddDriver1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5291986626400821202" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;On the Window, click Add and select the necessary Jar file of the driver.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/SXDqfk-V_oI/AAAAAAAAACg/Pd7vTlKOp74/s1600-h/AddDriver2.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 180px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/SXDqfk-V_oI/AAAAAAAAACg/Pd7vTlKOp74/s320/AddDriver2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5291987390382341762" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Then click Find. It will search the class name and display it as follows&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/SXDq9-GwNZI/AAAAAAAAACo/MbDN9b9tEcw/s1600-h/AddDriver3.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 242px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/SXDq9-GwNZI/AAAAAAAAACo/MbDN9b9tEcw/s320/AddDriver3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5291987912524576146" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Once the driver is installed, you can right click on it and click 'connect using'&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_NACWt_PFgLM/SXDrxQuNDCI/AAAAAAAAACw/c7p-tvxtzF8/s1600-h/AddDriver4.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_NACWt_PFgLM/SXDrxQuNDCI/AAAAAAAAACw/c7p-tvxtzF8/s320/AddDriver4.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5291988793695210530" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Then you will get the following screen&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/SXDsGSA2KQI/AAAAAAAAAC4/v7uZspoGW0Q/s1600-h/AddDriver5.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 220px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/SXDsGSA2KQI/AAAAAAAAAC4/v7uZspoGW0Q/s320/AddDriver5.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5291989154819090690" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Fill in your database name and host address. The port is usually 1433.&lt;br /&gt;&lt;br /&gt;You may try to connect after giving the correct parameters, but in some cases you may get an error saying you cant connect to the server. Under such cases, you may need to take the next step and assign a port manually.&lt;br /&gt;&lt;br /&gt;STEP 3: Assigning a port manually&lt;br /&gt;&lt;br /&gt;Go to Start-&gt;AllProgrammes-&gt;Microsoft SQL Server 2005-&gt;Configuration Tools -&gt;SQL Server Configuration Manager&lt;br /&gt;&lt;br /&gt;Then travel down to the following layer and doubl click on TCP/IP&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_NACWt_PFgLM/SXDuAI5BOqI/AAAAAAAAADA/ffaM5FsCxaM/s1600-h/AddDriver6.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 225px;" src="http://4.bp.blogspot.com/_NACWt_PFgLM/SXDuAI5BOqI/AAAAAAAAADA/ffaM5FsCxaM/s320/AddDriver6.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5291991248314383010" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After double clicking, you should get a similar picture.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_NACWt_PFgLM/SXDuXJRRY1I/AAAAAAAAADI/zPDS8aEY9rc/s1600-h/AddDriver7.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 286px; height: 320px;" src="http://4.bp.blogspot.com/_NACWt_PFgLM/SXDuXJRRY1I/AAAAAAAAADI/zPDS8aEY9rc/s320/AddDriver7.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5291991643553096530" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Select 'IP Addresses ' tab and enter some port values to the respected fileds as shown. You can use any unassigned port values for this. But generally using a higher number than the well known ports is good.&lt;br /&gt;&lt;br /&gt;Then you may need to restart your server.&lt;br /&gt;STEP 4: Writing queries on connection&lt;br /&gt;Once connection is established, you can write SQL statements and execute them via the IDE.&lt;br /&gt;&lt;br /&gt;Now you can use SQL Server 2005 Express Edition for your Java Work :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-1666889121030369250?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/1666889121030369250/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=1666889121030369250' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1666889121030369250'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1666889121030369250'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2009/01/connect-sql-server-express-2005-with.html' title='Connect SQL Server Express 2005 with NetBeans IDE'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_NACWt_PFgLM/SXDpzG69H9I/AAAAAAAAACY/seDzkK-vE4k/s72-c/AddDriver1.JPG' height='72' width='72'/><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-784213578665587551</id><published>2008-12-10T11:55:00.000-08:00</published><updated>2008-12-11T00:09:35.103-08:00</updated><title type='text'>Sending Mail Using Java</title><content type='html'>In this post, I would like to discuss how to send an e-mail using javax.mail library.&lt;br /&gt;&lt;br /&gt;I will discuss how to send an e-mail for the simplest case. ie: I present my example for a scenario without authorization and other related issues. Once you get this mail application up and running, you can extend it further. I would regard my example as a beginner's starting position.&lt;br /&gt;As I preffer to say, "Start from trivial" Dont't start your application with all complications and Network issues. You will get frustrated very soon. Once you get the trivial running, add the other requirements as features to your application.&lt;br /&gt;&lt;br /&gt;In order to get started, you need an SMTP server. (When I mean a server, it does not necessarily mean a seperate machine running as a server. You can simply run a server application on your own machine)&lt;br /&gt;An SMTP(Simple Mail Transfer Protocol) server is very similar to a post box. You pop a mail with the destination address stamped and, it takes care of delivering to the respected address.&lt;br /&gt;&lt;br /&gt;If you are using Windows XP, you can use the SMTP server that comes along with the Windows CD. However, it is to be noted that this SMTP server does not get installed by default. You need to browse the CD and Add them.(Basic procedure for anyone) Add IIS and SMTP server and click install.&lt;br /&gt;&lt;br /&gt;You can check that the installations were complete by right clicking on MyComputer-&gt;Manage&lt;br /&gt;&lt;br /&gt;If successfully installed, you would get a similar picture as below.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/SUAjPmO5E-I/AAAAAAAAAB4/12s6oI28qO8/s1600-h/1.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 226px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/SUAjPmO5E-I/AAAAAAAAAB4/12s6oI28qO8/s320/1.JPG" alt="" id="BLOGGER_PHOTO_ID_5278257514146239458" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Once you get the installation done, its time for coding.&lt;br /&gt;&lt;br /&gt;Sending a mail becomes very simple with javax.mail API.&lt;br /&gt;&lt;br /&gt;First, you need to create a Properties Object to store the&lt;br /&gt;details of your mail server. You hold the key value pairs just as a Hashtable in Java.&lt;br /&gt;&lt;br /&gt;Properties prop = new Properties();           &lt;br /&gt;prop.put("mail.smtp.host", "localhost");&lt;br /&gt;prop.put("mail.smtp.port", "25");&lt;br /&gt;&lt;br /&gt;Here, I have set the SMTP server's address to "localhost" indicating that the SMTP server is installed on my computer. You can also use "127.0.0.1" instead of "localhost". Makes no difference. The second property added is the port at which the SMTP server works. By default, these are Well known services which operate at so called "Well known ports". Port 25 is reserved for SMTP traffic.(Put for clarity. Should work even without that line. I have tested so)&lt;br /&gt;&lt;br /&gt;Next, you need to get a session. It can be done via either of the following LOC(Line Of Code)&lt;br /&gt;Note that, you need to pass the Properties object in any of the cases.&lt;br /&gt;&lt;br /&gt;Session session = Session.getInstance(prop, null);&lt;br /&gt;Session session = Session.getInstance(prop);&lt;br /&gt;&lt;br /&gt;On the firsr LOC, we have a null object passed on to the overloaded method getInstance()&lt;br /&gt;The second parameter is used when the mail server requires authentication. You need to pass an Authenticator object as the second parameter.&lt;br /&gt;If the authentication system used by the SMTP server is password authentication(there may be other authentication systems other than password authentication), you can pass in a "PasswordAuthentication" object in the following way.&lt;br /&gt;&lt;br /&gt;Session session = Session.getInstance(prop, new      PasswordAuthentication("accountName","password"));&lt;br /&gt;&lt;br /&gt;As in our very basic example, it is enough to use the second option as we do not bother about authentication. Make sure that you have switched off authentication mechanisms on your SMTP server. It can be easily found if you mess a little with the settings. Windows SMTP server by default allows annonymous users to send mail via the Server.&lt;br /&gt;&lt;br /&gt;Here is how it appears on Windows SMTP server&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_NACWt_PFgLM/SUAu3PJgQ1I/AAAAAAAAACA/GhNjQHB2Exk/s1600-h/2.JPG"&gt;&lt;img style="cursor: pointer; width: 286px; height: 320px;" src="http://3.bp.blogspot.com/_NACWt_PFgLM/SUAu3PJgQ1I/AAAAAAAAACA/GhNjQHB2Exk/s320/2.JPG" alt="" id="BLOGGER_PHOTO_ID_5278270289772299090" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_NACWt_PFgLM/SUAvI77Do6I/AAAAAAAAACI/aLA_aES_xqw/s1600-h/3.JPG"&gt;&lt;img style="cursor: pointer; width: 319px; height: 320px;" src="http://1.bp.blogspot.com/_NACWt_PFgLM/SUAvI77Do6I/AAAAAAAAACI/aLA_aES_xqw/s320/3.JPG" alt="" id="BLOGGER_PHOTO_ID_5278270593849074594" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Our Actual Message to send is used by an object of&lt;br /&gt;&lt;br /&gt;javax.mail.internet.MimeMessage&lt;br /&gt;&lt;br /&gt;We can create an object by the following LOC(Assume that you import javax.mail.internet package)&lt;br /&gt;&lt;br /&gt;MimeMessage mimeMessage = new MimeMessage(session);&lt;br /&gt;&lt;br /&gt;Then we need to set the TO and FROM address. The following LOC does them. They are very much self explained&lt;br /&gt;&lt;br /&gt;InternetAddress from = new InternetAddress("anything@anything.com");&lt;br /&gt;InternetAddress to = new InternetAddress("sendersAddress@gmail.com");&lt;br /&gt;mimeMessage.setFrom(from);&lt;br /&gt;mimeMessage.addRecipient(Message.RecipientType.TO, to);&lt;br /&gt;&lt;br /&gt;You can send the messages to any address. I just used well known domain for clarity.&lt;br /&gt;A serious issue with SMTP is that it accepts any address which is given as the sender. So you can add any address as the senders address and it would show up as that person actually sent it.&lt;br /&gt;&lt;br /&gt;The subject and message could be set using the following LOC&lt;br /&gt;&lt;br /&gt;mimeMessage.setSubject("TEST MAIL");&lt;br /&gt;mimeMessage.setText("Hello World! This is Coooooooll");&lt;br /&gt;&lt;br /&gt;Then sending the mail is done by the Transport Class's static method&lt;br /&gt;&lt;br /&gt;Transport.send(mimeMessage);&lt;br /&gt;&lt;br /&gt;You can write a simple programme with the above mentioned LOC and try it. Make sure you add try catch blocks! I removed them as they just obstruct the learnability of new Code.&lt;br /&gt;&lt;br /&gt;The following is a simple programme which I wrote. Just try to run it on your computer.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;package Main;&lt;br /&gt;import java.util.Properties;&lt;br /&gt;import java.util.logging.Level;&lt;br /&gt;import java.util.logging.Logger;&lt;br /&gt;import javax.mail.Message;&lt;br /&gt;import javax.mail.MessagingException;&lt;br /&gt;import javax.mail.Session;&lt;br /&gt;import javax.mail.Transport;&lt;br /&gt;import javax.mail.internet.AddressException;&lt;br /&gt;import javax.mail.internet.InternetAddress;&lt;br /&gt;import javax.mail.internet.MimeMessage;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;*&lt;br /&gt;* @author Ruchira&lt;br /&gt;*/&lt;br /&gt;public class SMTP_Sender {&lt;br /&gt;  &lt;br /&gt;   public static void main(String[] ar){&lt;br /&gt;       try {&lt;br /&gt;           &lt;span style="color: rgb(255, 0, 0);"&gt;new SMTP_Sender().send();&lt;/span&gt;&lt;br /&gt;       } catch (AddressException ex) {&lt;br /&gt;           Logger.getLogger(SMTP_Sender.class.getName()).log(Level.SEVERE, null, ex);&lt;br /&gt;       } catch (MessagingException ex) {&lt;br /&gt;           Logger.getLogger(SMTP_Sender.class.getName()).log(Level.SEVERE, null, ex);&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void send() throws AddressException, MessagingException{&lt;br /&gt;      &lt;br /&gt;           &lt;span style="color: rgb(255, 0, 0);"&gt;Properties prop = new Properties();            &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            prop.put("mail.smtp.host", "localhost");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            prop.put("mail.smtp.port", "25");          &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            Session session = Session.getInstance(prop);&lt;/span&gt;&lt;br /&gt;            &lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            MimeMessage mimeMessage = new MimeMessage(session);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            InternetAddress from = new InternetAddress("from@ruchira.com");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            InternetAddress to = new InternetAddress("to@gmail.com");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            mimeMessage.setFrom(from);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            mimeMessage.addRecipient(Message.RecipientType.TO, to);&lt;/span&gt;&lt;br /&gt;            &lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            mimeMessage.setSubject("TEST MAIL");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            mimeMessage.setText("Hello World! This is Coooooooll");&lt;/span&gt;&lt;br /&gt;                        &lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            Transport.send(mimeMessage);                       &lt;/span&gt;&lt;br /&gt;          &lt;br /&gt;          &lt;br /&gt;   }&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;hr/&gt;&lt;br /&gt;&lt;br /&gt;Compile this and try to run. If you set the destination address outside your domain, most probably you would get an Error saying something related to "Relay".&lt;br /&gt;By Default, SMTP servers are not privileged to send mail outside its domain for security issues. But for our app, we can safely remove the relaying settings.&lt;br /&gt;&lt;br /&gt;It can be done by clicking on the "Relay" button under "Relay restriction" of the above picture. Once you click that, you would get a similar picture as below(Your address 127.0.0.1 is Not added by default), where you can add your IP address to allow sending mails from your machine to other domains by clicking Add button.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_NACWt_PFgLM/SUAypuZDGvI/AAAAAAAAACQ/qJunZqjdpTw/s1600-h/4.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 318px;" src="http://4.bp.blogspot.com/_NACWt_PFgLM/SUAypuZDGvI/AAAAAAAAACQ/qJunZqjdpTw/s320/4.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5278274455687338738" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Once added, it would show up as above picture, where you have given privilege for your computer only.&lt;br /&gt;&lt;br /&gt;Now try and run the above application and hopefully you will be able to send tha mail.&lt;br /&gt;&lt;br /&gt;NOTE: Even though you sent the mail. It may be spammed by yahoo or gmail. So, instead of any senders address try using a valid username of a reputed mail server.&lt;br /&gt;&lt;br /&gt;Have fun!!!!!!!!!!!!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-784213578665587551?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/784213578665587551/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=784213578665587551' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/784213578665587551'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/784213578665587551'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2008/12/sending-mail-using-java.html' title='Sending Mail Using Java'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_NACWt_PFgLM/SUAjPmO5E-I/AAAAAAAAAB4/12s6oI28qO8/s72-c/1.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-1657958245591638438</id><published>2008-11-28T23:03:00.000-08:00</published><updated>2009-05-04T10:54:25.573-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network sniffer'/><category scheme='http://www.blogger.com/atom/ns#' term='sniffer'/><category scheme='http://www.blogger.com/atom/ns#' term='build network monitoring tool'/><category scheme='http://www.blogger.com/atom/ns#' term='Build your own Network sniffer'/><category scheme='http://www.blogger.com/atom/ns#' term='network traffic analyzer'/><title type='text'>Build your own Network sniffer</title><content type='html'>Recently, I ve been developing a tool to monitor the Network Traffic as an assignment. Here, I wish to share my experience with all of you who are interested in building your own Sniffer.&lt;br /&gt;&lt;br /&gt;Prerequisites : Java Programming capability, Knowledge on OOP(Object Oriented     Programming) basics&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;My Environment:&lt;br /&gt;&lt;br /&gt;I used the libraries specified for Java which is widely available.&lt;br /&gt;I ran my application on Windows XP only. But the libraries can be easily integrated with Linux based systems.&lt;br /&gt;I used NetBeans 6.1 version for development activities. But any other java IDE would do&lt;br /&gt;&lt;br /&gt;In setting up the environment, first you need to download Jpcap jar found at &lt;a&gt;http://sourceforge.net/projects/jpcap&lt;/a&gt;&lt;br /&gt;Once you download this, you have to add this to your NetBeans project.&lt;br /&gt;It can be done as follows.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_NACWt_PFgLM/STEAZb2CKqI/AAAAAAAAAAg/eiUR92juiCs/s1600-h/pic1.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://3.bp.blogspot.com/_NACWt_PFgLM/STEAZb2CKqI/AAAAAAAAAAg/eiUR92juiCs/s320/pic1.JPG" alt="" id="BLOGGER_PHOTO_ID_5273997075598682786" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/STEAqGsGmRI/AAAAAAAAAAo/B3I39xxVBsw/s1600-h/pic2.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/STEAqGsGmRI/AAAAAAAAAAo/B3I39xxVBsw/s320/pic2.JPG" alt="" id="BLOGGER_PHOTO_ID_5273997361977661714" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_NACWt_PFgLM/STEAy1S0JJI/AAAAAAAAAAw/FKO0OR4dQkM/s1600-h/pic3.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://3.bp.blogspot.com/_NACWt_PFgLM/STEAy1S0JJI/AAAAAAAAAAw/FKO0OR4dQkM/s320/pic3.JPG" alt="" id="BLOGGER_PHOTO_ID_5273997511927014546" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/STEA5oTwDcI/AAAAAAAAAA4/dSgN__KdcYs/s1600-h/pic4.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/STEA5oTwDcI/AAAAAAAAAA4/dSgN__KdcYs/s320/pic4.JPG" alt="" id="BLOGGER_PHOTO_ID_5273997628700364226" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/STEA_Zu9YXI/AAAAAAAAABA/sYHW5RsWcdY/s1600-h/pic5.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/STEA_Zu9YXI/AAAAAAAAABA/sYHW5RsWcdY/s320/pic5.JPG" alt="" id="BLOGGER_PHOTO_ID_5273997727867167090" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_NACWt_PFgLM/STEBGdseEmI/AAAAAAAAABI/iQer5RhcBwM/s1600-h/pic6.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://3.bp.blogspot.com/_NACWt_PFgLM/STEBGdseEmI/AAAAAAAAABI/iQer5RhcBwM/s320/pic6.JPG" alt="" id="BLOGGER_PHOTO_ID_5273997849189552738" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_NACWt_PFgLM/STEBaQC82TI/AAAAAAAAABQ/rClEVWiQfwQ/s1600-h/pic7.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_NACWt_PFgLM/STEBaQC82TI/AAAAAAAAABQ/rClEVWiQfwQ/s320/pic7.JPG" alt="" id="BLOGGER_PHOTO_ID_5273998189123131698" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/STEBgD-WFTI/AAAAAAAAABY/epD4T_7WZPs/s1600-h/pic8.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/STEBgD-WFTI/AAAAAAAAABY/epD4T_7WZPs/s320/pic8.JPG" alt="" id="BLOGGER_PHOTO_ID_5273998288961803570" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After adding the Jar file to the project, you need to download the WinPCap driver. It can be easily downloaded from &lt;a&gt;http://www.winpcap.org/&lt;/a&gt;&lt;br /&gt;It is required to get low level networking access regarding packets.&lt;br /&gt;As for Unix users, there is a version named libpcap which can be used instead.&lt;br /&gt;NOTE: In running built applications, you must allow administrative rights for the programme. Otherwise the driver may not be able to get the necessary information. As for Unix users, you need to run your programme as superuser.&lt;br /&gt;&lt;br /&gt;The capturing of packets can be done via a simple set of commands.&lt;br /&gt;For the sake of simplicity, I would just present the most basic commands which would enable you to get up and running. The details of the commands are available at the Jpcap website's tutorial found at &lt;a&gt;http://netresearch.ics.uci.edu/kfujii/jpcap/doc/tutorial/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Write a java file and include the following code on the main method and run the class.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;NetworkInterface[] interfaces=JpcapCaptor.getDeviceList();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;NOTE: &lt;span style="color: rgb(255, 0, 0);"&gt;Be careful when using the class for the first time. There is a class with the same name undet java.net package. So, be careful to use jpcap.NetworkInterface[] under the package jpcap.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;By using the static method "getDeviceList()" of class "JpcapCaptor", you can get an array of NetworkInterfaces fixed on your computer. The number depends on the computer you have. In my case, I get only one.(The Ethernet interface). But in other computers, you might get more.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;Then you need to open a selected interface to start capturing packets.&lt;br /&gt;You can do it in the following manner&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;JpcapCaptor captor=JpcapCaptor.openDevice(interfaces[0], 65535, true, 20);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here I'm passing the wanted NetworkInterface as the 1st element of the array returned(In my case I get an array of length 1). Please reffer to the tutorial for precise information on the other parameters.(It does not depend on the machine, so it should work on your machine as well)&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;captor.processPacket(-1, new PacketPrinter());&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The above Line of Code is used in actually capturing the packet. It accepts two paramenters. The first one saying how many packets to capture. Here I have put -1 which would mean infinitely. That means, I keep on capturing packets indefinitely.&lt;br /&gt;&lt;br /&gt;The next parameter is an object which needs to implement the interface "PacketReceiver", an interface which is defined by jpcap library.&lt;br /&gt;This interface has one method with the method signature.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;public interface PacketReceiver{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt; public void receivePacket(Packet packet);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You need to write a class which implements this interface. Thus you need to implement the method in your class.&lt;br /&gt;&lt;br /&gt;Here is my example:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;public class PacketPrinter implements PacketReceiver{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt; public void receivePacket(Packet packet) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;   System.out.println(packet);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;My class PacketPrinter just has one method, and I'm implementing the interface here.&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;Now, compile this code and run the application. You should get the description of all the packets captured on your Standard output.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Filtering packets can be done via the following Line of Code.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;NetworkInterface[] interfaces=JpcapCaptor.getDeviceList();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;JpcapCaptor captor=JpcapCaptor.openDevice(interfaces[0], 65535, true, 20);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;captor.setFilter("tcp", true);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;captor.loopPacket(-1, new PacketPrinter());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;captor.close();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The above code can be used to filter TCP packets only. If you need only other packets except TCP packets, then you can state "false" as the second parameter above.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;I'm sure, this is going to get to up and running with your development as soon as possible. It is up to you to develop a software GUI tool which would satisfy your needs. If you need any help please do not hesitate to mail me.&lt;br /&gt;ruchiram4@gmail.com&lt;br /&gt;&lt;br /&gt;The following displays the Tool I prepared. It has special filtering capabilities and Graph to show network traffic.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_NACWt_PFgLM/STEPvu8D_3I/AAAAAAAAABg/LDtMua5Fdpc/s1600-h/1.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 245px;" src="http://1.bp.blogspot.com/_NACWt_PFgLM/STEPvu8D_3I/AAAAAAAAABg/LDtMua5Fdpc/s320/1.JPG" alt="" id="BLOGGER_PHOTO_ID_5274013951355780978" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_NACWt_PFgLM/STEP595jB2I/AAAAAAAAABo/ONXhQdAB5IU/s1600-h/2.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 233px;" src="http://2.bp.blogspot.com/_NACWt_PFgLM/STEP595jB2I/AAAAAAAAABo/ONXhQdAB5IU/s320/2.JPG" alt="" id="BLOGGER_PHOTO_ID_5274014127170455394" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_NACWt_PFgLM/STEQCZRYVyI/AAAAAAAAABw/-qIySSRaEmI/s1600-h/3.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 233px;" src="http://1.bp.blogspot.com/_NACWt_PFgLM/STEQCZRYVyI/AAAAAAAAABw/-qIySSRaEmI/s320/3.JPG" alt="" id="BLOGGER_PHOTO_ID_5274014271957128994" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Due to the request of some, I would like to add some functioning code segment for this.&lt;br /&gt;&lt;br /&gt;Please copy the following Classes and try to run the code.&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * To change this template, choose Tools | Templates&lt;br /&gt; * and open the template in the editor.&lt;br /&gt; */&lt;br /&gt;package ruch.net;&lt;br /&gt;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.util.logging.Level;&lt;br /&gt;import java.util.logging.Logger;&lt;br /&gt;import jpcap.JpcapCaptor;&lt;br /&gt;import jpcap.NetworkInterface;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; *&lt;br /&gt; * @author Ruchira&lt;br /&gt; */&lt;br /&gt;public class SnifferExample {&lt;br /&gt;&lt;br /&gt;    JpcapCaptor captor;&lt;br /&gt;    NetworkInterface[] interfaceList;&lt;br /&gt;    &lt;br /&gt;    //Change this number according to the Network Interface which you wish to Sniff&lt;br /&gt;    private static final int interfaceNumber=1;&lt;br /&gt;&lt;br /&gt;    public static void main(String[] str) {&lt;br /&gt;        SnifferExample sniff=new SnifferExample();&lt;br /&gt;        sniff.printNetworkInterfaceList();&lt;br /&gt;        try {&lt;br /&gt;            sniff.capture();&lt;br /&gt;        } catch (IOException ex) {&lt;br /&gt;            Logger.getLogger(SnifferExample.class.getName()).log(Level.SEVERE, null, ex);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * Run this method first and it will list out the available network interfaces in your computer&lt;br /&gt;     * All of the interfaces will be put into an array (interfaceList)&lt;br /&gt;     */&lt;br /&gt;    public void printNetworkInterfaceList() {&lt;br /&gt;&lt;br /&gt;        interfaceList = JpcapCaptor.getDeviceList();&lt;br /&gt;&lt;br /&gt;        System.out.println("Number of Network Interfaces Found :"+interfaceList.length);&lt;br /&gt;        &lt;br /&gt;        for (int i = 0; i &lt; interfaceList.length; i++) {&lt;br /&gt;            System.out.println("Index :" + i + ", Network Device Name :" + interfaceList[i].name + ", Description :" +&lt;br /&gt;                    " " + interfaceList[i].description);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void capture() throws IOException {   &lt;br /&gt;        &lt;br /&gt;        captor=JpcapCaptor.openDevice(interfaceList[interfaceNumber], 65535, true, 20000);&lt;br /&gt;        captor.loopPacket(-1, new PacketPrinter());&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr/&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * To change this template, choose Tools | Templates&lt;br /&gt; * and open the template in the editor.&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;package ruch.net;&lt;br /&gt;&lt;br /&gt;import jpcap.PacketReceiver;&lt;br /&gt;import jpcap.packet.Packet;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; *&lt;br /&gt; * @author Ruchira&lt;br /&gt; */&lt;br /&gt;public class PacketPrinter implements PacketReceiver{&lt;br /&gt;&lt;br /&gt;    public void receivePacket(Packet pkt) {&lt;br /&gt;        System.out.println("Paket :"+pkt.toString());&lt;br /&gt;    }   &lt;br /&gt;   &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;hr/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-1657958245591638438?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/1657958245591638438/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=1657958245591638438' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1657958245591638438'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1657958245591638438'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2008/11/build-your-own-network-sniffer.html' title='Build your own Network sniffer'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_NACWt_PFgLM/STEAZb2CKqI/AAAAAAAAAAg/eiUR92juiCs/s72-c/pic1.JPG' height='72' width='72'/><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-2763620156701338739</id><published>2008-11-23T10:36:00.000-08:00</published><updated>2010-03-01T01:58:43.189-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='run executable java programme'/><category scheme='http://www.blogger.com/atom/ns#' term='run application from java'/><category scheme='http://www.blogger.com/atom/ns#' term='java runtime'/><title type='text'>Run a programme by java application</title><content type='html'>You may have encountered situations where you wish to run a programme say Web Browser (FireFox) from your Java programme.&lt;br /&gt;It is very simple&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Find the location of the actual executable of the programme.&lt;/li&gt;&lt;li&gt;As in the case of FireFox Web Browser, the actual executable file is placed at                C:\Program Files\Mozilla Firefox\firefox.exe&lt;/li&gt;&lt;li&gt;You can use the following code to run it from your Java application&lt;/li&gt;&lt;li&gt;Runtime runtime = Runtime.getRuntime();&lt;br /&gt;runtime.exec("K:/Program Files/Mozilla Firefox/firefox.exe");&lt;/li&gt;&lt;li&gt;(YOU MUST USE A TRY CATCH BLOCK. Just excluded them for clarity)&lt;/li&gt;&lt;li&gt;ENJOY programming :-)&lt;/li&gt;&lt;/ul&gt;Here is a great tip if you wish to launch the native applications for specific tasks such as sending a mail, opening the native web browser.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public static void main(String[] args) {&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;      &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        Desktop dt = Desktop.getDesktop();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                dt.browse(new URI("http://yahoo.com"));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            } catch (URISyntaxException ex) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        } catch (IOException ex) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    }&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-2763620156701338739?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/2763620156701338739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=2763620156701338739' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/2763620156701338739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/2763620156701338739'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2008/11/run-programme-by-java-application.html' title='Run a programme by java application'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-6560471880601615179</id><published>2008-11-03T05:48:00.000-08:00</published><updated>2008-11-03T07:16:52.738-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='flush method'/><category scheme='http://www.blogger.com/atom/ns#' term='writing output to file'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Buffered Writer issues'/><title type='text'>Java Buffered Writer Issue</title><content type='html'>&lt;ul&gt;&lt;li&gt;Using Buffered Writers is an efficient way to write the output to a file where hard disk accesses are costly.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;The main idea behind the Buffered Objects is(Here it is the buffered writer) having a buffer which is, writing the output to a memory location in the computer's main memory(which is faster than writing to hard disk). And then once the Buffer is filled with enough data, the whole buffer is written to the hard disk.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;However, this can bring up some issues which are difficult to find. One of such issues is my attempt to write to a text file using a buffered writer. I used the following code.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;          &lt;span style="color: rgb(255, 0, 0);"&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;FileWriter&lt;/span&gt; writer;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;           &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;BufferedWriter&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;bWriter&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;           &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;PrintWriter&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;pwriter&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            writer = new &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;FileWriter&lt;/span&gt;(new File("./output.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;txt&lt;/span&gt;");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;bWriter&lt;/span&gt; = new &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;BufferedWriter&lt;/span&gt;(writer);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;pwriter&lt;/span&gt;=new &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;PrintWriter&lt;/span&gt;(&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;bWriter&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;           int i=0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;           while(i&lt;1000){&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;                &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_12"&gt;pwriter&lt;/span&gt;.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_13"&gt;println&lt;/span&gt;(i);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;                i++;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;This should seem to print the numbers 0 to 999 each on a new line. But practically it printed only up to 658.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;The cause for the issue was the use of Buffers for printing the output. The Buffered writer only writes to the disk once the buffer is full. The reason is that after printing line 658, the buffer does not become full till 999. So, there is still content left in the buffer which had not been written to disk.&lt;/li&gt;&lt;li&gt;To provide a better view of the example I would present a real world scenario which is similar.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Suppose a bus(analogous to the Buffered writer) has seating for 50 people. The bus moves from A to B only when the seats are full. So, if we were to transport 120 people from A to B, it would be as follows.&lt;/li&gt;&lt;li&gt;Trip 1: passengers 1 to 50 will be transported to B and Bus returns to A&lt;/li&gt;&lt;li&gt;Trip 2: passengers 51 to 100 are transported to B and Bus returns to A&lt;/li&gt;&lt;li&gt;Trip 3: passengers 101 to 120 get aboard the bus, but the bus does not transport them to B because the bus is not full. The third trip does not occur :-(&lt;br /&gt;&lt;/li&gt;&lt;li&gt;So, in such scenarios, we must force the bus to make a trip even though the bus is not full, because our number one objective is to transport all the 120 people from A to B. Efficiency and fuel cost would be number two on our list of importance.&lt;/li&gt;&lt;/ul&gt;In Java, you have a method to overcome the issue. Buffered Writers come with a method 'flush()'. When you invoke this method on the object, it does not care whether the buffer is full or not. It makes a disk write immediately.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-6560471880601615179?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/6560471880601615179/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=6560471880601615179' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/6560471880601615179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/6560471880601615179'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2008/11/java-buffered-writer-issue.html' title='Java Buffered Writer Issue'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-7534499517215203765</id><published>2008-10-08T13:00:00.000-07:00</published><updated>2008-10-08T14:04:01.847-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Janaka Perera'/><category scheme='http://www.blogger.com/atom/ns#' term='tribute Janaka Perera'/><title type='text'>Tribute to a National hero</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_NACWt_PFgLM/SO0SqI5_MiI/AAAAAAAAAAM/mOOMw0pRqWg/s1600-h/janaka.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 195px; height: 319px;" src="http://3.bp.blogspot.com/_NACWt_PFgLM/SO0SqI5_MiI/AAAAAAAAAAM/mOOMw0pRqWg/s320/janaka.jpg" alt="" id="BLOGGER_PHOTO_ID_5254876855365743138" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Sincere condolences for the assassination of late Major General Janaka Perera who served our nation as a true hero.&lt;br /&gt;&lt;br /&gt;Major General Janaka Perera was one of the exceptional figures and one of the most successful military leaders in the history of Sri Lankan battlefield. During his military career, his leadership and endeavors to rescue the homeland from the terrorists are well known and praised by every peaceloving citizen.&lt;br /&gt;&lt;br /&gt;His leadership in rescuing the Jaffna peninsula at a crucial and decisive situation is one of his most successful and well known operations.&lt;br /&gt;&lt;br /&gt;Major General Janaka Perera also led the army in defeating the terrorist attacks of Weli Oya where his skills and intelligence were used effectively to overpower the terrorists. There were more than 300 terrorists killed and minimum damage to the army. A village was later named as Janakapura in Weli Oya for his contribution.&lt;br /&gt;&lt;br /&gt;He was awarded the medals of honour 'Rana Wickrama Padakkama','Rana Sura Padakkama', 'Vishishta Seva Vibhushanaya','Uttama Seva Padakkama'&lt;span style="text-decoration: underline;"&gt;&lt;br /&gt;&lt;/span&gt; for his devotion and commitment in saving motherland.&lt;br /&gt;&lt;br /&gt;       Major General Janaka Perera retired in 2001 and was appointed as the Sri Lankan High Commissioner to Australia and later as the Sri Lanka's Ambassador to Indonesia.&lt;br /&gt;&lt;br /&gt;       After retiring from his diplomatic career, he entered into politics after joining the United National Party(UNP) and was selected as the candidate for the Chief Minister of North Central Province Municipal Council Election 2008. He received the highest number of votes in the North Central Province Municipal Council Election and was elected as the Opposition Leader of North Central Province Municipal Council.&lt;br /&gt;&lt;br /&gt;       His untimely death was caused by a suicide bomber who blew himself at an opening ceremony of the party held at Anuradhapura. Major General Janaka Perera was killed along with his wife and 27 others.&lt;br /&gt;&lt;br /&gt;       As a nation, we salute you for the bravery and leadership you gave in rescuing our country from the clutches of the terrorists.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-7534499517215203765?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/7534499517215203765/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=7534499517215203765' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/7534499517215203765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/7534499517215203765'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2008/10/tribute-to-national-hero.html' title='Tribute to a National hero'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_NACWt_PFgLM/SO0SqI5_MiI/AAAAAAAAAAM/mOOMw0pRqWg/s72-c/janaka.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-3923207484559301878</id><published>2008-10-03T11:39:00.000-07:00</published><updated>2008-10-03T11:41:01.872-07:00</updated><title type='text'>Java</title><content type='html'>Hi folks,&lt;br /&gt;&lt;br /&gt;I will use this area to share my experience related to Java&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-3923207484559301878?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/3923207484559301878/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=3923207484559301878' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/3923207484559301878'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/3923207484559301878'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2008/10/java.html' title='Java'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5313762687362102870.post-1013620851897232308</id><published>2008-10-03T11:35:00.000-07:00</published><updated>2008-10-03T11:39:01.327-07:00</updated><title type='text'>Welcome Folks</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Welcome folks to my personnel web blog.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I am Ruchira Randana, an undergraduate of University of Moratuwa.&lt;br /&gt;Currently I am engaged in Level -4 Computer Science and Engineering.&lt;br /&gt;I hope to use my blog to share my experiences with all of you out there.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5313762687362102870-1013620851897232308?l=ruchiram4.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ruchiram4.blogspot.com/feeds/1013620851897232308/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5313762687362102870&amp;postID=1013620851897232308' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1013620851897232308'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5313762687362102870/posts/default/1013620851897232308'/><link rel='alternate' type='text/html' href='http://ruchiram4.blogspot.com/2008/10/welcome-folks.html' title='Welcome Folks'/><author><name>ruchira</name><uri>http://www.blogger.com/profile/01144355522403055482</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
