Tuesday Mar 04, 2008

Latest on scripting for the Java platform...

Updates on the world of Scripting for the Java platform:

Friday Feb 15, 2008

VM on a VM on a ...

My recent fun with virtualization continues. In the last JavaOne, I missed the talk titled "Everything Java": JPC, a Fast x86 PC Emulator. But, I downloaded the source and binary of JPC just to check it out. I ran the classic game "Prince". Nostalgia :-)

Thursday Feb 14, 2008

A tale of many OSes without reboot/partitioning

In my previous post, I talked about having to use more than OS for education/entertainment purpose. The problem is that I've quite a few ISO images and LiveCDs with those images. Two problems:

  • I need to keep searching right LiveCD I want or I need to install more than one OSes on the same/different boxes.
  • Need to re-start the machine if I've use a single machine with many OSes.

For kids, all they want is the best stuff available across all operating systems. They don't wait for the machine to reboot from another partition or from a LiveCD. Besides, while they can switch between applications easily, restarting a different OS is bit much to ask :-) [although I won't be surprised if they do that!]. Kids want to switch between interesting applications/games/edutainment stuff rather quickly. Also, we don't seem to get all the good stuff on the same OS! For example, I need to Scratch on Windows or Mac -- no official Linux binary yet :-( While it is possible to hack to run Scratch on Linux by taking the Squeak image, there are issues with MIDI etc. There are many good stuff in Edubuntu and OLPC too. The point is that you want to run the best set of applications/games across operating systems -- without having to reboot.

This is where Virtualization helps! As Tim Marland said, you don't have to be a hypervisor/virtualization expert to use it. I downloaded VirtualBox for Windows XP [just run .msi file to install] and edubuntu [this later was very easy -- I just to use Add/Remove programs menu and look for "VirtualBox". VirtualBox is very easy to configure -- mostly point-n-click stuff. Now, I can run OLPC, Edubuntu and Belenix on my Windows XP latop without having to partition my hard-disk or rebooting. Kids can switch between their favorite applications across Operating Systems easily. If you are curious how it looks, here are some screen-shots:

Monday Feb 11, 2008

A tale of two operating systems for kids..

When I introduced computers to my kids, as like many other kids they started with games on the net. Mostly playing simple games like tom-and-jerry chase, bob the builder etc. My mother tongue is Tamil and so I came across the kids section of the Tamil Virtual University site.

Then, I started experimenting with Squeak and EToys. Later on, I moved to use Scratch. After some time, I learned about GCompris, Tux Math, Alice, Robomind etc. During that period, I still used the non-open-source OS that came with my laptop. GCompris version on that OS does not include all the activities -- to encourage the usage of open source operating systems! So, I looked for operating systems for kids. I've started using the following operating systems.

  1. Edubuntu. Venkateswara TV of Solaris sustaining team suggested this to me when I asked him about a Linux distro with GCompris. Wow! Edubuntu is very nice. In addition to what edubuntu comes with (lot of good stuff!), I installed more programs like Childsplay etc.
  2. LiveCD for OLPC (One-Laptop-Per-Child). The user interface definitely appeals to kids. Kids seem to enjoy the text editing, painting, Turtle (LOGO) and EToys...!!

Recently, I came to know about OpenSolaris in Tamil -- one of these days, I'll try a LiveCD. Need to check if there is a Tamil version of Belenix out there...

Monday Jan 07, 2008

No evidence, but still guilty?

Harbhajan banned for three-matches for alleged "racial abuse". Umpires haven't heard or seen anything. Mike Procter himself came on camera and said that the umpires told him they have not heard or seen anything. Did he see anything from the TV footage? It does not seem so. If there is any evidence, we have the right to know it. Aussie players claim something. Indian players claim otherwise. Two parties are not agreeing on what really happened. Under the circumstances, you expect the ICC referee to dismiss the charge on the lack of evidence. Instead, he punished Harbhajan. Did he go by just the word from Aussie players alone?

Now, by this process anyone can be punished. Any team can gang against the better players of the opponent team and claim racial abuse or anything that can get a ban! If a Muttiah Muralidaran bowls well, previously they claimed chucking, shouted "no ball", wrote "expert" columns about his bowling action and so on. Now, it seems that there is even a new trick - claim "racial abuse", get a ban for 2/3 matches and then you can bag the series!!

If BCCI believes injustice has been done, then they should just pull out and send a strong message to ICC. It is ICC that needs India and it's large cricket crazy population. Not the other way around. It is economically viable to have our own tournaments, entertain public, have fun and make money. BCCI has to learn from the ICL example and start something within India and expand.

Sunday Jan 06, 2008

Aussies win as expected, but...

Aussies win as expected. But, that does not change my comments earlier. While Indian second inning batting is worst, the controversial umpiring decisions had definite effect on the match. While it may sound "sour grapes" now, ICC has to do everything to improve umpiring. And Steve Bucknor has to go!

Aussies can win any match....

Observations based on the second test:
  1. Aussies lost 6 wickets fairly quickly in the first inning. It could have been easily 200 all out. But, one player [Symonds] gets multiple lives! He goes as not out.
  2. So long as Steve Bucknor officiates matches India has no chance. He does not ask for third umpire at times when Indian team needs most.
  3. Even the third umpire seems to "get it wrong" [what was he doing other than watching TV?]
  4. Umpire (Mark Benson) asks the Aussie fielder to check whether Ganguly was out or not!! Why not call out third umpire or ask the batsman as well? [never mind even the third umpire gets wrong to help the Aussies!]
  5. They can play so called "mind games". Even a bunch of former players and local media bat and bowl for their team. Other teams don't have this luxury or haven't learned the "art". They write/talk about so called "weakness" of opponents, "talk a lot" during fielding/batting. But, claim racial abuse when the opponent talks. I don't believe Aussies are talking the truth here. Why should anyone believe Aussie players? They claim catch after picking up the ball from the ground. Aussie players don't walk when they know they are out. ( "I was out when I was 30 - given not out. I can sit here and tell you about some bad decisions as well, but I won't. That's the game." Andrew Symonds tells). That talks a lot about their honesty. Why should anyone believe them? I believe (like many in India) this may be one of the tricks by Aussies. Unless the umpires have seen/heard something or TV has captured something, it is not fair to punish Harbhajan Singh based on the words from Aussies.

Saturday Jan 05, 2008

blu-ray.. blu-ray...

I am thrilled to know this news!! And that is not without a bit of self-interest. I work on some blu-ray related activities @ Sun (more on that in future!).

BTW, if you are interested in learning about blu-ray and related Java programming platform called BD-J, you may consider the following:

Thursday Jan 03, 2008

Latest on the Scripting project

Updates on the Scripting project.

  1. Updated JavaScript script engine with Rhino version 1.6R7. This version supports E4X without requiring XMLBeans.
  2. Updated Groovy script engine to use version 1.5.1.
  3. Updated Jython script engine to use version 2.2.1.
  4. Updated Freemarker script engine to use version 2.3.11.
  5. Yoko Harada is planning to update JRuby script engine with version 1.1x.

Wednesday Jan 02, 2008

13 players in a 11 player sport?

13 players in a 11 player sport? And "that's cricket"??

Monday Nov 12, 2007

What's new with Scripting for the Java platform?

Sorry about the looo..ng hibernation! Now, it is time for updates on the Scripting project.

  1. Yoko Harada updated JRuby script engine with JRuby 1.0.2 and added few other fixes in engine code.
  2. I've pre-built binaries of the project (uploaded the .zip and .tar.gz files)

Three new jsr-223 compliant script engines:

  1. JavaFX Script interpreter had jsr-223 support. Now, the JavaFX Script compiler has jsr-223 support -- you may want to checkout JavaFX Script compiler project. The following code works as expected:
    import javax.script.\*;
    public class Test {
        public static void main(String[] args) throws Exception {
            ScriptEngineManager m = new ScriptEngineManager();
            ScriptEngine e = m.getEngineByName("javafx");
    Please note that you need to build JavaFX Script compiler by checking out sources from the SVN repository and put the jar in the CLASSPATH.
  2. Xavier Clerc sent a link to the jsr-223 script engine for the Object Caml language. Thanks!
  3. Alexandre Bergel sent a link to the jsr-223 script engine for the Smalltalk language. Thanks!

Happy scripting!

Monday Sep 10, 2007

javac's hidden options...

javac has "hidden" and "even more hidden" options. This blog entry is about how to use one such option without actually modifying javac's source code. [Read More]

Monday Jul 30, 2007

ANTLRWorks and fun with grammars

If you are a programming languages enthusiast, you'll probably like this. I downloaded ANTLR Parser Generator. In addition to ANTLR, I downloaded the following:
  • ANTLRWorks - a grammar development environment for ANTLRv3.
  • Java 1.5 ANTLR Grammar It is fun to navigate/debug/view grammars and parse trees. Parse tree of a simple Java class looks as follows:

Saturday Jul 28, 2007

If you don't live in Chennai, please skip this post...

I've been receiving many "wrong" calls these days. Apparently, there is a hospital with a telephone number starting with "2664". And my telephone number starts with "2446" and the rest of the digits are same! Looks like folks get confused and dial "44" instead of "66". I end up receiving calls to "Dr. XYZ" at odd times!! Now, I understand what doctors have to go though in their life. Our after working hour conference calls are lot better - at least our US friends understand time zone difficulties and schedule meetings around 8 AM west coast time (which is ~ 8.30 PM in India).

Saturday Jul 14, 2007

Week-end fun with the java compiler source code

I downloaded java compiler (javac) source code from the JDK 7 site. I did not download entire JDK – I just downloaded compiler-7-ea-src-b15-05_jul_2007.zip I've installed JDK 6 and NetBeans 5.0

I extracted the source zip file into c:\\javac directory. From NetBeans IDE, File->Open Project menu, I chose c:\\javac\\compiler directory. Then, I build the project – I scrolled the build output log to the end and I saw:

Building jar: C:\\javac\\compiler\\dist\\lib\\javac.jar


Copying 1 file to C:\\javac\\compiler\\dist\\bin


BUILD SUCCESSFUL (total time: 8 seconds)

So, I tried to run the newly compiled java compiler. I attempted to compile a simple “Hello World” program. I got the following error:

C:\\javac\\compiler\\dist\\lib>java -jar javac.jar Hello.java

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main

What happened? I looked at the build log again. I missed the following lines – because I had seen only at the end!!

Copying 7 files to C:\\javac\\compiler\\build\\bootclasses

recompiling compiler with itself

javac: invalid flag: C:\\javac\\compiler\\build\\classes

Usage: javac <options> <source files>

use -help for a list of possible options

Java Result: 2

Copying 7 files to C:\\javac\\compiler\\build\\classes

Copying 1 file to C:\\javac\\compiler\\build\\classes\\com\\sun\\tools\\javac\\resources

Building jar: C:\\javac\\compiler\\dist\\lib\\javac.jar


Copying 1 file to C:\\javac\\compiler\\dist\\bin


BUILD SUCCESSFUL (total time: 8 seconds)

Looks like there is a build error. The compiler in built in two steps:

  1. The sources are built with javac in JDK 6 (on which my NetBeans IDE ran)

  2. Then, compiler sources are built again – but this time with the new compiler binary generated by step (1).

Looks we got error in the step (2) [see above: recompiling compiler with itself] . I searched the ant script used to build for “recompiling compiler with itself”. The following is the fragment after that:

<echo message="recompiling compiler with itself"/>

<pathconvert pathsep=" " property="src.javac.files">


<fileset dir="${src.classes}">

<patternset refid="src.javac"/>




<java fork="true" classpath="${build.bootclasses}" classname="com.sun.tools.javac.Main">

<arg value="-sourcepath"/>

<arg value=""/>

<arg value="-d"/>

<arg file="${build.classes}"/>

<arg value="-g:source,lines"/>

<arg line="${src.javac.files}"/>


The problem seems to be with “java” command above. Empty string is set as value for -sourcepath option. I changed that to the following:

<arg value="-sourcepath"/>

<arg value="${src.classes}"/>

When I re-built the compiler after the above change, there were no errors – yes, I scrolled the build output to check it :-) And newly compiled javac could compile “Hello World” program.

Now, I wanted to make some to “interesting” but simple change to the compiler source. From a “doc” page, I came to know that there is a hidden javac option called “-printflat”. It appears that with -printflat option javac prints source code after doing transformations for generic types, inner classes, enhanced for-loops, assertions etc. It would be great to visualize the kind of transformations done by javac. So, I wanted to make “hidden” option available. I searched for “printflat” in the project. I got three hits:

  1. JavaCompiler.java

  2. RecognizedOptions.java

  3. java.properties

As usual, I am impatient – wanted to enable printflat option always [regardless of what the command line is]. So, I changed the following line in JavaCompiler.java

printFlat = options.get("-printflat") != null;


printFlat = true; // options.get("-printflat") != null;

so that the secret option is enabled always. After rebuilding the compiler, I tried compiling my “Hello World” program. Surprise! I got the following error:

C:\\javac\\compiler\\dist\\lib>java -jar javac.jar Hello.java

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main

When I checked “javac.jar” by “jar tvf javac.jar”, I saw only “.java” files instead of “.class” files! Remember I mentioned that javac is recompiled by itself (step (2) above)? Apparently with “-printflat” option, javac just write transformed files but does not generate .class files! Because I had hardcoded printflat to be true always, during the second bootstrap compilation javac did not generate .class files. Looks like my lazy way does not work! I need to find how to really change the code to accept printflat command line option explicitly. I cut the story shot and just summarize the changes I made:

  1. added a enum value to com.sun.tools.javac.main.OptionName – PRINTFLAT("-printflat");

  2. In com.sun.tools.javac.main.RecognizedOptions class, I added PRINTFLAT to “static Set<OptionName> javacOptions” initialization value.

  3. In public static Option[] getAll(final OptionHelper helper) method of RecognizedOptions class, I added “new HiddenOption(PRINTFLAT)” as an element in the returned Option[].

I managed to compile and run the compiler after the above changes! Now when I can pass “printflat” option!! I compiled the following simple Book.java:

class Book {
  private String name;
  public Book(String name) {
     this.name = name;

  class Order {
     private int quantity;
     public Order(int quantity) {
        this.quantity = quantity;

with the following command:

c:\\javac\\compiler\\dist\\lib\\>java -jar javac.jar -printflat c:\\Book.java

Now, I can see the generated Book.java and Book$Order.java in the current directory where java compiler was run:

class Book {
    private String name;
    public Book(String name) {
        this.name = name;

class Book$Order {
    /\*synthetic\*/ final Book this$0;
    private int quantity;
    public Book$Order(/\*synthetic\*/ final Book this$0, int quantity) {
        this.this$0 = this$0;
        this.quantity = quantity;

Wow! I can see how java compiler generates a hidden synthetic parameter for the outer class object and so on. Note that the java compiler does not overwrite your original source files. You need to run the compiler in a different directory – compiler generates new files [which is good, you won't accidentally overwrite your original code with generics, inner classes and so on].

Now, you can experiment with constructs like asserts, inner class methods accessing outer's private methods/fields, anonymous/local classes, local class accessing final parameters/locals of enclosing method, generics, enhanced for-loop and so on and see how java compiler transforms those constructs to generate good-old “flat” classes without these features. Have fun!!




« May 2016

No bookmarks in folder


No bookmarks in folder


No bookmarks in folder