Wednesday, November 17, 2010

Capital IQ - Moving To McGraw Hill Financials

In a move to foster innovation and drive growth, The McGraw Hill Companies (NYSE: MHP) announced several Organizational and Management changes a few days back (November 15th 2010).

Though there are a few Management changes, I will be mostly stressing on the Organizational changes here. From a bird's-eye view, the current financial services of McGraw-Hill will be realigned into two segments - Standard & Poor's and McGraw-Hill Financials.

Currently, McGraw-Hill Companies is divided into three segments -

  1. Financial Services which includes Standard & Poor's Credit Market Services and S&P Investment Services (which includes Capital IQ)
  2. McGraw-Hill Education
  3. Information & Media

Beginning January 1st, 2011, McGraw-Hill Companies' reporting segments will be -

  1. Standard & Poor's - the leading credit rating company
  2. McGraw-Hill Financials - combining Capital IQ (including ClariFI, Compustat, etc.), S&P Indices, Valuation & Risk Strategies and Equity Research Services
  3. McGraw-Hill Education - the world's premier education services company
  4. McGraw-Hill Information & Media - a global business information company

The words of Harold McGraw Hill III, President and CEO of the McGraw Hill Companies on the strategic decision -

"This change will enhance our ability to deliver a broad and deep suite of products for investors across asset classes around the world, positioning us to capitalize on the growth trends we see in the global financial markets."

Check out the official announcement here. Coming to the impact of this decision on the Capital IQ brand - I guess our tagline "A Standard & Poor's Business" might change accordingly. However, there hasn't been any official confirmation on this. I will post in an update if we have anything.

Monday, November 15, 2010

RockMelt - Will Melt Your Heart

In my previous post I said I would be writing about Hibernate in this article, however I made an exception to write about a new browser I just started using - RockMelt. RockMelt is a social media web browser developed by Tim Howes and Eric Vishria and backed by Netscape founder Marc Andreessen.

It wouldn't be an overstatement if I say that it will melt your heart, especially if you're into social networking and particular a regular Facebook user like me. Here's how RockMelt looks like -

By this time, I guess most of you must have realized that it looks pretty much like Google Chrome. In fact it is more-or-less Chrome itself. Developers who have been interested in Google Chrome would have heard about Google's Chromium project - the open source project from which Chrome was born. Chromium was the parent of browsers like Nickel and now RockMelt.

However RockMelt was built to target a specific crowd - the Social Networking generation, especially users of Facebook and Twitter. Let me highlight a few features of RockMelt which I found interesting -

Friends Strip

RockMelt integrated Facebook's chat application directly into the browser as a strip running in the left side. The chat UI is pretty impressive; in fact it is as good as Google Talk. The best part is that each chat window now runs as a desktop app independently of the browser allowing users to use chat windows individually like Google Talk.

Status Updates

Updating your status in Facebook is just a click away from any site. With RockMelt, you need not actually go to Facebook to change your status or share a link. The browser itself allows you to do it.

RSS Feeds

The best thing I liked about RockMelt was its integration of RSS/ATOM feeds with the browser itself. Though many browsers manage feeds, nothing can beat this. The integration of the feeds as a strip to the right is really awesome. By default, feeds of Twitter and Facebook are built into the browser. Feeds from other sites like Gmail and Blogs can be added easily.

For people who use browsers only for surfing the web and reading articles, these changes won't be much and the regular Chrome browser should be enough. But people who are into Networking, Blogging, etc. will find it exciting and might enjoy it.

RockMelt was released a few days back and is presently “By Invitation” only and if you are interested, you should register yourselves here for an early access - http://www.rockmelt.com/. Lucky I got an invitation from one of my friends :). So if you want to try it, either register at the mentioned site or catch hold of a friend who already has an invitation :D.

Know more about RockMelt straight from the horse's mouth -

I will back on Hibernate and ADO.NET Entity Framework in my next two posts. Until then Happy Facebooking and Happy Twittering :)

Friday, November 12, 2010

Object-Relational Mapping

Over the years we have seen a paradigm shift in Programming Languages from the traditional Procedural programming approach to an Object-Oriented approach. However Databases have changed very little in terms of their fundamental principle - Set Theory. Databases are and have been Relational almost from their advent. Most of the Database Management Systems which we use like MySQL, Microsoft SQL Server and Oracle are Relational to a very large extent. Though there have been approaches like Object-Relational DBMS and Hierarchical DBMS, they have rarely been adopted in production environments.

This article focuses on creating a relationship between Object-Oriented Programming Languages and Relational Databases through a concept called Object-Relation Mapping. This article will be followed by two related articles - Using Hibernate in Java with NetBeans and Using ADO.NET Entity Framework in .NET (C#) with Visual Studio.

Before jumping into ORM, here are two common concepts which most of you must be familiar with -

Class - A class is a construct that is used as a blueprint (or template) to create objects of that class. A class defines the properties that each and every object possesses.

Table Schema - A table schema primarily defines the fields and relationships of a table. A table contains records which have the same structure.

Observing closely, we can notice that these two definitions are pretty similar. Both of them talk about a template which multiple instances follow (objects in OO and records in DBMS). Both of them talk about fields (properties) these instances possess.

This similarity is the basis of ORM. Table Schemas of Relational Databases correspond to Classes in an Object Oriented Programming Language and Records of these tables correspond to instances of the Classes (Objects).

Consider an example of a Student table in a Database created with the following schema -

CREATE TABLE Student_tbl
(
StudentId INT PRIMARY KEY,
Name VARCHAR(MAX),
Age INT
)

This table can be translated into a Class with the following structure -

class Student
{
Int32 StudentId;
String Name;
Int32 Age;
}

Each record of the Student_tbl will be an object of the Student class.

There are several free and commercial packages for Object Oriented languages that perform Object Relational Mapping. Most of these packages incorporate advanced features like -

  • Automating the class generation process from the Database Schemas
  • Maintaining foreign key dependencies using Lists
  • Generating identity keys while inserting records and using these keys in subsequent insertions as foreign keys if required
  • Creating methods for retrieving data and saving data directly as objects

The major advantages of ORM lie in -

  • Minimal database dependency - most of the ORM packages use a concept called 'Dialect' to identify the DBMS the application is connecting to. So changing the dialect when the DBMS is changed is sufficient for the application to run. No application code has to be changed
  • ORM reduces the amount of code that needs to be written by a developer

However it is often argued that ORM packages don't perform efficiently during bulk deletions and with joins. So generally it is recommended to check if there a hit in the efficiency of the application when ORM tools are introduced, especially when complex operations are involved.

Though ORM is a simple concept, it's a rapidly over-shadowing the traditional database connectivity models in Object Oriented Programming Languages like Java and C#. In my next post, I will be introducing Hibernate - an ORM package for Java and in the subsequent post I will introduce the ADO.NET Entity Framework - an ORM package for .NET.

Sunday, September 26, 2010

Standard Compression Scheme For Unicode (SCSU) - Java & .NET Implementations

In the previous article, I introduced the compression techniques available in SQL Server and highlighted the Unicode Data Compression feature of SQL Server 2008 R2. This post will cover the algorithm used by SQL Server for Unicode compression.

The Java and .NET (C#) implementations of the algorithm have been attached to the post. They have been built as Class Libraries to support reusability.

Standard Compression Scheme for Unicode

As evident from the post title, the algorithm used in Unicode Data Compression is the Standard Compression Scheme for Unicode (SCSU). SCSU is a technical standard for reducing the number of bytes needed to represent Unicode text. It encodes a sequence of Unicode characters as a compressed stream of bytes. It is independent of the character encoding scheme of Unicode and can be used for UTF-8, UTF-16 and UTF-32.

I am not going to explain the entire SCSU algorithm here but you can get its specifications from the Unicode Consortium. The SCSU algorithm processes input text in terms of their Unicode code points. A very important aspect of SCSU is that if the compressed data consists of the same sequence of bytes, it represents the same sequence of characters. However, the reserve isn’t true; there are multiple ways of compressing a character sequence.

Applications/Organizations using SCSU -

  • Symbian OS uses SCSU to serialize strings
  • The first draft of SCSU was released by Reuters, a news service and former financial market data provider. Reuters is believed to use SCSU internally
  • As already mentioned, SQL Server 2008 R2 uses SCSU to compress Unicode text

To be honest, SCSU has not been a major success. There are very few applications which need to compress Unicode Data using a special compression scheme. In certain situations, especially when the text contains characters from multiple character sets, the compressed text can end up being larger in size than the uncompressed one.

SQL Server and SCSU

SQL Server stores data in the compressed format only if it occupies lesser space than the original data. Moreover there must be at least three consecutive characters from the same code page for the algorithm to be triggered.

A major issue with the implementation is determining whether the stored text is in compressed or uncompressed format. To resolve this issue, SQL Server makes sure that the compressed data contains an odd number of bytes and adds special case characters whenever required.

The SQL Server implementation details are from a blog post by Peter Scharlock, a SQL Server Senior Program Manager.

SCSU Implementation

Though the specifications of SCSU are pretty compressive and a sample Java implementation is available at the Unicode Consortium, the implementation isn’t reusable as it is built as a Console App.

Using the specification and the sample Java implementation, I built a similar implementation as a Class Library to encourage reuse. The implementation is available in two languages - Java and C#.

The Java implementation is made available as a NetBeans project and the .NET implementation is made available as a Visual Studio solution. The implementations come along with a sample Front End which uses the corresponding Class Library.

If you are planning to modify the source code of the implementations, please keep these points in mind -

  • The .NET implementation differs from the Java implementation on a basic fact that the byte in Java is signed and the byte in .NET is unsigned. sbyte is available in .NET but using byte is more comfortable
  • Both the implementations have been tested for UTF-16 Little Endian encoding schemes. Since the default behavior of a Unicode character in Java is Big Endian, a few tweaks have been implemented

Example

To check the integrity of the SCSU implementations, a sample text file contains text from German, Russian and Japanese (the same text available at the SCSU specifications site) is taken and verified if the compressed text is as expected. The size of the file was compressed from 274 bytes to about 199 bytes.

The source code of the Java and .NET implementations can be found here. If you find any bugs, please let me know and I will make the necessary modifications.

Friday, September 17, 2010

Unicode Data Compression In SQL Server 2008 R2

SQL Server 2008 R2 was released a few months back and one of the features I found interesting was its ability to compress Unicode data. In this post, I will be introducing the various compression options available in SQL Server and towards the end I will emphasize a sample analysis used to estimate the efficiency of Unicode Data Compression and the Compression-Ratio improvements of SQL Server 2008 R2 over SQL Server 2008.

In my next post, I will emphasize on the actual algorithm used by SQL Server to achieve this compression and will provide the Java and .NET implementations of the algorithm.

Compression Techniques in SQL Server

In computer science, compression is the process of encoding information in fewer bits than an un-encoded representation would use. The compression techniques available in SQL Server can be broadly categorized into two types depending on the way they are architected - Data Compression and Backup Compression.

Data compression occurs at runtime, the data is stored in a compressed form to reduce the disk-space occupied by a database. On the other hand, backup compression occurs only at the time of a backup and uses a proprietary compression technique. Backup compression can be used on a database that has already undergone data compression, but the savings might not be significant.

Data compression is again of two types - Row level Data Compression and Page level Data Compression. Row level compression primarily turns fixed-length data-types into variable data-types, thereby saving space. It also ignores zero and null values saving additional space. Because of this, more number of rows can be accommodated in a single data page. Page level compression initially performs Row Level compression and adds two additional compression features - Prefix and Dictionary Compression. As evident, page level compression offers better space saving than row level compression.

Though compression can provide significant space saving, it can also cause severe performance issues if misused. For further reading on compression, refer "An Introduction to Data Compression in SQL Server 2008".

As the name suggests, Unicode Data Compression comes under Data Compression, and to be more specific it's a part of Row-level Compression.

Sample Analysis

Microsoft had promising stats on the Unicode Data Compression in SQL Server 2008 R2, going up to a 50% space savings on a few character sets like Hindi, German, etc. So I decided to give it a try myself.

Being from India, I decided to test the compression ratios for Hindi text. I created a randomizer in C# (.NET) to generate random text from a few Hindi phrases obtained from Linguanaut. The program generates 1.5 million random Hindi strings and writes them into a temporary file which is Bulk Inserted into a table.

To check the improvement of SQL Server 2008 R2 over SQL Server 2008 in terms of Data Compression, two separate instances of SQL Server were established on the same system configuration (Intel Core 2 Quad and 4 GB RAM). Both the instances had the same schemas for the databases and the tables. The Randomizer and the Schemas + Bulk Insert scripts are attached below.

A major drawback of Unicode Data Compression in SQL Server 2008 R2 was that it couldn't be applied on columns of the data type NTEXT and NVARCHAR(MAX) and to highlight this we used two different tables, one using NTEXT and another using NVARCHAR(250).

Here is a quick reference table of the compression-ratios obtained in the analysis -

SQL Server 2008
SQL Server 2008 R2
NTEXT
98.24%
98.25%
NVARCHAR(250)
95.68%
57.78%

From the above table, we can observe the compression-ratio for Unicode Data in SQL Server 2008 R2 is around 57% (nearly the space saving mentioned by Microsoft). However in all the other cases, we can observe that the saving savings is almost negligible. For space savings of other character sets refer "Unicode Compression (MSDN)".

Get the Visual Studio Solution of the Randomizer and the Database Scripts here.

SQL Server 2008 R2 Screen Shots

SQL Server 2008 Screen Shots

Sunday, August 22, 2010

Creating A Bootable Windows 7 USB Flash Drive

In this post, I am going to emphasize on how to create a bootable USB drive with the Windows 7 installer. It's a pretty simple and straight-forward process. There are several advantages of doing this -

  • Installing Windows 7 on computers without an Optical CD/DVD Drive. Many of the new laptops/desktops come without the CD/DVD drive. Using a bootable USB is very helpful here
  • Installing from the USB drive is typically faster than installing from a DVD drive
  • OS disc images (.iso, .nrg) need not be burned onto a CD/DVD to use them. You can make a bootable USB drive from the image and install the OS from the USB

There are two phases involved in the process - "Formatting the USB drive" and "Copying the installation files and making it bootable".

Formatting the USB drive

I am using the Diskpart command line utility in the following steps to format the USB drive. I guess even the Right-click and Format option can be used, but I haven't tried it. If you get into any trouble using the Format from the Right-click menu, put in a comment and I will look into it.

  1. Open the command prompt as an Administrator
  2. Start the DiskPart utility by typing in "diskpart". This will show a list of all the drives connected to the system. Identify the disk corresponding to the USB drive
  3. Select the USB drive using the "select ###" command
  4. Clean it using the "clean" command
  5. Create a primary partition on the USB using the "create partition primary" command. This is where we will be copying the installation files
  6. Select the partition using the "select partition 1" command
  7. Make it active by typing "active"
  8. Format the drive and create an NTFS filesystem on it using the "format fs=ntfs" command
  9. Assign a drive letter to the USB disk using the "assign" command
  10. Exit the DiskPart utility using the "exit" command

The USB is now formatted and is ready for the transfer.

Copying the installation files and making it bootable

The following steps are the crux of the process.

  1. Insert the Windows 7 DVD
  2. Navigate to the boot directory of the DVD
  3. There is a utility "Bootsect" which comes bundled in the Windows 7 DVD. This does the entire work for us
  4. Run the utility from the command line and specify the drive letter of the USB drive. bootsect.exe /NT60 X:
  5. The utility adds the appropriate boot-code to the USB drive
  6. Copy the contents of the DVD onto the USB drive

That's it, reboot the system, make sure that the USB boot is given the highest priority and the installation starts.

Saturday, August 07, 2010

Community TechDays August 2010

I spent my entire day today at Microsoft IDC, Hyderabad where I had a wonderful experience at Community TechDays organized by the Microsoft User Group, Hyderabad (MUGH). For people wondering what Community TechDays is - It is a multi-city event conducted quarterly by the technology community for Developers, Infrastructure Professionals, Architects, Project Managers and Students. This was the fourth Community TechDays series in India but the first one I attended.

The event started at around 9:30 and there were two parallels tracks - one for the Developers and another for the IT Professionals. Having registered for both, I attended the sessions which I found interesting in the two tracks. On a whole there were 5 sessions which I attended. I will give a brief description of the sessions I attended and will try to get the technical details on my Tech Blog sometime soon. But no promises on that :)

The first session was on the Data compression options in SQL Server 2008 by Arun Shankar which was pretty good. It covered how the database can be compressed during backup and various data compression techniques like row level compression and page level compression to reduce the size taken up the database. Following that was a session on IIS End to End by Muqeet Khan. To be honest, I didn't have much experience on IIS but had a reasonable exposure to web servers as a whole. So learnt a lot through the session and loved the concept of running languages like PHP and Java in IIS 7.0.

The next session I attended was on Cloud Services with Windows Azure Platform by Arun Ganesh. This was one session where content was very good but time was a major constraint. Initially he started with an introduction on Cloud Computing and a live demo on developing and deploying a sample application on Windows Azure. He also covered Azure Storage - Tables, Blobs and Queues with a live example. Though he introduced SQL Azure and Azure Services like Service Bus and Access Control, he couldn't cover a live example there. As I had prior experience in developing and deploying an Azure app, I was really looking forward for the demo on Service Bus and Access Control but was a bit disappointed at the end.

Post lunch, there was a session on WCF in .NET 4.0 and Windows Server AppFabric by Phani Kumar. This was a bouncer for me. With negligible hands-on experience on WCF, the session was way above my head. Though the speaker was explaining it well, me and my friends had a tough time co-relating it to what we did. The last session was more like an open discussion again with Muqeet Khan. It started with batch processing admin tasks in Power Shell and soon moved on how Windows works. It was more like a refresher of my OS class at college but more entertaining :D

The day ended with a curtain raiser of XBox Project Natal (more popularly known as Kinect for XBox 360) at around 4:30. I can't wait to get my hands on it when it comes to India in December this year.

Oh, the best part of the day - I guess we were among the youngest developers who came for the event today. It was actually interesting sitting in a crowd with people with work-experience of around 2-3 years with our work-experience of around 2-3 months ;)

Thursday, July 22, 2010

Ciao, Osmania University

It's been more than a month I left Osmania University and day after day I see my friends spread out to pursue their careers. But, whenever I go back in time, several sweet memories flash by before my eyes. To be honest, it's a little heart-breaking to realize that the college which I claimed to be mine is no more mine. But I still have what Osmania University has given to me - a whole lot of friends and a wonderful experience :)

One thing I understood at the end of this post was that these were the most happening four years of my life and I will definitely miss them :(

Four years back, I never thought that this time span would be over as quickly as it did. I still remember the day when I was at the EAMCET counseling, heart filled with anxiety, not sure which college I would get into and the seat-counters of various colleges go down one by one. As destiny wanted, I ended up at Osmania University, College of Engineering and then began a whole new chapter in my life.

Every one of these four years was special in its own way. In the first year, we were "The Juniors", with an unofficial formal dress code and living under the shadows of the seniors. To be honest, it wasn't as bad as it sounds. My seniors were really good and they did help us a lot and supported us when required. We also managed to learn several things from them over the years – both in terms of technology and event management. The first year ended with a magnificent freshers week at the "Landscape Gardens" and the freshers party at "Sixth Element".

Second year, we were "The Seniors" ;). We managed to have a lot of interaction with the our juniors and over a period of time we made a lot of friends among them. We had a lot of free time in the second year and even started bunking classes :D. We started exploring the college and spent a lot of time at the "Caroms Room". The second year ended with another freshers week and the freshers party at "F-Bar". I enjoyed making the freshers DVD and it will truly be one of my cherished possession of Osmania University.

All the career decisions began in the third year. A lot of my friends started taking up coaching for GATE and CAT. I was more focused towards taking up a job and didn't pursue either of the two. I joined Sun Microsystems Inc. as a Campus Ambassador (Technical Evangelist) in my third year and spent a year and a half working in it. Third year was a serious year concentrating on education and careers. And of course, the "Cricket Ground" :D. The third year ended with an Industry Attachment Program with Sun Microsystems Inc.

The fourth year was the fastest to pass by. Starting with a deep worry about job opportunities thanks to the recession impact in the country, it went by with me and my friends searching for jobs and spending countless moments at the "Placement Cell". Within a few months, the competitive exams like CAT and GATE came by and most of my friends were completely occupied with them.

Classes, Jobs, Exams and a little Fun - This is what fourth year was. And over and above all this, the Telangana Agitation ;). I even started my internship during the latter half of the fourth year along-side my final year project. I was literally beseeching for time the six months, but I believe it was worth the effort.

Over these years, I had several moments of fun and joy; and a few moments of sorrow and regret. But thinking back, I actually enjoyed each and every one of those moments. Well, time can never come back but it is the memory of these moments which brings about a warm smile on our faces.

Before I sign off, I would like to thank everybody whose has been a part of my college life over these years for giving me such a wonderful time and my sincere apologizes to anyone whom I have hurt knowingly or unknowingly. My deepest gratitude to the entire faculty for their guidance and putting up with all the juvenile things we have done. Wishing everyone the best of luck in their future endeavors and with a bright hope that our paths will cross again, Good Bye.

Thursday, July 15, 2010

Technology Team Outing 2010

Last week, the entire technology team of Capital IQ, Hyderabad went to Lahari Resorts. CIQ has a tradition wherein every year, every team goes out to a vacation spot to relax and enhance team bonding. So following the lines of this tradition, the technology team geared up this year to visit Lahari Resorts. The best part of this tradition is that the new joinees are responsible for the co-ordination of the entire event. Having joined Capital IQ last month as a fresher, the responsibility of organizing the event was on us and we had a great time organizing it :)

If you have already read Aishwarya's blog-post on the outing, this post may seem redundant, but before leaving, check out the photo show embedded at the end of the post. If you haven't read it, "Read On!".

After a lot of discussions and putting in a lot of thought, we selected Lahari Resorts for this year. Like any event, the major focus was on transportation, food, publicity and event management.

To lighten up the spirits of the team, we planned a few in-office events the day before the outing. We conducted various fun activities like "Logo identification" and "Recognizing the blurred images of various celebrities". To be honest, I never expected anybody to participate, but it was delightful to see people spare time from their work and participate in the events. And judging from their enthusiasm, I guess they had they had a very good time. We also designed posters and digital invitations to unleash the fervor.

The following morning, the D-day arrived, we all assembled in the office and moved on to the resort. Buses were arranged for people who didn't have their own vehicles. I went in a car, as me and a few others planned to reach a bit early so as to take care of the arrangements at the venue. From what I heard, the people in the bus had a wonderful time. Damn, I missed it :(

Once we reached the venue, we were in for the shock of our lives. The entire team had planned something for us, "The Freshers" - An Interaction. We were asked to introduce ourselves and do something - sing, dance, act, anything. For people wondering what I was asked to do - "Introduce myself in pure Telugu" (no laughing please ;)) and narrate a dialogue from a popular Telugu movie.

One thing which everybody in the office were waiting for were the Cricket tournaments. We booked a ground for ourselves and had several Cricket matches. In parallel a few of us played football and a few went directly into the pool.

After a few matches of Cricket and Football, we all plunged into the swimming pools. As the evening progressed, we assembled for a pool-side dinner. Simultaneously the dance-floor was opened. I personally felt that the Disco was the best part of the day. Initially a lot of people refrained from the dance-floor but eventually most of them ended up on it. It was nice to see people coming out of their shells and join us :)

We partied all night long and I reached home at midnight. I had a wonderful time and am enthusiastically waiting for the next party ;).

It would be unfair if I conclude without introducing the guys and girls who have made the event memorable - Aastha, Aishwarya, Anindya, Ankit, Arnav, Dinesh, Karthik, Niya, Preeti, Rajashree, Rohan, Sandhya, Sasikiran and Sudha - "New Joinees 2010" (Jame and Simanta - we missed you both)

And kudos to Raghu Vamsi, a year senior to us at CIQ, for his inspiring guidance through-out the event organization. Also my sincere regards to the entire Technology Team for making the night unforgettable.

And here's a small photo slide-show of the two days -

Saturday, July 10, 2010

Integrating OACurl With A Java Desktop Application

In my previous post, I introduced the Google Buzz API and the technologies surrounding it. In this post, I will be emphasizing on how to integrate OACurl with a Java Desktop Application to make the authentication process simpler. Before I continue, let me categorical state that this method is good for small student projects; but for serious production applications, OACurl integration isn't a good option.

OACurl is primarily an OAuth aware wrapper around the popular cURL command line utility. If you are wondering what cURL is, it is a software project providing a library and command-line tool for transferring data using various protocols like HTTP, FTP, HTTPS, LDAP, IMAP, POP3, etc. The beauty of cURL is that it simplifies the process of data transfer using these protocols to a very large extent. OACurl is an extension to this utility which supports OAuth, the authentication/authorization protocol of the Google Buzz API. OACurl provides an easy way to experiment with the Buzz API.

Before I start with OACurl Integration, let's see how we can connect a desktop application to the Google Buzz API without OACurl. As I mentioned in the previous post, the OAuth token request and authorization process takes place through a Web Browser. So the desktop application should open the Browser and allow Google to verify the user credentials. Then Google issues an authorized token to a Callback URL as specified by the application. This has to be detected by the application and it has to regain focus. For a more detailed view on this, check out - http://code.google.com/apis/accounts/docs/OAuthForInstalledApps.html.

The biggest challenge in this process is that in devices like Gaming Consoles, Setup Boxes, etc., where a Web Browser isn't available the entire procedure goes haywire. Google is working on a solution for this, until then we have to adjust with the Web Browser technique.

OACurl is a pretty easy tool to work with. It is available as a Java Archive with multiple classes for various operations like Logging in, Fetching data from URLs, etc. To use OACurl directly from the command-line, refer http://code.google.com/apis/buzz/v1/oacurl.html.

To use OACurl within a Java Desktop Application, add a reference to the jar file from your project. Now there are two classes which do the entire thing for us - Fetch and Login. Both of them contain a main method; actually it is these classes that are being used in the URL mentioned above. But instead of using classes from the command-line, we will directly call the main method in them from our Java program.

A bit of reverse engineering makes it clear that the flags like "-buzz", "-X", "POST", etc. are being sent as command line arguments. So we can create a String array of these flags and sent it to the main method.

com.google.oacurl.Login.main (new String[] { "-buzz" });
com.google.oacurl.Fetch.main (new String[] { "-X", "POST", URL });

The main methods push the output content to the default output stream as specified by System.out. By default, this is the user screen. If we want to use this output, we can transfer this output into a temporary file and read from this file.

File temp = File.createTempFile ("output", null);
PrintStream output = new PrintStream (temp);
System.setOut (output);

Similarly, the main methods read the input from the default input stream as specified by System.in. By default, this is the keyboard. If we have to send our input, we can create a temporary file, write the content into it and make the file the default input stream.

File temp = File.createTempFile ("output", null);
// Write into the file
PrintWriter writer = new PrintWriter (temp);
System.setIn (writer);

This way we can use the Google Buzz API within our Java Desktop Application without having to worry anything about the authorization process. Developers curious to know how this works can explore the OACurl project hosted on Google Code at http://code.google.com/p/oacurl/. The complete source code of the Login and Fetch classes as well as the Callback Server and other classes is available at the link.

Before I wind up, here is a small project developed in NetBeans which reads the latest buzz and publishes buzz content.

Saturday, June 26, 2010

The Google Buzz API

It's been a month Google released their Buzz API at Google I/O and I have been dying ever since to write an article on it. Finally got an opportunity today and really hope that the posts live up to my expectation :)

In this post, I am going to introduce the Google Buzz API and the technologies surrounding it like OAuth, REST, AtomPub and JSON. And in my next post, I will be emphasizing on how to integrate OACurl, an OAuth wrapper, with a simple Java Desktop Application. Most of the information in this post is pretty basic and if you are comfortable with these technologies, I would recommend you to skip the post.

Google Buzz

Google Buzz is a social networking and messaging tool from Google, designed to be integrated into Gmail. Google Buzz was an attempt by Google to compete with micro-blogging services like Twitter. After the release of the Buzz API, it has been well received both as a platform and as a service.

The Google Buzz API revolves around two main concepts - Authentication which is done through Open Authorization (OAuth) and Service Usage which is managed using the REST architecture with data formats like XML (through AtomPub) and JSON.

Authentication

OAuth is an open standard that allows users to share their private resources like photos, videos, etc. stored on one site with another site without having to hand out their username and password. It works through the exchange of tokens which provides access to a specific site for specific resources for a defined duration.

Most of Google Data APIs like the Google Calendar Data API, Blogger Data API, Google Contacts Data API, etc. use OAuth for authentication. The authentication process is done through a Web Browser for web applications as well as desktop applications using the APIs. A browser pops up and users are authenticated with respect to their usernames and passwords directly by Google and then the control is returned back to the application which can proceed accordingly.

A major disadvantage of this process is that a web-browser should be available for authentication even for desktop applications.

Service Usage

Data transfer for the Buzz API is done primarily on the basis of REST (Representational State Transfer). It is a style of software architecture for distributed hypermedia systems such as the World Wide Web. The crux of REST is that is uses the basic HTTP methods like GET, POST, etc. for resource manipulation (getting a resource, saving a resource, etc.)

Google Buzz API returns data in two formats - XML and JSON. XML is sent in the form of AtomPub. AtomPub (also known as APP) stands for Atom Publishing Protocol. It is a HTTP-based protocol for creating and updating web resources. It uses an XML language known as the "Atom Syndication Format" (ASF) and is very popular for web feeds. The Atom Syndication Format and AtomPub form the Atom Standard. The ASF is primarily an XML format with tags like feeds, links, etc.

Google Buzz API can also return back data in the form of JSON. JSON, standing for JavaScript Object Notation, is an open standard designed for human-readable interchange. Despite its strong relationship to JavaScript, it is language-independent with parsers available for almost every language.

The major reason for Google Buzz API to offer JSON besides ATOM was that JSON parsing is comparatively faster than XML parsing in JavaScript. So in web applications which might pull data from the Google Buzz API using JavaScript and AJAX, JSON parsing will be a major performance gain.

A Quick Example

Navigate to https://www.googleapis.com/buzz/v1/activities/userId/@public to see your latest public buzzes in the ATOM format and to https://www.googleapis.com/buzz/v1/activities/userId/@public?alt=json to see them in the JSON format.

There are several URLs like these available at the Google Buzz API site - http://code.google.com/apis/buzz/v1/using_rest.html. However most of them require authentication before they show the results, which means that without authorization by OAuth, a URL based mechanism will not fetch the data.

To know your userId, you can do the following steps -

  • Login to GMail and go to the Buzz tab
  • Click on your name which is displayed at the upper-left corner of the Buzz tab
  • The last handle (the string after the last /) is your userId

Saturday, June 19, 2010

NetBeans 6.9 - The JavaFX Composer Rocks

NetBeans 6.9 has finally been released a few days back, June 15th 2010 to be exact. It was a very special release in the NetBeans community as this was the first major revision after Oracle's acquisition of Sun Microsystems this January. Check out the release notes at http://netbeans.org/community/releases/69/relnotes.html.

Along with NetBeans, a minor revision of GlassFish, GlassFish 3.0.1 has also been released. The minor revision contains several bug fixes and the GlassFish Server Open Source Edition 3.0.1 has been integrated with NetBeans 6.9.

There are several new features which been added to NetBeans this time, like the support for Zend Framework on PHP, Ruby on Rails 3.0 Beta support, Spring Framework 3.0, JavaFX SDK 1.3, CSS Refactoring and Code Completion, support for JDK 7 and several other features. The complete feature enhancement list is available at http://wiki.netbeans.org/NewAndNoteworthy69.

But personally, I felt the best feature addition to NetBeans this time was the JavaFX Composer. For people who are new to JavaFX, it is a Java platform for creating and delivering Rich Internet Applications (RIA) that can run across a wide variety of connected devices like computers (as browser-based and desktop applications), mobile phones, TV set-top boxes, gaming consoles and Blu-ray players.

The JavaFX Composer is a visual layout tool similar to Project Matisse for Swing. Initially released as a plugin for NetBeans 6.8, it has now been completely incorporated into NetBeans 6.9. The primary features of the JavaFX Composer are -

  • Visual editor for a form-like UI using components
  • Dynamic design editing based on states
  • Data access to Web Services, databases and local storage
  • Support for JavaFX binding
  • Simple animation editor
  • Multi-screen-size editing

Create a new JavaFX project using the JavaFX Composer by navigating to File, New Project and choosing a JavaFX Desktop Business Application or a JavaFX Mobile Business Application under the JavaFX category depending on the requirement. Give a project name and the UI editor opens for creating the UI from the JavaFX components.

Drag and drop components from the palette and create the user-interface as you want. Here's a small echo application which echoes what has been typed in the text-box. To be honest, this is my first application in JavaFX and I could finish it by typing only a single line of code and that too a JOptionPane.showMessageDialog and I had help from the auto-complete feature of NetBeans for this :), rest of the work was done the JavaFX composer. That actually reflects the ease of development which the composer and NetBeans are driving. On a whole, a big thumps-up for the JavaFX composer and the entire NetBeans development team for integrating this into the IDE.

Download the project here.

If you give the JavaFX Composer a try, check out the huge arsenal of features which the palette possesses like Shapes, Effects, Charts, etc. You will definitely love them.

This blog-post was shown as a featured article on NetBeans -

Friday, June 04, 2010

Capital IQ - An Interns View

Successfully, my 6 months intern at Capital IQ which started on December 14th has come to an end on May 31st. These six months are a few of the best days in my engineering life which I can never forget.

After hiring us during Campus Placements at our college, Capital IQ gave us an offer to work for six months as an intern at their company. I was working for three days (Wednesday, Thursday and Friday) at Capital IQ and three days (Monday, Tuesday and Saturday) I had to attend classes at my college. I personally felt that this was a perfect blend of enjoyment and work.

I learnt a lot at Capital IQ and enjoyed more than what I learnt. I was a part of the Web Mining team and was working on a very critical project for the company at that time. I guess we were lucky to be in the team as we learnt a lot of technologies and understood a lot about the dynamics of the corporate world - bottom-lines, dead-lines, project management, etc. But as we were interns, there wasn't any pressure on us :)

The three days at office were fun and work. However, the remaining three days at college was completely fun :D. In fact, I think we bunked more classes than we attended :P

The project at college was another exciting thing, as we weren't allowed to submit the project which we were doing at Capital IQ, I had to work on a separate project. Though it was exciting to manage office, project and classes together at the same time, it did become very hectic.

On a whole I had a great time at Capital IQ along with the other interns (Aishwarya, Dinesh, Jame, Rohan, Sasikiran, Simantha, Sneha and Suvansh) and I joined Capital IQ on June 1st (the next day we completed our internship) as a full-time employee :)

Sneha and Suvansh - best of luck for your future, we will be missing you here and for the rest, nice to be working with you again. And before I sign out, a big thanks to the Placement Office of Osmania University and the entire hiring team of Capital IQ for the opportunity.

Monday, May 17, 2010

Cloud Computing Portal For SMEs - Curtain Raiser

As our final year project, two of my classmates (A. Raghuveer and G. Nishanth) and I are working on a project (Cloud Computing Portal for SMEs) under the domain of Cloud Computing.

In this blog-post, I will be introducing the domain of Cloud Computing and give a small overview of our project. In a few days, I will be unveiling the code along the documentation at - http://cloud-smes.appspot.com/, so keep checking this space for more updates.

Here's a short video about the project -

Cloud Computing

Cloud Computing is a paradigm in the field of computing. Technically, Cloud Computing is defined as -

"A computing capability that provides an abstraction between the computing resource and its underlying technical architecture, enabling convenient on-demand network access to a shared pool of configurable resources that can be rapidly provisioned and released with minimal management effort or service provider interaction."

From a customer's perspective, Cloud Computing is a cost-effective solution offering flexibility in usage at low investment costs. From a vendor's perspective, Cloud Computing helps in reducing the operational costs of a data-center with a high degree of customizability. Cloud Computing allows vendors to reach more and more customers with a low cost of delivery.

Cloud Computing is mainly built on its delivery mechanisms which define the service being provided by an application running in a Cloud Computing environment. There are hundreds of delivery mechanisms available like Infrastructure as a Service (IaaS), Platform as a Service (PaaS), Software as a Service (SaaS), and Data as a Service (DaaS).

Advantages of Cloud Computing include Reduced Costs, Increased Storage, High Levels of Automation, Flexibility, More Mobility, etc.

Cloud Computing Portal for SMEs

Small and Medium Enterprises (SMEs) are companies whose headcount or turnover falls below certain limits. In most economies smaller enterprises are greater in number. In many sectors, SMEs are responsible for driving innovation and competition. In India, the Micro and Small Enterprises sector plays a pivotal role in the overall industrial economy of the country.

Every organization consists of several applications like -

  • Financial Accounting
  • HR Payroll
  • Inventory Control
  • Management Systems

Every organization makes a certain investment in its core infrastructure for these applications and for scalability and expandability of this infrastructure; Cloud Computing Centers are viable solutions.

This approach is very useful in high-risk SMEs where the requirements are high, stability is low and sustenance is risky. This methodology allows such organizations to outsource their mundane housekeeping tasks to Cloud Computing Centers and pay as per their usage. This reduces their initial investments for hardware and software, minimizing their risk. As time progresses and things stabilize in the organization, situation can compare the available options and proceed accordingly.

Cloud Computing Centers benefit from the fact that they leverage their hardware and software across multiple SMEs. With appropriate planning, the breakeven point can be reached easily and as time progresses the center can profit from such a venture.

Understanding this potential market, the project concentrates on SMEs by providing them with business applications on demand. These applications form a web portal, which is distributed across multiple Cloud Computing environments to avoid vendor lock-in.

The applications covered as a part of the project are -

  1. Self-Managed Repository
  2. Name Finder
  3. Knowledge Management System
  4. Sales Management System
  5. Appraisal Management System

These applications are the primary requirements of any organization, irrespective of its sector - Education, IT, Banking, Automobiles, etc. and every organization needs them for its proper functioning.

Sunday, April 11, 2010

James Gosling Quits Oracle

Finally, James Gosling confirms the rumors that were going around the internet of his resignation from Oracle. On 9th April, he confirmed that he resigned from Oracle a week back (April 2nd, 2010).

The news struck as a big blow to the millions of Java developers and fans across the world. When asked about his decision of leaving the company, his response was truly terrifying. Here are the actual words he wrote at his blog -

"Just about anything I could say that would be accurate and honest would do more harm than good"

I personally think its high time Oracle comes out and does something to instill confidence in the huge developer-base of Java.

Thinking positively, I believe Java is mature enough to sustain itself and a single person leaving the company cannot kill the product.

Anyways, let wait and watch how the story unravels at the Oracle camp.

Check out his resignation article at his blog - http://nighthacks.com/roller/jag/entry/time_to_move_on

Thursday, April 08, 2010

Running Chromium OS In VirtualBox

If you would like to try Chromium OS without disturbing your system or without going through the trouble of downloading the source code and building it, this blog-post is for you.

The Chromium OS has been built and bundled as a VMWare image (.vmdk). This image can be used with VMWare workstation, but this piece of software isn't free. So in this blog-post I will be targeting the free virtualization application - VirtualBox.

Oracle VM VirtualBox is an x86 virtualization software package originally created by a German software company Innotek, purchased by Sun Microsystems and now being developed by Oracle Corporation as a part of its family of virtualization products. Download VirtualBox from http://www.virtualbox.org/wiki/Downloads

Download the VMWare image of Chromium OS as a zip file at - http://uploading.com/files/ff856c8d/chrome-os-0.4.22.8-gdgt.vmdk.zip

Extract the VMWare disk image from the zip using a compression utility like WinZip, WinRar or IzArc. Fortunately .vmdk images can be used in VirtualBox without any prerequisites, so we don't need a VMWare workstation to use the image.

I couldn't find a proper .vdi image when writing this article. If you find one, please post a link in the comments section. Either way, the series of steps will still be the same.

The following steps will get Chromium OS running in VirtualBox as a Virtual Machine.

  1. Start VirtualBox

  1. Create a new Virtual Machine

  1. Name the Virtual machine as Chromium OS and select the operating system type as Other/Unknown

  1. Allocate certain RAM for the operating system to run

  1. Use the existing available hard-disk (the image which we have just downloaded)

  1. The Virtual Media Manager ups on clicking the button beside the drop-down list

  1. Add the image file which was obtained after extraction

  1. The new image becomes the hard-disk for the virtual machine now

  1. Click on Finish to complete the process

  1. You can now see a new virtual machine docked on the right-hand panel of the window

  1. Double-click on the VM and Chromium OS boots up

  1. Login using your Gmail

That's it, Chromium OS is up and ready. Explore it!!!

Chromium OS

Chromium OS is the open source development version of the Google's Chrome OS. The source code of Chrome OS was released on November 19th, 2009 under the BSD license as Chromium OS.

Chromium OS aims to build an operating system that provides a fast, simple and more secure computing experience for people who spend most of their time on the web. It targets to build a powerful platform for developing a new generation of web applications.

Chromium OS is the name of the project and Google Chrome OS is the name of the product. But the developer builds are still termed as the Chromium OS.

But the advent of the Chrome OS has led to a bigger question – Do we really need a new Operating System? More specifically - Why Google Chrome OS?

The traditional boot-up process that we go through everyday involves a series of steps like -

  • Loading the BIOS
  • Hardware detection
  • Loading and starting the Boot-loader
  • Loading and starting the Kernel
  • Starting the OS primitives
  • Running the startup applications

Even the fastest computer in the world takes about 45 seconds for this to happen.

This was the focal point of Google while building the Chromium OS. For millions of naïve users who use their netbooks/laptops mostly for internet, 45 seconds is a lot of waiting time. Google plans to make the web browser the Operating System for fast boot-up and this OS is the Chromium OS. In fact Google is claiming a 7 second boot-up for the Chrome OS and in certain instances the boot-up time has been as low as 3-4 seconds.

The Chrome OS hasn't been released yet and the expected release date of the Chrome OS is late 2010 or early 2011. But technical enthusiasts can still get first impressions through the open-source Chromium OS project.

Google Chrome OS is built on the Linux kernel and is expected to be free on release, but then what’s the economy model of Google? - Chrome pushes Google web applications like Google Docs, Google Calendar, Picassa, Youtube, etc. The major revenue stream of Google is through its advertisements. More users of Google applications will yield more revenue to Google through advertisements.

All the applications utilized by the Chorme OS are cloud based applications. A major drawback is the customer trust on Google. All our documents – text docs, spreadsheets, and presentations are all on the Google cloud. How can an individual be sure that his documents are secure from unprivileged users? The recent crash of Gmail has strengthened the apprehension and has caused a panic about the cloud based OS of Google.

Major Drawbacks

  • Google is considering Chrome OS as a companion device. It is assuming that every user will have another work-station at their disposal
  • Vague support for working offline. Google is planning to provide a little support through Google Gears and local caches, but every the idea has to be solidified
  • Android applications are incompatible with Chrome OS
  • Chrome OS requires internet access for everything
  • Every application which users desire cannot be integrated into the cloud
  • Browser lock-in. No other browser can be used expect for Google Chrome

The Brighter Side

  • Speedy boot-up
  • Security by default
  • Support for both x86 and ARM architectures
  • Several applications are available by default like Google Docs and Microsoft Office Live
  • No need to install anything. Just plug-n-play

On a whole, Google has created a lot of buzz about its new Operating System. Let’s wait and watch. I recently was a part of a presentation around the Chromium OS - check it out here.

If you would like to try out Chromium OS for yourself, either follow the build instructions at http://www.chromium.org/chromium-os (or) check out my next post - Running Chromium OS in VirtualBox.

Sunday, March 28, 2010

Demystifying A Geek, A Nerd And A Dork

There have been a lot of misconceptions surrounding the usage of these three words - geek, nerd and dork. In fact they are considered offensive by many people.

Unfortunately, most of them don't even understand the difference between them. Here's a Venn diagram that shows how they relate to each other.

As evident from the Venn diagram, the classification deals with three major criteria - Intelligence, Obsession and Social Ineptitude. One major point to be noticed here is that the usage isn't restricted to education. A person who is obsessed with Cricket and is intelligent with respect to the game of Cricket can be considered as a Geek at Cricket. So the general stereotype of a guy with glasses reading a book for a geek isn't really a great notation.

Terming oneself as a geek/nerd/dork needs a really broad mind. On a whole being termed as a geek or a nerd need not be as offensive as it sounds and people with a really really broad mind might even take it as a compliment.

Coming to myself, I am not sure if I am intelligent, but I am definitely not socially inept. I am considered addicted to Computers and PC Games but not really obsessed, I guess.

I actually stumbled across the Venn diagram when one of my friends buzzed the link at Google Buzz. Do check it out if you would like to read the original article.

Monday, March 01, 2010

CAT 2009 - A Case Study

Finally, CAT 2009-2010 comes to an end. Most of the people who have appeared for CAT this year called it a debacle. I don't think the entire situation was that bad but the process could have been managed more professionally and more systematically.

For all the readers who have no idea what CAT is - CAT stands for Common Admission Test. It's an all India test conducted by the Indian Institutes of Management (IIMs) as an entrance examination for the management programs of its seven business schools. Besides the IIMs, CAT scores are used in several other B-Schools for admissions.

Last year, it was announced that CAT 2009 would be going online, that is CAT 2009 was becoming a computer based test. As time progressed it was decided that the major decisions regarding the examinations would be taken by the IIMs and the actual management of the exam would be outsourced to Prometric.

The IIMs are a few of the finest B-Schools in India. They produce a few of the best managers in the world and are known for their expertise in management. Prometric is a U.S. company in the test administration industry. Prometric is spread across 135 countries and conducts examinations for several big players in the Computer sector like Microsoft, IBM and also several government organizations.

It's really surprising that a test conducted by the best management academy and the best test administration organization in the world could get into so many controversies.

The CAT exam was conducted in a 10 day window beginning on 28th November 2009 to 7th December 2009 and in addition two more days because of technical glitches - January 30th and 31st 2010. Finally the results were declared yesterday, i.e. 28th February 2010. That's three whole months.

CAT 2009 was a big thing for Prometric. In India, Prometric conducts a lot of exams, but most of them are score-based and a majority of these are qualification exams rather than competitive exams. But CAT was completely different for Prometric India. It was percentile based (rank based) and a national level competitive exam.

A major difference between competitive exams and qualification exams is that in qualification exams performance is absolute and students really don't care about other students. Prometric conducts a lot of exams like this in India, examples include certification exams for organizations like Sun, Oracle, Microsoft, etc. and has been successful in their administration. But, competitive exams are different, the performance of students is relative so every student should be given the same opportunity to show their expertise. The major factors which influence this are -

  • Questions should be never repeated across slots
  • The question paper pattern should be same
  • The difficulty level of the questions should be same

There were a lot of speculations that questions repeated across slots and that questions even came from question papers of previous years.

Though the question paper pattern was the same, it wasn't declared before. However, I don't think Prometric can be blamed for it.

Estimating the difficulty of the question paper is indeed difficult, so methods like Computerized adaptive testing should have been used. I am not sure if Prometric used such techniques in CAT, but if they did, a thumps up to Prometric.

Another major problem faced by the students was that there was a lot of technical problems with the computers. A few technical issues can be tolerated but it was found that 8000 students were allowed to reappear for the exam, which was a huge embarrassment for Prometric. The pathetic part of it was that Prometric attributed this problem to common viruses and what was more surprising was that the test wasn't even internet-based but was LAN-based. Maybe Prometric should have invested on a good Anti-Virus program or at-least installed a free one like Avast on the systems ;)

Personally I faced no problems when I took my test and I believe that despite a few lapses, Prometric did do a reasonably good job.

Now coming to the bigger picture, I didn't understand a lot of decisions that were taking by the administration committee of CAT -

  • Why wasn't the pattern of the paper announced before the exam? This did give an advantage to the students who wrote the exam in the later part of the window as they knew the pattern as opposed to the students who wrote it in the beginning. I guess IIMs were being over-optimistic when they expected that details of the exam won't go out when the students press an "I Agree" button to the terms and conditions.
  • Why were the results declared so late? Initially they said the results would come out in January, then in the third week of February and then finally at the end of February. This did create a lot of frustration in the students.
  • How were the marks allocated? I am sure a lot of students are still wondering how a score of 450 was divided between 60 questions. If this was because of normalization, why wasn't the formula published?

I am sure, the administration committee have their reasons for this.

A Comp. Sci.s view on CAT 2009

Being a Computer Science student, I was very happy when CAT was announced as a computer based test as I assumed it would very efficient and well organized. In fact, I expected the results to be out soon, as once the entire data was available, a formula would have given the results within a day; which of course wasn't the case. During the entire CAT process, I found a lot of features in their software interesting.

During slot reservation, the queue system implemented was very good. It made the process of reserving slots more professional and at the same time eased the load on their server. However the venue details on a few hall tickets were wrong, which created a panic among the students. For example, Andhra Pradesh was misprinted as Arunachal Pradesh in the hall tickets of several students. I was also a victim of this error. Prometric should have done a quality check on the software for such issues as well.

The exam software very good and comfortable for the students. Time and session management were implemented flawlessly. But the students did face some trouble with an "Exit" button, despite the Prometric guys warning everybody about it.

But coming to the results, there were a lot of things which I didn't understand. One big question was - Why didn't they just email the results to the students instead of putting up a server. This would have made the result declaration a lot easy and obviously mail servers of Google and Yahoo wouldn't have crashed on heavy loads. This would have even saved the students from F5 blues.

When they decided to go for a result server, it is surprising why they didn't make sufficient arrangements to accommodate the huge number of requests. In fact, they did implement load balancing and had nearly four servers running, but most of the students didn't know this. However even that wasn't sufficient and within a few hours, the entire system came down crashing.

Another big mistake was that they actually displayed the exception messages outside for the world to see. Here's a screen-shot of one of them -

Does the world really need to know that the IIMs/Prometric servers used a MySQL database? A custom error page would have been a lot better.

Maybe even the best managers in the world need efficient computer engineers ;)

Well, that's the story of CAT 2009. I personally felt the movement towards an online CAT was very good and will be really beneficial in the future.

And for all those who would like to know my percentile in CAT this year - it's 88.47. Not a great percentile, but at the same time not even a bad one.

Before I conclude, I would like to congratulate all the students who are satisfied with their percentile and wish the best of luck to all of them for their interviews at various B-Schools. For the others, I have only statement to make - "Failure is the stepping stone to Success". :)

Sunday, February 28, 2010

Passing Functions To Functions In C++, C# & Java

Before I start the article, I admit I used the word "Function" a little loosely in the title. Functions are available in C++, but in C# and Java it would be more appropriate to call them methods of a class because of the Object Oriented approach followed by these languages.

There are a lot of situations where we write modules such that other developers have the flexibility to fine-tune them to meet their requirements. Assume we are writing a module (function/method) wherein a function/method will be called in the middle of its execution but we don’t know the implementation of this function/method nor its actual name. Wouldn't it nice if we could just leave the implementation of the function/method to the developer who will be using the module?

This is exactly what I target in this blog-post. The article will give a quick overview of how to pass a function (actually a reference to a function) to another function in C++; how to create and use delegates in C#; and finally how to simulate a similar effect in Java which has neither pointers nor delegates.

To help the readers understand the concept better, I will be taking a simple example here. In the example, there is an addition module which takes three arguments - two integers and a function/method which is the display routine. It's not a real-world example as I could have just returned the sum back.

An apt real-world example for this approach would a customized sort routine which takes a function/method which can be used as a comparator for the sort. I will leave it to the users to think of more complex situations where such an approach will be beneficial.

Function Pointers in C++

A Function Pointer is a pointer in C/C++ which points to a function. When dereferenced, a function pointer will result in the execution of the function it points to. A function pointer is defined as -

return_type (*function_name)(argument_list)

An important point that is to be noticed here is that the signature of the function to which the pointer can point to has to be declared in the declaration of the pointer. Once that is done, it can be assigned to any function which follows that signature.

Here is an example C++ program which uses function pointers -

Function pointers play a very important in Callback layered architectures. For example, function pointers can be used to register a function with an event handler.

Delegates in C#

A delegate is a type that references to a method. When a method is assigned to a delegate, the delegate behaves exactly like the method. A delegate in C# is defined as -

access_modfier delegate return_type delegate_name(argument_list)

Similar to Function Pointers in C/C++, the method signature has to be specified in the definition of the delegate. But unlike function pointers, delegates are type safe. This is because since Function Pointers are basically pointers, even an improper assignment will not raise any error until it’s too late. On the other hand delegates are associated with the signature specified and any wrong assignment will lead to a compilation error.

Another important feature of delegates is that delegates can be chained together. That is, multiple functions can be executed when the delegate is called. This is done through + and - operations on delegates. Here is how the syntax looks -

delegate_name reference_name;
reference_name = method1_name;
reference_name += method2_name;

Now when reference_name is called, both method1_name and method2_name are executed one after another.

Delegates also allow methods to be passed to other methods using lambda expressions, which can be written in the method call itself. Go through the following example which shows how to use delegates for method passing and how lambda expressions are useful -

Delegates are very useful in event handling, for defining callback methods like a customized sort, etc.

Simulation Using Interfaces in Java

Ok, now coming to the fun part. How can I get the same effect in Java which has neither Function Pointers nor Delegates?

The approach which have discussed above can be simulated in Java using single method Interfaces. The single method interface can be implemented and the class can become an argument of the method. The concrete class passed to the method is used to call the one and only method of the interface.

However, there are three major drawbacks in this -

  • Every developer using the method is forced to create a class implementing the interface
  • The name of the function is fixed, the implementation will change but not its name
  • We are not passing the method anymore but instead passing an object which has the required method

Similar to C#, the interface implementation can be done in-line to the method call using anonymous classes.

Here is a Java program which achieves the same result as the above two examples -

As we know, C# was heavily influenced by Java. So, almost everything that we can do in Java can be done in C#. The interface technique discussed for Java can also be applied in C#, but I guess it’s more easy to use Delegates for such a requirement than creating Interfaces.