Tuesday, November 28, 2006


Today I was thinking of all the games I used to play in my school time. And side by side I was also looking at the advancement of Game Programming. More or less all the Game which I used to play on paper and pencil are now automated and I can play on Computer with screen, mouse and keyboard.

I can remember one of the my favourite game that not seems to automated (I guess). The game is something like this:

We call it "Army Man" Game or "Tank" Game. On top and bottom of a paper, we have 3-3 army men like



You can force any armyman at anytime to move, but it should be one at a time. He will fire a bullet, that we used to do by sliding the pencil. And then you need to put a dot on the end of his path,that is, the path covered by pencil. Now its the time of other side army man to fire the bullet. Sameway you can dot his path. Both need to do this till one of them intersect the path of other. This game is looking very simple, but actualy its not. You need to put your head, when to go defensive and when to go aggresive. Also when both the teams are going straightway, you can go aggesive but if you missed, other will kill you.

Game finished, Rub the paper and start again. Best time to play this game was our Geography class :D


Monday, November 27, 2006

Java Code and Version Dependency

If you are a person who plays with different versions of Java, according to your business need, client need or your interest. Be careful for java version dependency. Ok, let me show you an example, this is the code I was trying in morning:

class StringTest {

public static void main(String[] args)
throws Exception
String s[] = new String[10];
String news = s[-1].valueOf('a');

Nothing great in this code, but will this code give an exception or not ? s[-1] is ofcourse a negative index array value but mind it method "valueOf" is a static method and hence not depending on the instance of the class. The result is quite interesting:

jdk 1.1 - running perfect.
jdk 1.2 - throwing an error.
jdk 1.3 - running perfect.
jdk 1.4 - throwing an error.
jdk 1.5 - throwing an error.

Thanks to my office system , which has all the java versions. Hmm, result is quite interesting.

I start searching the problem in "Google" and I got an awesome article, again on Javaworld.com which practically not solved my problem but at least relaxed me (Click on the main title to go on Javaworld.com page). Lots of things to read off, I can't write whole in blog :)

Thursday, November 23, 2006

java -ddoc option

One customization :

There is now more than lakh's of project developed in Java, that went for a maintenance, enhancement and servicing. The common problem in which most of the company stuck of is with the chain of ongoing and incoming employee. For a new engineer its difficult to understand the code written by someone else. And the worst happens when they don't have any supporting document to understand the code.

I am here proposing a java -ddoc option which generated a HTML(XML) format design document of the work flow of the code along with the output of the code.

It tells user about the class variables, share variables, method flow and Native API's(if any). Being Java an Open Java, engineers can understand the internal functionality and can perfectly understand the requirement of the written code.

Wednesday, November 22, 2006

Java is Slow ?

Are you feel anything bad about Java ?
Ya, its damn slow.

This is a inherited sentence from someone, not a self-checked statement. Our teachers used to say so, and so our seniors and so we.

Today, I was compiling some of the native API's where the function body is actually a CPP or C code. Just came across a paper " .P.Lewis and Ulrich Neumann Computer Graphics and Immersive Technology Lab University of Southern California " regarding the performance of Java against C++. There are many things to surprise of.

Let me discuss few of them:

1. Java performace is comparible to CPP and in some cases better than CPP. Not only this its improving ... !
Operation Units C Smalltalk Java
Polynomial 10th degree msec. 1.1 27.7 9.0
Neville Interpolation msec. 0.9 11.0 0.8
LUP matrix inversion sec. 3.9 22.9 1.0

2. Java performance at the time to be somewhere in the middle of C compiler performance - faster than the worst C compilers, slower than the best.more recent java(1.4) and gcc(3.2), using full optimization.This time java is faster than C the majority of the tests, by a factor of more than 2 in some cases...

And in theories YES, many reasons:


It's most Adaptable, not the most Powerful, who survives ! :)

Thursday, November 09, 2006

Garbage Collector ... Wow !!

Garbage collector is one of the most toughest code that is written under JVM. Highly optimized but not yet fully optimized code !

Most of the time we think as an application developer on Java, that GC is something which is not under our control and handled by JVM only and this is one of the place where we are really killing our application. Java HotSpot (JVM) gives 'n' number options to optimize GC according to the application need and to be frank this 'n' is 63. Some of the optimization is now deprecated in Mustang(jdk1.6) .

We can have several questions like how we can optimize our code!

Let me tell one perfect analogy that I saw someday back on JavaWorld for GC. Here it goes :

You are owner of a city, small city say 'JavaVelle' :) and in your city all the ppl are software eng'er. They are using too much of Computer and Car . Being small city there is only one main road in your city. Now, Dumping of computers and Cars is becoming too much and now you as an owner of the city want some garbage ppl to come and collector the garbage.

So, he is all the time coming with a big truck and collecting all the garbage and then putting it out of the city. But his truck is so big that when his truck is on road other ppl cant move here and there, and hence creating a congestion and not only that the biggest problem is Police and Ambulance type of critical process cant stop because of Garbage Truck.

This is the true scenario with GC. When JVM is running the GC to collect the Kachara (Garbage) it stop all the current running process. But some process which are real time or some which has too many client to serve cant stop like that. Sun provides a smart solution in Jdk 1.4 and smartest in Tiger release(JDK 1.5). It really based on some hopeless assumptions, like New object will die early, but it holds good. We are not going to discuss the whole process but as an application developer on Java, We can optimize the GC according to our own need. How ???

If you have a single-processor client machine and are having problems with pause times in your application, try the incremental garbage collector. This might help with perceived performance, even though it may decrease real application performance somewhat. Remember that perceived performance is usually more important than real performance for client applications. If the incremental garbage collector doesn't help (or doesn't help enough), and you have plenty of RAM, try the concurrent garbage collector.

If you have a single-processor server machine with lots of memory and experience trouble with application pause times, try the concurrent garbage collector.

If you have a multiprocessor machine, especially with four or more processors, try one of the parallel garbage collection algorithms. These should significantly decrease pause times. If you have lots of memory (gigabytes), use the scavenging collector; otherwise, use the copying collector.

Command-line switch

-XX:+UseParNewGC Parallel copying
-XX:+UseParallelGC Parallel scavenging
-Xincgc Incremental [none] Mark-compact [default]

If you just want to check a demo, make a program with Lot of GC work. And then try these commands.

Example :
javac Test.java
java -XX:+UseParNewGC Test

javac Test.java
java -XX:+UseParallelGC Test

javac Test.java
java -Xincgc Test

For web application developer, we need to make change in Web Container. I havn't try this but will do soon :)

Really want to go in detail, please check the Title Link.