Sunday, June 12, 2005

The real story about how Anakin Skywalker became Darth Vader (Java Version)

Kirill Grouchnikov's Blog: The real story about how Anakin Skywalker became Darth Vader: "

Kirill Grouchnikov's Blog describe us the last Star Wars episode with the point of view of a Java Developer. It is a really funny history...

The real story about how Anakin Skywalker became Darth Vader:

Here it is - the JDK 5.0-compliant story behind 'Revenge of the Sith'. See it in all its glory, using the new java.util.concurrency package:

public class Princess implements ExecutorService {
public static final Princess PADME = new Princess();

// private member
private StarShip ship;

private Princess() {
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
timer.scheduleAtFixedRate(task, new Date(), 1000);

public class JediKnight implements ExecutorService {
public static final JediKnight ANAKIN = new JediKnight(false);
public static final JediKnight OBI_WAN = new JediKnight(false);
public static final JediKnight YODA = new JediKnight(true);

private JediKnight(boolean isYoda) {
if (!isYoda) {
else {
Locale yodaLocale = Locale.EN;

public class Sith {
public static final Sith LORD = new Sith();

private Sith() {

public static main() {
// The following line has been commented out so as not
// to confuse fans who never did it

// Utils.initChildren(JediKnight.ANAKIN, Princess.PADME);

// Use JDK 5.0 concurrency package
Future> padmeFuture = Princess.PADME.submit(
new Callable>() {
public Set call() {
try {
int weeks = (int)(36+4.0*Math.random());
this = null;
finally() {
Child boy = new Child("Luke");
Child girl = new Child("Leia");
Set result = new HashSet();
return result;

if (JediKnight.ANAKIN.poll(padmeFuture) instanceof ThreadDeath) {

// use some marketing ideas
Sith.LORD.promise(JediKnight.ANAKIN, new RuntimePermission("object.restore.afterGC"));
Sith.LORD.promise(JediKnight.ANAKIN, new RuntimePermission("force.power.dark.*"));
Sith.LORD.promise(JediKnight.ANAKIN, new RuntimePermission("force.power.*"));
Sith.LORD.promise(JediKnight.ANAKIN, new RuntimePermission("force.*"));

JediKnight.ANAKIN.setInternalName("Darth Vader");

JediKnight.ANAKIN.promise(Princess.PADME, new RuntimePermission("*"));


// Use JDK 5.0 concurrency package
Future anakinFuture =
new Callable() {
public RuntimePermission call() {
try {
Class princessClass = Princess.getClass();
Field shipField = princessClass.getDeclaredField("ship");
// will never throw SecurityException on Jedi Knight
JediKnight.this.add(new RuntimePermission("object.ship.board.*"));
return (StarShip)shipField.get(Princess.PADME);
catch (SecurityException se) {
// never supposed to happen to Jedi Knight
System.out.println("Internal error. Contact George Lucas.");

StarShip padmeShip =;



// note - absolutely no need for GC, Anakin will be collected automatically.

ReferenceQueue sithWatchList = new ReferenceQueue();
PhantomReference anakinRef = sithWatchList.remove();
JediKnight anakinPhantom = anakinRef.get();

Sith DARTH_VADER = Sith.LORD.assemble(anakinPhantom, LimbFactory.getSpareInstances());
MouthPiece newMouthPiece = MouthPieceFactory.getInstance();
// no need to check that it works - guaranteed to work with no noise
else {
// TODO - create alternative scenario for Sith revenge

A great Java Book Catalog! is a Java technology book Catalog, that lets the user find the smallest prize of a book at the main online book stores (Amazon, etc)

This is the result list of a book search.

We can know the different prizes of a book with only a click! This online catalog of Java books consume the web services that the online book stores offer.

... I want this book, My Master!

JAVA KNOWLEDGE ! [ ArrayList deserialization problem]

Java Forums - ArrayList deserialization problem: "Re: ArrayList deserialization problem
Author: sylviae May 25, 2005 12:47 AM (reply 3 of 4)

You're actually corrupting the serialized form by converting from a stream of bytes into a String, and then back again.

As a general rule, you cannot convert a random array of bytes into a String and back again and expect to have what you started with. In your particular case, it's altered the serialization identifier for the ArrayList class, but there's no predicting what it might do.

Use toByteArray() to get the serialized form as an array of bytes, and then construct your input stream from that and it will work.

BTW, you really should include a call to ous.flush() before you obtain the byte array.


Developer! Mustang need you !!!

Now, external developers can contribute to Mustang (The new Java J2SE 6.0 version). How to Contribute with my Code to Mustang?,

I Need You for Mustang Development

well I you have detected a bug or you have a good idea for the new versión of Java, then you don't think it more and sumbit it to the new version of Java ;)

.... yes, my Master!

Where I can find Java APIs?

Docjar is a Java APIs search engine powered by Google, that allows the user, search classes, methods, etc..., from thousands of Java APIs from the Eclipse IDE.

... it rocks!, My Master!

How determine the number of rows in a Java ResultSet?

Well, last week, I see the following code for determinate how many rows had a Java Resultset:

int i;


well there is a better way to do this ... just we must use the attribute last() of a Resultset as follows:

int totalRows=0;


easy, no?

... yes, my Master!

Jar Jar, where are you?

Sometime we want to create a JAR (Java ARchive file), may be of interest to know what is the JAR file that contains an specific class defenition at runtime. To know what is this JAR file, we must do the next:

try {

String myClassName = "";
String myJarName="";

myClassName=.replace('.', /');

Class myClass=My_Instance_Of_A_Class.getClass();

int index=myJarName.lastIndexOf(":")-1;
int indexExclam=myJarName.indexOf("!");


} catch (Exception ex) {
/*There has been an error*/

... yes, my Master!

Their Java, Your Java, Its Java, Her Java, His Java, Your Java and My Java Server !!!

MyJavaServer is a new space where all developers that want to test their web applications made on java technology can do it!

MyJavaServer is free and is supported by, Java developers can test many type of API's and frameworks... It is a great site!, the only disadvantage is that your disk quota is only 5 MB.

.... yes, my Master!