Saturday, May 21, 2005

Re: Integrating OpenEJB with Tomcat 5.0


I know what you guys are thinking - "Dinesh talking about EJB


Welcome to the Dark Side!! Btw how many of you all like Star Wars??



I guess you all know that Tomcat is not an EJB Container and as such requires external support for it to work with EJB's, well I at work have been reading on EJB's for the past few days and as usual being my impatient self, just couldn't contend myself with reading the book, I had to see and run some code. Well, I already had Tomcat installed so I was wondering if there's anything I can do to get it working with EJB's and that's when I fell upon OpenEJB. (I think there's also Jboss)


I'll just give a brief intro. Tomcat is a J2EE Web Container which can be used to deploy Java Server Pages(JSP) and Servlets both of which are used to create dynamic web pages. Open EJB is (i suppose) just an EJB Container which allows you to deploy EJB's. OpenEJB and JBoss are open source implementations.



Revo, you'll really love this, that's if you already haven't done it. Just try it out, it's really simple and yet so powerful.


You mean calling EJB's from JSP's or Integrating OpenEJB and Tomcat?

I have used Sun's Reference Implementation(RI) J2EE App Server for deploying my EJB's. The RI includes Tomcat as a Web Container so you do not have to manually integrate. Also the RI has a good admin console. The RI is free for use. I am not sure about the source. I haven't used OpenEJB. I guess the RI will be more user friendly.



It was a great moment to see my SessionBean being called from my jsp. A good experience, but yet I'd rather be writing cryptic C++ code ;)


I am sure you have read about the functionality provided by J2EE App Servers.. all the distibuted stuff.. implicit middleware etc. Writing an app to achieve functionality like this will really take a huge team and loads of cryptic code. Btw are there any C++ App Servers which provide such services??


Also I spoke of the Dark side. EJB's are difficult to use. Don't Make me Eat the Elephant Again is an article that talks a bit on what the situation is today. There are alternatives to EJB like Spring + Hibernate which I have been hearing a lot of but have never had time to read about. Also the EJB 3 release will be coming soon which is based on J2SE 5.0 and heavily uses annotations which should really simplify coding.

Mohn.. could you mention a little about how the .NET framework handles persistence for the Enterprise?? I have heard that it is simple compared to the Java model.

Re: Adventures with Linux


Looking around I came across ndiswrapper on sourceforge. This is a really neat project which uses windows drivers to get linux to recognize the card. I had some trouble with the newest vesion (1.1), so tried different versions (.10, .09), compiled and can it. It worked! So configured "wlan0" and now writing this post in Opera 8.0 on Mandrake 10.0! Just had a feeling of euphoria!


Woohooo... Congrats man on finally getting your wlan working. Mohn had asked me to help with ndiswrapper ages back.. and as lazy as I am, he had to do it himself!!



You would think that having struggled with it for so long, I would be quite sick of it. In some ways I am, but I've also learnt a lot in the process. And this is the essence of Linux.


Exactly. There are so many things we just take for granted when we use Windows. But only for customization etc when you go deep into Linux do you understand a lot more about the OS and other stuff.

Thursday, May 19, 2005

SciTE Text & Code Editor

I have to admit that I'm a Editor freak!! I keep scourging the net for free, fast and good text editors namely for the Windows Platform. On Linux, Vim just kicks everyone else's butt!!

Recently I came across SciTE which in my opinion is one of the best I have ever used. It's simple and extremely fast. It's also extremely customizable and supports an array of programming languages!!

I think I'm going to stick with this editor for quite some time, hope you guys check it out!

Dinesh.

Wednesday, May 18, 2005

Integrating OpenEJB with Tomcat 5.0

I know what you guys are thinking - "Dinesh talking about EJB, GIVE ME A
BREAK!!" ;) But as the Walrus said "The time has come to talk of many
things" :)

I guess you all know that Tomcat is not an EJB Container and as such
requires external support for it to work with EJB's, well I at work have
been reading on EJB's for the past few days and as usual being my
impatient self, just couldn't contend myself with reading the book, I
had to see and run some code. Well, I already had Tomcat installed so I
was wondering if there's anything I can do to get it working with EJB's
and that's when I fell upon OpenEJB. (I think there's also Jboss)

I will not go into what you should do inorder to integrate the two cause
there's already an excellent article available on the subject at OnJava.com.

Revo, you'll really love this, that's if you already haven't done it.
Just try it out, it's really simple and yet so powerful.

It was a great moment to see my SessionBean being called from my jsp. A
good experience, but yet I'd rather be writing cryptic C++ code ;)
(Sorry, I'll be me, always!)

Dinesh.

Tuesday, May 17, 2005

Adventures with Linux

Ok, I admit it. I've been a blind bastard. Blind to Linux and open source. I've read about it and been keeping up with what's been going on in the "community" but never really "got" it. Well, I think something finally hit me - that light bulb turned on. Anyway, I've decided to write some stuff about my Linux experience.

Here's a brief history of my dealings with Linux as a total newbie (warning: boring stuff ahead). What got me interested in Linux, was my India trip in summer 03 when Rahul and Hrishi were using it. Before that, I never really thought about trying it out and didn't have much interest in it. But the way they spoke about it, I couldn't resist having a go at it. So after coming back, I installed Red Hat 9 on a couple of machines. At the time, I had a network setup over the phoneline and wasn't able to get Red Hat to recognize the NIC. Basically I gave up after several futile posts to message boards and many email exchanges with Rahul. Last May, I installed Mandrake 10 in the hopes that it would work. No luck there either. I realize it was my network setup - which was quite rare. So I gave up on that too. Last summer, I changed over to a wireless network. This time, I was a little more hopeful because this was a more common network setup. Anyhow, long story short, I had a usb wireless adaptor and Mandrake didn't recognize it. I remember spending an interesting afternoon with Rahul on messenger giving me step by step instrutions to recompile the kernel with added support for wireless drivers. Unfortunately, didn't work. Also tried Knoppix without luck. Finally, I installed Mandrake on a laptop which had a wirless card built in. This was pcmcia so I was hoping for better. Again, no luck.

Looking around I came across ndiswrapper on sourceforge. This is a really neat project which uses windows drivers to get linux to recognize the card. I had some trouble with the newest vesion (1.1), so tried different versions (.10, .09), compiled and can it. It worked! So configured "wlan0" and now writing this post in Opera 8.0 on Mandrake 10.0! Just had a feeling of euphoria!

You would think that having struggled with it for so long, I would be quite sick of it. In some ways I am, but I've also learnt a lot in the process. And this is the essence of Linux.

I'll post some stuff about some stuff I've liked about Linux next time.

Monday, May 09, 2005

RE: Stroustrup's Interview Leaked...

The "matter" is obviously a bunch of ******* bullshit but I would have liked to believe that it was Bjarne's idea of a joke! :-p

Friday, May 06, 2005

RE: Stroustrup's Interview Leaked...

I second Dinesh's "you got to be kidding right?" comment. Obviously the work of a C programmer.

RE: Stroustrup's Interview Leaked...

You actually thought that it was Bjarne Stroustrup?? You got to be kidding, right??

Dinesh.

Stroustrup's Interview Leaked...

I don't know how far this is true but entertaining to read nevertheless... :-)

Here's the link.

Thursday, May 05, 2005

Implementing "finally"

Java has this great facility when dealing with exceptions called "finally". When you have a finally block, any code within it will execute regardless of whether an exception has been thrown or not. It's a good place to put code that must absolutely positively be run like closing files, database connections and any other similar resources. C# also has it and I believe it's also been standardized in C++, but not sure. Anyway, ever wonder how it is actually implemented?

I wrote a really simple method that just has a try, catch, finally block and examined the bytecode generated using this really cool Eclipse plug-in.

Here's the java code...

public void testFinally()
{
    try
    {
        System.out.println( "try" );
    }
    catch ( Exception ex )
    {
        System.out.println( "catch" );
    }
    finally
    {
        System.out.println( "finally" );
    }
}


and here's the bytecode...

// testFinally()V
L0 (7)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "try"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
GOTO L1
L2 (9)
ASTORE 1
L3 (11)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "catch"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
L4
GOTO L1
L5 (14)
ASTORE 3
JSR L6
ALOAD 3
ATHROW
L6
ASTORE 2
L7 (15)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "finally"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
L8 (16)
RET 2
L1 (14)
JSR L6
L9 (17)
RETURN
L10
LOCALVARIABLE this Ltest; L0 L10 0
LOCALVARIABLE ex Ljava/lang/Exception; L3 L4 1
MAXSTACK = 2
MAXLOCALS = 4


I don't understand bytecode. I would be interested in knowing more about it. But anyway, you don't need to be a bytecode specialist to understand how "finally" is always executed regardless of exception or not...

This is the "try" part

L0 (7)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "try"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
GOTO L1


and this is the "catch" part

L3 (11)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "catch"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
L4
GOTO L1


Notice any similarities? What is at "L1"?

L1 (14)
JSR L6


JSR is a jump instruction. So all this does is just to location L6. As you would suspect, it is the finally block...

L6
ASTORE 2
L7 (15)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "finally"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V


Voila. Mystery solved!

I have to say that the bytecode is NOT the most diffcult thing in the world to interpret. A lot of it is pretty self-explanatory. I realize this is a real toy example and it gets more complicated, but it looks like something one can pick up. It's the same situation with IL code in the .NET world. I think maybe IL is a bit easier to read.

Maybe not the most important thing, but something that's interesting and nice to know.

The essential Java language library

The essential Java language library

Seems like a decent list. Of the books mentioned, I can vouch for "Effective Java". Haven't read Bruce Eckel's "Thinking in Java", but he's a good writer... "Thinking in C++" was a good read and we've included him in many of our discussions! And I know Rahul is a big fan of "Design Patterns". As far as sites are concerned, onjava.com and theserverside.com have decent articles. onjava.com is part of oreilly which I really respect.

What are some of your fav books? We discussed books we'd LIKE to read long back, but what about books you've already read? I'll mention three - "Applied .NET Framework Programming", "Effective Java" and "The C++ Object Model". I really like books that go into detail and explain HOW things work, you know what's going on underneath the covers or talk about best practices rather than just talk about syntax. I think all these three do that and more.

Java turns 10

See James Gosling (and friends) celebrate his kid turning 10.

Warning - celebration is pretty pathetic.