Showing posts from 2012

Performance comparison of Executor framework vs Fork/Join framework’s RecursiveTask feature in java or JDK7

I was testing new RecursiveTask feature of ForkJoin framework introduced in JDK7 or Java 1.7.

There are two types of ForkJoinTask specializations:
Instances of RecursiveAction represent executions that do not yield a return value. In contrast, instances of RecursiveTask yield return values. I have already posted an example of RecursiveAction in previous post. To know more about theoretic details and RecursiveAction sample code, you can visit the link: How to use Fork-Join Framework features in JDK7?

In this post I will do comparison of Executor Framework Vs ForkJoin framework's RecursiveTask feature. Following example fills primitive long array of size 100000000 with values from 0 to 10000000.

I use executor framework to calculate the sum of whole array  then I perform same logic using ForkJoin framework's RecursiveTask feature. To setup the example, I will first show the code which uses executor framework and its result then I will show ForkJoin framework's RecursiveTask …

How to use Fork/Join Framework's RecursiveAction feature in JDK7?

JDK 7 has new additions for supporting parallelism using ForkJoinPool executor that is dedicated to running instances implementing ForkJoinTask.

ForkJoinTask objects feature two specific methods:
The fork() method allows a ForkJoinTask to be planned for asynchronous execution. This allows a new ForkJoinTask to be launched from an existing one. fork() only schedules a new task within a ForkJoinPool, but no child Java Virtual Machine is ever created.In turn, the join() method allows a ForkJoinTask to wait for the completion of another one.There are two types of ForkJoinTask specializations:
Instances of RecursiveAction represent executions that do not yield a return value. In contrast, instances of RecursiveTask yield return values. You can checkout RecursiveTask code sample at link: Performance comparison of Executor framework vs ForkJoin framework’s RecursiveTask feature in java or JDK7Following example illustrates how to use RecursiveAction type of ForkJoinTask implementation:

Code Sampl…

How to use node.js?


Node.js is a platform built on Chrome's JavaScript run-time for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Node.js is a server-side version of JavaScript. That means all the things all them cool things about JavaScript apply here.

What makes Node any different from the rest?
Node is evented I/O for V8 JavaScript. V8 is Google’s super fast JavaScript implementation that’s used in their Chrome browser. JavaScript’s ability to pass around closures makes event-based programming dead simple.

Node is not strictly for web development. You can think of Node as a framework for server development of any kind. With Node you can build an IRC server, a chat server, or HTTP server as done in following hello world example. 

You can use node.js to create light weight web server. See the foll…

How to create android 4 ICS emulator UI in tablet mode instead of phone mode?

Till now I was developing android application for Android 2.3.3. Now, I have started development for Android 4.0.* ICS (Ice scream Sandwich) version. I created new Android 4.0.3 image using AVD manager targeting API Level 15. Emulator runs but UI is in phone mode instead of tablet mode.

After some investigation I found following solution:
Step1: Goto AVD Manager.
Step2: Select Android 4.* AVD image.
Step3: Click Edit button on right side in AVD Manager UI.
Step4: Change skin type from "Default (WVGA800)" to "WXGA800" or WXGA720. (which ever resolution works for you)
Step5: Click Edit AVD button.
Step6: Start your Android 4.* emulator. This time you should see Android tablet like emulator UI.


How to use keytool in java to generate key store to use MapView in Android?

Android MapView needs a MD5 key to access Google Maps on Android device or emulator. To do that we need to generate key store using java toolkit's keytool.exe.

Following command shows how to generate key store using keytool:
Command: C:\Program Files\Java\jdk1.6.0_30\bin>keytool -genkey -alias android -keyalg RSA -keystore <keystre.jks-path> -keysize 2048 -keypass <password>

For above command you can you JDK 1.6 or JDK 1.7. I tried the command with both versions.

How to find the MD5 key store if you have already generated it in past?
Command: keytool -list -v -keystore <keystore path>

Above command will ask you for that password. Provide the password you used to generate the key store. If you are using JDK 1.7 then don't forget to mention "-v" in above command otherwise you will get "SHA1" key only as output.

Issues faced:
1. I noticed in few post people mentioned that use keytool.exe from JDK 1.6, using JDK 1.7 key tool generates key s…

Why do I get debug certificate expired error when I debug Android app from Eclipse?

When I ran my Android app from eclipse IDE I got "Error generating final archive: Debug certificate expired" error at the console. I investigated on net and found following solution for the issue:

Step1: Goto "C:\Users\<user-name>\.android" (In fixed in Windows 7)
Step2: Delete "debug.keystore" file there or delete your debug certificate under ~/.android/debug.keystore on Linux and Mac OS X.
Step3: The Eclipse plugin should then generate a new certificate when next time you try to build a debug package. You may need to clean and then build the project to generate the certificate.

The self-signed certificate used to sign your application in debug mode (the default on Eclipse/ADT and Ant builds) will have an expiration date of 365 days from its creation date.

Note:You cannot release your application to the public when signed with the debug certificate.


Playing around to Compiling Java Files At Runtime using Compiler API, as a result of JSR 199.

I was playing around to compiling java files at runtime using Compiler API as a result of JSR 199.  I used source at Compile Java Files At Runtime. From the source "ToolProvider.getSystemJavaCompiler()" at line 28 was returning null. Posting here so it might help someone else facing same issue in future.

I was getting java.lang.NullPointerException so I did "System.out.println(System.getProperty("java.home"));" and noticed my eclipse was pointing "C:\Program Files\Java\jre7" even after I changed my preferences to use JDK1.7 in place of JRE1.7. This error accors if java development envrionment points to JRE instead of JDK as it is menioned in a bug report at link:

I found a work around by forcing to use JDK1.7 by setting system property like this: "System.setProperty("java.home", "C:\\Program Files\\Java\\jdk1.7.0_02");"

Then I compiled my program and did not…

Getting Started with Scala

I started my learning by doing fresh eclipse 3.6 + Scala 2.9 build setup. Setup failed first time but second time I was able to create sample project and run few sample programs. Scala IDE download link is mentioned in references link at the bottom of this post. Now it is time to take deep dive into Scala world!

Why Scala? Scala is a SCAlable LAnguage.

Scala is a functional-object hybrid language with several powerful factors working in its favor:
1.    Scala compiles to Java byte code, meaning it runs on the JVM. In addition to enabling you to continue leveraging the rich Java open-source ecosystem, Scala can be integrated into an existing IT environment with zero migration effort.
2.    Scala is based on the functional principles of Haskell and ML, yet still borrows heavily from the familiar object-oriented concepts Java programmers love. As a result, it can blend the best of both worlds into a whole that offers significant benefit without sacrificing the familiarity …

Why Android 2.3 apps can not access telephone API's or modify call state using MODIFY_PHONE_STATE permission?

I tried to record call as well many others are trying all over the world. Android 2.3 does not allow you to do that as far as i know. I refereed following links:


Above linked seemed to help. Many people told it worked from them in Android 2.1 and Android 2.2 but it does not work with Android 2.3. I got error message: "java.lang.SecurityException: Neither user 10035 nor current process has android.permission.MODIFY_PHONE_STATE." 

To capture call or pickup call programatically you need to use "android.permission.MODIFY_PHONE_STATE" permission in AndroidManifest.xml. From Android 2.3 onwards developers are not allowed to access this permission. Only venders with OEM license can use it for any apps which come preloaded on Android device when you …

What is LazyPanel convenience class in GWT and how to use it?

The gwt lazy panel has a createWidget method that is created when lazyPanel.setVisible("true") is called, making it possible to reduce initial loading of a panel. It is a convenience class to help lazy loading of a panel. The bulk of a LazyPanel is not instantiated until setVisible(true) or ensureWidget() is called.

This class primarily can be used in conjunction with StackPanel, DisclosurePanel, and TabPanel when the child panels contain relatively heavy weight contents. It can a speed your GWT UI load time if LazyPanel is used wisely.

Check out following links for more information:

API documentation link:

Example link:

How do I optimize GWT compiler for faster compilation?

I use eclipse IDE for my GWT application development. GWT is a great way to develop web applications but to do quick server side code test takes long time due to GWT compilation process. Thankfully I found a way to speed up GWT compilation by making small configuration changes.

If you are targeting specific browser then you can always define user agent in UserAgent.gwt.xml file as follows:

<set-property name="user.agent" value="ie6"/>

You can also speed up by isolating locales as follows:

<extend-property name='locale' values='en'/>

In the newer versions of GWT, you can add <collapse-all-properties /> to your yourapp.gwt.xml for development purposes. That will tell the GWT compiler to create a single permutation which covers all locales and browsers. That means you can test in all browsers and languages but are still only compiling a single permutation.

Compiling a single permutation that handles all browsers and languages still ta…

where is AndroidManifest.xml file in monodroid project?

You won't see an AndroidManifest.xml in a project by default. If you do decide to, you can manually create it or create it in the project properties. This file the permissions that an application needs to run. This can include things like the version of the API required for an application to run as well as access to what features on the device an application needs. These can be set by editing the file hand or by modifying the project's properties -> Android Manifest Tab.

For more information, visit following link:

Title: Working with AndroidManifest.xml

How to access GWT application running in development mode from different machine?

I was using eclipse for my GWT application development. I wanted to test GWT application from different browsers. I was unable to access my GWT test application running on development mode from external machine. After bit of investigation, I found below solution that helped me expose development mode application to external IP address.

In eclipse Go to -> Debug Configurations... -> Arguments -> Program arguments -> add param at the end " -bindAddress" -> Apply -> Start Debug