Custom Search

29
Feb


Recently, I had the chance to use Jython in one of the projects I am working on, and I must say that it is one cool scripting language. ;)

Jython is so easy to understand and learn, and the what I really like about it, is that it combines the best of 2 worlds, namely Python and Java. A hybrid scripting language as some people call it. As a Java programmer, and a Linux guru, this is something that I find very useful. Not only am I able to do native scripts within Linux, but I can also access Java classes and objects within these scripts. The more I use it, the more I am having fun. I’m like a kid now, that loves to play over and over again with his new toy. :)

It took me quite some time to get used to Jython’s syntax, especially that I had been programming Java my entire career, and had only been using Shell scripts when doing some stuffs with my Linux servers. Take for example the if-then-else statement that I got used to in Java:

if (var1 == 1) {
... do something
} else {
.. do something
}

In Jython you do it this way:

if var == 1:
... do something
else:

This confuses me a lot back then, but now I’m getting used to it.

Another weird thing I find about Jython is that you don’t have to declare the object type you want to create, like in the case of Java. For example, we have a User object in Java, we usually declare it as:

User user = new User()

But in Jython you simply ommit the User object declaration at the beginning and the “new” keyword in the right part of the equation:

user = User()

Aside from that, there are still a lot of things that you might find confusing at first, such as importing classes, packaging of namespaces, and as you can see in the samples, no “;” at the end of each line. Of course if you are already very competent in Python, then things would be a lot easier for you. In my case, I haven’t really used Python that much except on debugging or customizing some server side scripts or apps in Linux.

This is a great addition to my arsenal of development tools and languages. Just imagine being able to access your Java application’s business logic through a script, and saving on a significant amount of programming overheads in the process. This is very useful if you just want to try out some excerpts from your codes, and not spending a lot of time or resources to do so. It’s really a lot faster to do this in Jython than create Java classes to do the same thing. Moreover, you are also able to harness the benefits of Python in the process.

I should have known about Jython a long time ago, but it’s better late than never. ;)

Popularity: 5% [?]

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes