Archive

Archive for March, 2007

How to look smart before Java developers? — A manager’s guide

March 30th, 2007 Arun Manivannan No comments

Funny as hell. Enjoy.

  1. Before the initial project meeting go to jcp.org. List all JSR’s learn some (5 are enough in general) numbers and headers.. If you have to do with more advanced developers – also read the abstract. Mention the JSRs during the meeting and enjoy the impact.
  2. If you project is going to be a realized with Java EE: Emphasize the verbosity of Java. Point to elegant languages like Python, or Ruby. (it is not necessary to know these languages – it is not very likely, that they will be used in a Java EE environment). If they are going to be chosen go to point 6.
  3. Mention JDK 1.7 and closures. (this strategy is very safe -> most companies are just now thinking about upgrade to Java 5). In general it is enough only mention the term “closure” in the context of Java.
  4. Wait a random amount of time. Pick one of the vs. issues and try to initiate a dicussion; SOA vs. ROA, Ruby on Rails vs. Java EE, Thin vs. Rich, AJAX vs. Rich, Swing vs. SWT, Netbeans vs. Eclipse, Java EE vs. .NET, SOAP vs. REST and OSGI and JSR-277. The highlighted ones are more funny and the discussion longer.
  5. Use terms like Web 2.0-ish, SOA-ish etc. Don’t care about the meaning: no one is able to define them.
  6. Suggest more esoteric languages like Haskell, Scala, or Fortress but not Malbolge for the realization. In general there is no reason to doing that (Java is working well), but why not?
  7. Don’t forget code generation. Sometimes it is enough to initiate a discussion about MDA vs. MDSD. If nothing happens ask the developers about PIM, PSM and code transformation etc.
  8. Very important: mention things like team velocity, pair programming, ask about Xtreme-Programming, Agile, Scrum, Crystal, Test First, Mocking (the more the merrier).

source : Adam Bien’s weblog

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis
Categories: Uncategorized Tags: , ,

Stack trace without line numbers — Unknown Source

March 29th, 2007 Arun Manivannan No comments

Sometimes, application servers don’t display the line numbers during printing the trace but instead just print the method name with the “(Unknown Source)” on it.

eg. something like this.

Exception in thread “main” java.lang.ArithmeticException
at TraceWithoutLineNumbers.main
(Unknown Source)

I wrote this small class to just help me learn why the line numbers get missed and Unknown Source comes up when the trace gets printed.

public class TraceWithoutLineNumbers {

public static void main(String[] args) {

System.out.println(”hello world”);

if (true){
throw new ArithmeticException();
}
System.out.println(”very true”);

}

}

For the above code, I gave a

javac TraceWithoutLineNumbers.java

and got

java TraceWithoutLineNumbers
hello world
Exception in thread “main” java.lang.ArithmeticException
at TraceWithoutLineNumbers.main(TraceWithoutLineNumbers.java:9)

Cool. Got the line number.

By default, the minimal debugging option is on. (Only line number and source file information is generated). Here is the list of all the other java compiler options.

So, I do a

javac -g:none TraceWithoutLineNumbers.java

java TraceWithoutLineNumbers
hello world
Exception in thread “main” java.lang.ArithmeticException
at TraceWithoutLineNumbers.main(Unknown Sourc
e)

There is nothing you could do on this if the class is built and run by the server ( read if you dont have control over the class’ compilation). However, if it is a standalone class, you can very well do a javac -g .

Or use this option.

-g:{keyword list}
Generate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:
source
Source file debugging information
lines
Line number debugging information
vars
Local variable debugging information

Probably, the app server or the web server you are running your class on would have disabled the debugging option for performance purposes.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis

Why finalize method is protected?

March 29th, 2007 Arun Manivannan 1 comment

I used to wonder why all methods in the java.lang.Object is public and only finalize is protected.  Finalize is just a callback method which is supposed to be called by the JVM.  So, ideally, it should be private.  Here is a mind-blowing explanation of why finalize is protected?

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis
Categories: Uncategorized Tags: , ,

RequestURI URL Pattern Matching

March 29th, 2007 Arun Manivannan No comments

Back when i was preparing for the Web Component Developer exam, i had an idea of the requestURI and pattern mapping against the exact servlet. In simple words, the logic behind how the server maps the “<url-pattern>” tag and the <servlet-class> tag. I know that it is really a monstrous job, but then i wanted to try it using a simple array. Of course the code i wrote is buggy ( I myself found one big bug in there.) But for most cases, it works fine.

Here is my code. Download from here.
public class Navigation {

static String[] config= { “/test2″, “TestServlet2″, “/test”, “TestServlet” };
static String requestUri= “/test2/”;

public static void main(String[] args) {

System.out.println(”output” +new Navigation().getHandler(config, requestUri));
}

public String getHandler(String[] config, String requestUri)
{
System.out.println(”Request uri : “+requestUri);
int maxMatch=0; //store the length of the match that is the longest.
String currentMatch=null; //the most accurate match string

for (int i=0;i<config.length;i=i+2){
//looping through the array.
// Coz, you know that every odd String in the array is the Handler String,
//you can just skip them

System.out.println(”config[i] :”+config[i]);

if ((requestUri.startsWith(config[i]))){
if (config[i].length()>maxMatch){ //compare the length of the
//previously matched String, if any
maxMatch=config[i].length(); //if so, store it
System.out.println(”max match… “+config[i+1]);
currentMatch=config[i+1]; //Dont forget the String too
}

}

}

if (currentMatch!=null){
return currentMatch; //return it.
}

return “/”;
}

}

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis
Categories: url pattern matching Tags: ,

Apache Commons Lang – Find number of String occurences

March 28th, 2007 Arun Manivannan 1 comment

The Apache Commons Lang page says ” The Lang Component provides a host of helper utilities for the java.lang API, notably String manipulation methods, basic numerical methods, object reflection, creation and serialization, and System properties. Additionally it contains an inheritable enum type, an exception structure that supports multiple types of nested-Exceptions, basic enhancements to java.util.Date and a series of utlities dedicated to help with building methods, such as hashCode, toString and equals.”

I have been using the commons library for quite sometime. But everything are in bits and pieces. So, just thought i could learn something more.  But before that download the commons lang libraries.

Counting the number of occurences of a String in a particular file or String requires lots of code. Here is one simple solution.

import org.apache.commons.lang.StringUtils;

public class StringMatch {

public static void main(String[] args) {

String inputString=”hello arun, say hello to all coz” +
” it’s going to save you from a hell a lot of trouble”;

int occurences=StringUtils.countMatches(inputString, “hell”);
System.out.println(occurences); //gives you 3
}

}

If you are reading from a file, then go for


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;

import org.apache.commons.lang.StringUtils;

public class StringFromFile {

public static void main(String[] args) {
try {
FileReader fileReader=new FileReader(”InputFile”);
LineNumberReader lineReader=new LineNumberReader(fileReader);
int count=0;
while (lineReader.ready()){
count=count+StringUtils.countMatches(lineReader.readLine(),
“hell”);
}
System.out.println(”Number of occurences is : “+count);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}

}

}

Download the entire source code

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis
Categories: Uncategorized Tags: , , ,

Adobe Flex Tutorial

March 28th, 2007 Arun Manivannan No comments

This site has a HUGGEEEEE number of video tutorials on Adobe Flex. All videos are in FLV. If you want to download them in a different format, then use this.

Good luck.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis
Categories: Uncategorized Tags:

Compare two Objects using Comparator

March 27th, 2007 Arun Manivannan 5 comments

Old story but will be useful for sure.

Say you have an ArrayList of Beans (eg. ArrayList of Employee objects) that need to be sorted based on an attribute inside the Bean (eg. EmployeeName) before displaying to your GUI. You have two options before you..

1) If you are among the lucky lot who gets access to the Data Access Object (EJB or a class that has queries), just alter your query to return the ResultSet after sorting. i.e. use an “order by” clause in your query.

2) Or…. Use the Comparator interface. (you can use Comparable too. I am not talking about that in this post)

The implementation is pretty simple..

Here goes the code.

I have three classes with me

1) UserBean.java (which is just a bean Bean with regular getters and setters). It has three attributes inside it. userId, userName, address

2) UserNameComparator.java (which implements the Comparator interface and obviously overrides the compare method). The compare method just accepts two objects and returns an int. neednt worry about what to return as “int”. Just call the compareTo(Object) method inbuilt in String and Wrapper classes. It will return an int. Just use it.

3) SortUserBean.java (the caller method). Just builds a dummy ArrayList of UserBeans, displays the ArrayList before sorting and after sorting.

Download the complete source code

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis

Turn your laptops touchscreens

March 27th, 2007 Arun Manivannan No comments

Crazy about touchscreens? And you can’t afford to buy one?

If you’ve got a laptop and just crazy about touchscreens, then you have this wonderful gizmo called the Laptop Tablet from NAVIsis.

Touchscreen laptop

source : scifi

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis
Categories: Uncategorized Tags:

“Save Image As” without Right Click using Javascript

March 26th, 2007 Arun Manivannan 2 comments

<script>
function saveImageAs (imgOrURL) {
if (typeof imgOrURL == ‘object’)
imgOrURL = imgOrURL.src;
window.win = open (imgOrURL);
setTimeout(’win.document.execCommand(”SaveAs”)’, 500);
}
</script>

<A href=”#”
ONCLICK=”saveImageAs(document.getElementById(’embedImage’)); return false” >save image</A>

<img id=”embedImage” src=”impossible.jpg” >
I am not the author of this code and i am really not sure where i picked up this script. But it works too good… only on IE

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis

Zimbra — It’s just not an open source email program

March 25th, 2007 Arun Manivannan 2 comments

Zimbra is another wonderful example of community supported software development. Started by three friends and widely supported and contributed by the community, Zimbra is growing up as a serious challenge for Microsoft’s Exchange server. The exciting thing is that it offers features that are unimaginable otherwise in an Outlook client.

Zimbra can work both inside the web-browser as well as in offline mode on mail-clients as Eudora, Thunderbird, Outlook etc.

With the outburst of Linux desktops in home and the enterprise, Zimbra profits on the Microsoft’s lack of an email service in Linux system.

So, whats so great on Zimbra

1) You view a mail of some earlier day and “tomorrow” and “next Tuesday” translates into relative dates.

Date appointments zimbra

2) A phone number gets recognized easily and a direct call to the mail sender could be made through Skype or a configured caller program

Direct Skype call zimbra

3) Create your own customized RSS folders and read your feeds offline, just like mails.

Rss Folders

4) This feature is awesome. A mashup on the mail client. Your address calls up the Yahoo map web service and the location of the mail sender is viewed on a map.

Yahoo map for addresses zimbra

These are just “few” of the features. If you interested in knowing all the features, watch this flash video.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis
Categories: zimbra Tags: