Posts

Showing posts from 2008

Sending Mail Using Java

Image
In this post, I would like to discuss how to send an e-mail using javax.mail library. 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. 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. 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) 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

Build your own Network sniffer

Image
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. Prerequisites : Java Programming capability, Knowledge on OOP(Object Oriented Programming) basics My Environment: I used the libraries specified for Java which is widely available. I ran my application on Windows XP only. But the libraries can be easily integrated with Linux based systems. I used NetBeans 6.1 version for development activities. But any other java IDE would do In setting up the environment, first you need to download Jpcap jar found at http://sourceforge.net/projects/jpcap Once you download this, you have to add this to your NetBeans project. It can be done as follows. After adding the Jar file to the project, you need to download the WinPCap driver. It can be easily downloaded from http://www.winpcap.org/ It is required to get low level networking access regarding packets. As for

Run a programme by java application

You may have encountered situations where you wish to run a programme say Web Browser (FireFox) from your Java programme. It is very simple Find the location of the actual executable of the programme. As in the case of FireFox Web Browser, the actual executable file is placed at C:\Program Files\Mozilla Firefox\firefox.exe You can use the following code to run it from your Java application Runtime runtime = Runtime.getRuntime(); runtime.exec("K:/Program Files/Mozilla Firefox/firefox.exe"); (YOU MUST USE A TRY CATCH BLOCK. Just excluded them for clarity) ENJOY programming :-) 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. public static void main(String[] args) { Desktop dt = Desktop.getDesktop(); try { try { dt.browse(new URI("http://yahoo.com")); } catch (URISyntaxException ex) { Lo

Java Buffered Writer Issue

Using Buffered Writers is an efficient way to write the output to a file where hard disk accesses are costly. 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. 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. FileWriter writer; BufferedWriter bWriter ; PrintWriter pwriter ; writer = new FileWriter (new File("./output. txt "); bWriter = new BufferedWriter (writer); pwriter =new PrintWriter ( bWriter ); int i=0; while(i<1000){ pwriter . println (i); i++;

Tribute to a National hero

Image
Sincere condolences for the assassination of late Major General Janaka Perera who served our nation as a true hero. 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. His leadership in rescuing the Jaffna peninsula at a crucial and decisive situation is one of his most successful and well known operations. 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. He was awarded the medals of honour 'Rana Wickrama Padakkama','Rana Sura Padakkama', '

Java

Hi folks, I will use this area to share my experience related to Java

Welcome Folks

Welcome folks to my personnel web blog. I am Ruchira Randana, an undergraduate of University of Moratuwa. Currently I am engaged in Level -4 Computer Science and Engineering. I hope to use my blog to share my experiences with all of you out there.