December 28, 2006

Scripting in Java

The latest version of java brings a number of new features and enhancements that will improve the development of software in java platform. One new feature is the Scripting support that the new JDK will provide and this article is just the basics of it.

Most developers know scripting languages like Perl,PHP,Python,Ruby and some are crazy about it because they are simple,flexible and highly productive. Java now comes with built-in support for scripting languages. This has been encoprated through Java Specification Request (JSR) 223, which defines a framework and provide the necessary API required to access and control the scripting environment, create web content with scripting and embed scripting technology in java based applications.

So the start with, we have a script engine that helps us in executing the script and our first step would be to import some packages. The classes and interfaces required are defined in the package javax.script. The main class is ScriptEngineManager which is the script engine that executes the scripts. So we have it instantiate it as our second step. So the simple steps for incoprating scripting will be:

1) Create an instance of ScriptEngineManager.
2) Get the required scripting engine.
3) Execute the script using the scripting engine.

The first two steps are as follows:

ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine engine = sem.getEngineByName("JavaScript");

So now you have the engine to run java scripts. To execute a script we have to use the eval API which is in ScriptEngine.
To execute (evaluate) a script we have:

engine.eval("script to run");

One thing to remeber is eval method return an Object and we have many overloaded versions of eval. These are not the only features, we can invoke procedures using the Invocable interface. To invoke a procedure we use invokeFunction or invokeMethod methods.

So that's all about scripting for now. For reference check the tutorials provided in java site and also check the javadocs.

December 27, 2006

Bill Gates' High School Speech!!!

A few months ago I read an article about Bill Gates' speech to high school kids about rules of life in Deccan Chronicle . I also cut out the article and had it with me (even though i am against his business ideas) till the last days in VIT hostel. Here is the extract of the great speech:

RULE 1: Life is not fair - get used to it.

RULE 2: The world won't care about your self-esteem. The world will expect you to accomplish something BEFORE you feel good about yourself.
RULE 3: You will NOT make 40 thousand dollars a year right out of high school. You won't be a vice president with car phone, until you earn both.

RULE 4: If you think your teacher is tough, wait till you get a boss. He doesn't have tenure.
RULE 5: Flipping burgers is not beneath your dignity. Your grandparents had a different word for burger flipping they called it Opportunity.

RULE 6: If you mess up,it's not your parents' fault, so don't whine about your mistakes, learn from them.

RULE 7: Before you were born, your parents weren't as boring as they are now. They got that way from paying your bills, cleaning your clothes and listening to you talk about how cool you are. So before you save the rain forest from the parasites of your parent's generation, try delousing the closet in your own room.

RULE 8: Your school may have done away with winners and losers,but life has not. In some schools they have abolished failing grades and they'll give you as many times as you want to get the right answer. This doesn't bear the slightest resemblance to ANYTHING in real life.

RULE 9: Life is not divided into semesters. You don't get summers off and very few employers are interested in helping you find yourself. Do that on your own time.

RULE 10: Television is NOT real life. In real life people actually have to leave the coffee shop and go to jobs.

RULE 11: Be nice to nerds. Chances are you'll end up working for one.

But all this is a rumor! Bill Gates never delivered this speech! Recently my friend send my this link that says it all. But the trouble is this was published in a newspaper!!! Many of you would agree that Deccan Chronicle is gossip paper but see how media have diverted from its real goal. The goal to spread the right information!

December 19, 2006

First day in Office!

I am one day late to write this blog, but here is my experience on "First day in office". Basically it was good! The whole day was a mixture of formal and informal events. but there are funny events that happened even before I reached the office. Our report time was at 10.30 am, but my friends and I left the guest house around 9.15 am. As all of us are not familiar with Bangalore city we had hire an auto. The great day was struck with a mishap when the auto refused to move forward after running few kilometers! So we where near "Silkboard". The next auto trip started from front of Silkboard building after some help from some Patni and Wipro employees. And we finally reached Honeywell Campus at Banargatha road sharp 10:30 am! But we where not still inside. Security took away 15 minutes in printing our temporary IDs, and finally reached conferences room on "Pluto" around 10:50. But we had little trouble in entering the office wing since we didn't have our access cards.
The first event was submitting our documents that we where supposed to carry and that took away 2 hours. during this time our snaps where taken for our Access cards. And then the big lunch! After lunch we here supposed to move to new Honeywell campus called Orion. So we picked our shuttle from Pluto to Orion at 3. In mid way we met with a accident when one heavy truck brushed our shuttle (bus). But it was a minor one and we moved on :) . Orion is new campus and the only building is named Alpha. We where to meet our manager in Alpha 003 at 4:00 pm and we did. Alpha 003 room's discussion included our introductions, interests etc and we where out by 6 pm. But the real fun started now. We played Table tennis will 7.30 and left home once we where tired! So my first day in office was good!
And this blog is being written from office and its my second day. i will be assigned to my project today and the meeting is scheduled to be at 5:30!

December 13, 2006

Why Java was GPLed?

Sun's open sourcing of java is not a one night task. It has been on news for quite long now. java.net even had polls to see what developers community thought about it and also under which license it should be given out. Now it's finally open under GPLv2! But what surprised me was the license which they have used.With the conterversy of GPL versions arround I really didn't like the choice of license. But that's not all!! What made Sun to open source java?
A little investigation what is happening arround will give you a picture. Through my hunt I feel the main reason for Sun to open source java was the pressure from the open source community to open it up. The pressure was in the form of open source implementations of the J2SE. One such project is Harmony of Apache Software Foundation. The Harmony project site says "Apache Harmony is a top-level project of the Apache Software Foundation! See below for more information". And the big news is they plan to complete the implementation of Java SE 5 JDK by mid 2007. It can run servers like Tomcat,Maven etc. The license under which its distributed is Apache License.
Now its not just the Apache group that's under hard work! GNU is also comming up with its own implementaion of Java SE! Its called GNU Classpath. but the problem is its behind as we have implementation of 1.4 only. But they warmly welcomes the Sun's open sourcing of java.
So Sun Micorsystem is under pressure by these two open source java implementation because they will become more popular and may even become better than Sun's own implementation. Another reason is, at present no Linux distribution have sun's J2SE.The user have to install a copy by downloading from Sun's site. By making Java open source, you will now get to see the Sun's JDK with many major distributions like Novell,Red Hat,Open Suse, Fedora etc...
So what's the effect of it all on developers? Developers are going to be more involved in Java's development and tune it. One good example is the new Java JDK ie JDK6.So as a developer : KEEP PROGRAMMING ! :)