EMMA- because you need to check the code coverage

EMMA is a free open-source Java code coverage tool. The keyword here is free, as I am not aware of many free code coverage tool. Moreover, I am not sure if people would like to spend money on a code coverage tool, especially if we are working on small applications. It is relatively easier to check the code coverage in small applications, for example, if you run the application in debug mode on eclipse, you can very well see line by line which code is getting executed. But if your application is a multi thousand line, this approach fails. In that case you would need a proper code coverage tool, and if you are getting one for free, nothing like it.

One question we forgot to ask is, why do I need to check the code coverage at all. Say, we have an application where we need to get user information and this is done using three different forms which are handled by 3 servlets at the back-end. Now someone came up with an idea that instead of three forms we can have 2 or 1. The idea was good and it was implemented, design got changed, test suite got changed, code got changed as per the new design. But there is a major possibility that some code which was part of earlier design did not get remove. It was old code, so nobody bothered as it it will not be used any more. At then, we end up shipping code which was not required. More changes to the application and more such code. So it is better to check what all is required or not.

Another thing might be, that the code shown by the tool as unused is actually useful code, but that did not get executed while running the test suite. That implies, your test suite is not complete enough.

Now if you are convinced, here is your quick start link – Quick Start with EMMA

Artificially Intelligent

Artificial Intelligence or AI as it is commonly termed was one of my favorite subject while in college. Inspired by movies like ‘I,Robot’ I used to think that it might be possible to create machines which can think on its own.

No I am not thinking about hardcore AI right now, I am thinking about usage of AI in day today web applications. This is nothing new, one example is, when you go for shopping on some website, after you choose or check a product, it shows you a list of related products. That is some sort of intelligence.

First things first, what do we think intelligence is. Telling 2+2=4? That’s mathematics. Reasoning, analysis, common sense. These can be categorized as intelligence. So can a machine or software or an application reason. Not on its own for sure. It needs someone to code how to reason. A very simple example is lets say I show a sequence of numbers to a human, 1,2,3,4 and then I show 1,3,5,7 and then 1,4,7,10. he would be easily able to understand the pattern and will be able to tell the next in series. But can a machine do the same. Not unless someone code it that way. Does that mean the concept of ‘thinking machines’ would be possible only in fiction?

Coming back to my original point of adding some intelligence to the web applications, what I mean here is an application, smart enough to guess what a user wants from it. Or in simple words, helping user. Shopping cart is a good example as already mentioned. You search for a book on AI and it will show related books. Let’s take the same example in real world. You go to the book shop, ask for a book on AI, the shopkeeper will show you books on AI. And if he is a good salesman, will also suggest the best buy based on his past experience of sales of various AI books. You go next time again ask for the AI books. Third time you go, probability is that even before you ask, he will show you the latest arrivals in AI section. That’s intelligence. This can easily be replicated in web applications.

So think that next time you go to a web site and it just dishes up whatever you need without even asking.

DWR: Direct Web Remoting

Notes from my Recent Research on DWR

DWR is an open source Java library which helps client side AJAX code to call and use Server side Java code as if it is available locally. The communication can be two way, on one hand, JavaScript can call Java methods and on the other hand Java can call JavaScript methods (Reverse AJAX)

For getting started download the latest jar from http://directwebremoting.org/dwr/download

DWR consists of two main parts:
A Java Servlet running on the server that processes requests and sends responses back to the browser.

Let’s create a simple DWR application.

Step1: Add these lines to web.xml

<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>


<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

Step 2: Create dwr.xml

<!DOCTYPE dwr PUBLIC
“-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN”
“http://getahead.org/dwr/dwr20.dtd”>

<dwr>
<allow>
<create creator="new" javascript="JDate">
<param name="class" value="java.util.Date"/>
</create>
<create creator="new" javascript="Employee">
<param name="class" value="testPkg.EmployeeBean"/>
</create>
</allow>
</dwr>

Step 3. Create EmployeeBean. Java

package testPkg;

public class EmployeeBean {

private static String name;
private static String EmployeeNum;
private static String Address;

public String getAddress() {
return Address;
}
public void setAddress(String address) {
Address = address;
}
public String getEmployeeNum() {
return EmployeeNum;
}
public void setEmployeeNum(String employeeNum) {
EmployeeNum = employeeNum;
}
public String getName() {
System.out.println(“return:”+name);
return name;
}
public void setName(String name) {
System.out.println(“called with:”+name);
this.name = name;
System.out.println(“now:”+this.name);
}
}

Step 4: Here is the final HTML code (change the path for JS files as per the project)

<html>
<head>
<script type='text/javascript'
src='/[Path]/dwr/interface/Employee.js'></script>
<script type='text/javascript' src='/[Path]/dwr/engine.js'></script>
<script type='text/javascript' src='/[Path]/dwr/util.js'></script>
</head>
<body>
First Set the Employee Name:
<input type="textbox" id="setname" value="Name Here" />
<input type="button"
onclick='Employee.setName(document.getElementById("setname").value, reply8);'
value="Set Name" />
<script type='text/javascript'>
var reply8 = function(data)
{
if (data != null && typeof data == 'object') alert(dwr.util.toDescriptiveString(data, 2));
else alert("data set!");
}
</script>
<br></br>
<input type='button' onclick='Employee.getName(reply);' value='Get Name'
title='Calls Employee.getName(). View source for details.' />
<script type='text/javascript'>
var reply = function(data)
{
if (data != null && typeof data == 'object') alert(dwr.util.toDescriptiveString(data, 2));
else alert("set data was: "+data);
}
</script>
</body>
</html>

Now go to your dwr.html and see the magic

http://directwebremoting.org/

The Beginning.. Again

In last four years, Kamalmeet.com has gone down twice. But the important thing is, it has came back each time from the ashes like a phoenix. Already twice, and the alchemist said that if something happens once, it will rarely happen again, but if it has happened twice, it will definitely happen the third time. But then, should I be worried..

Jahan Main Ahl-e-Imaan Soorat-e-Khursheed Jeete Hain
Idhar Doobe, Udhar Nikle, Udhar Doobe, Idhar Nikle

(People with faith and confidence live and shine like sun
if they go down at one place, they will come up from other)