Monday, April 23, 2007

Solaris DVDs for free !

Finally ! My Solaris DVDs arrived. I requested two Solaris distributions : open Solaris starter kit and Free Solaris 10 Media Kit (Solaris 10 11/6 and developer tools). It’s taken a lot of time from requesting to arrival. But.. it's interesting that "Media Kit" arrived faster from San Jose than "starter kit" from Sweden if I'm not missing something. Friendly speaking I’m almost forgot about this story at all... but it is doubly pleasantly to receive them now. So, I'm Solarised up to 100% :) Thanks to Sun Microsystems, it is really nice move. Not all the people can download 4GB distribution just to see what Solaris is. I will share DVDs in the university with some students and co-workers.

I’m planning to install Solaris at my second hdd, but not earlier than I backup useful information :) Starter kit has 3 distributions on Live DVD, but real system is rather more interesting. I saw Nexenta almost a year ago, so I can evaluate it is evolution. Nice idea – Debian system with openSolaris kernel.

Friday, April 20, 2007

Random strings and removing duplicates

Sometimes I need a large database with non-real data for playing. In fact it is not just playing, but testing database layer in real world comparable environment. Recently I came across with a problem : I heed a lot of unique random strings with random length. Here is the result of my work. I'm using Set to remove duplicates. According to docs HashSet is the fastest implementation of Set Interface. It is not guarantees the order of iteration, but in my case it is not an issue. By the way, you can compare this Java code with another one - in Python. See the difference ? :) Dont beat me if my solution is not very original... it is works for me. Can it be done better ? Any suggesions are welcome.

import java.util.Random;
import java.util.Set;
import java.util.HashSet;

class RandomStringRandomLength
private static final String alphabet[] = {"a","b","c","d","e","f"...};
public static void main(String args[])

int numberOfRandomStrings = 0;
int minLength = 0;
int maxLength = 0;

minLength = new Integer(args[0]);
maxLength = new Integer(args[1]);
numberOfRandomStrings = new Integer(args[2]);
catch(NumberFormatException NumEx)
System.out.println("Enter a numbers !");

Set<String> set = new HashSet<String>();

final Random random = new Random();
int rndStringLength = 0;
int rndIndex = 0;
StringBuffer rndString = null;
for(int i=0;i<numberOfRandomStrings;i++)
rndStringLength = minLength +
rndString = new StringBuffer();
for(int j=0;j<rndStringLength;j++)
rndIndex = random.nextInt(alphabet.length);

for(String s : set)

Monday, April 16, 2007

IT Podcasting

I'm become a fan of podcasting. Why ? It is interesting to me to hear what the people say. I don't know, maybe it is wish to be closer to the technology leaders. I'm not able to visit such parties as ApacheCon, JavaOne etc. Maybe someday, somehow... :) So, podcast listening is a nice alternative.

I've listened few podcasts in Russian - one IT only podcast, another not so related to IT but from IT specialist. It was interesting to hear about lifestyle and some points from interviewer form Chicago, US. Another interesting thing (in Russian also) is about startup creation. I have a few ideas which I found interesting, but I need a lot (maybe not) of meditation to create at least business-plan and prototype. Searching a venture capitalist is the most complicated thing as far as I see. But maybe not. I'm noticed that I have a visitors from different kind of financial organizations. Will see :) I guess the most exciting thing of startup creation is that I'm not loosing something. When it is successful - I won, when not - I'm also won because I completed some work and added a line to my CV. When you have nothing life is simple - go and fight :)

Of course I'm interested in Java related podcasts. I've found one -
I have to admit that is not too easy to perceive sound. English is not my native language, so I need a lot of practice. As the Lenin said "To learn, to learn and to learn once again!"

Wednesday, April 11, 2007

Using XDoclet with Maven 2

One of the useful features of Ant is ability to generate different kind of config files (and othe stuff) with the help of XDoclet. I would like to use this feature with Maven. It's take a lot of time to understand how to do the trick but for now it is working as expected and I want to share with you some of hints.
So, what is doing here. I just want to build servlet with Maven, generate deployment descriptor from annotated source and finally create a war file. OK, lets start.
First of all I'm creating a new Maven project like thins :

mvn archetype:create

In my pom.xml I have
so, all is ok. Final name of war file will be longRunningServlet.war. Further more interesting. Where I should place servlet source code ? Answer is longRunningServlet\src\main\java. But you should to create "java" directory by hand since it is not created by Maven. Is it bug of feature ? :) How we have directory strucure for building project with sources placed at longRunningServlet\src\main\java. To build servlet we need to set up dependencies. Standalone servlet has one dependency
Please notice scope=provided. In practice it is means that servlet api jar will not be placed in war's WEB-INF\lib.
And now XDoclet. Dependencies for XDoclet are :
Actualy XDoclet is executed via Maven Antrun plugin with specific configuration of both - maven-run plugin and xdoclet. Looks impressively :

<taskdef name="webdoclet"
classpathref="maven.compile.classpath" />

includes="**/*.java" />
Webdoclet configuration in between "tasks" tag. You can place any Ant task here but in my case it is XDoclet call.

Tuesday, April 03, 2007

Low-level networking in Java

Sniffer in Java ? Hm.. Not possible ? Not actually so. There is pcap library which is used by Wireshark (formerly Ethereal), tcpdump, Snort, Nmap. The most sweet thing is that there is a binding between Java and native pcap library - jpcap. Nice thing. With the help of it I was able to capture ICMP packets from Java code. I've noticed that data in every ping request is the same - it is "abcdefghijklmnopqrstuvwabcdefghi" in string representation. It's on my Windows box.