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.

Thursday, February 25, 2010

A Day At Deloitte

Last Saturday, i.e. 20th February 2009, my friends and I visited the Deloitte campus to participate in an event conducted by Junior Achievement India in association with Deloitte. We had a wonderful time there.

Junior Achievement India is a member of JA Worldwide. JA Worldwide is the world’s largest organization dedicated to educating students about business, economics and entrepreneurship through experiential, hands-on programs. JA works along-side business ventures to bring the real world to students and to bridge the gap between education and business.

JA India was established in 2007 and has its mark on several cities in India like Bangalore, Chennai, Hyderabad, Mumbai, etc. Know more about JA India at - http://www.jaindia.org/

Deloitte (also branded as Deloitte Touche Tohmatsu) is one of the largest professional services organizations in the world and one of the Big Four Auditors. Deloitte mainly delivers audit, tax, consulting and financial advisory services through its member firms. Know more about Deloitte at - http://www.deloitte.com/

JA India in association with Deloitte invited our college to a business simulation competition - "JA Titan". There were four teams which represented Osmania University at the event. I was a part of one of these teams. My team members were Roopak, Sunil and Harish.

The competition date was announced as 20th February 2010. We were supposed to have an exam that day and were disappointed that we wouldn’t be able to attend it. But as luck favored us, the exam was postponed due to a bandh and we decided to go to Deloitte.

Deloitte had a huge campus and was really appealing. Initially, all the participants were put through regular security protocols and given identification cards. Then we all were escorted to the cafeteria for a light breakfast. The event started with an introduction to Deloitte, JA and community involvement of Deloitte by the CFO of Deloitte, Hyderabad.

There were basically two things that we did that day - attended a workshop by JA on "Careers with a purpose" and participated in "The JA Titan competition".

The workshop focused on the fact that there are a lot of jobs that are available but the students aren’t equipped with the right tools to be employed for the job. It also emphasized the point that most of the students rarely apply what they study at their colleges and generally tend to work in other domains. A noteworthy point of the presentation was the SEEK principle to estimate if an individual is capable of taking a particular job - Skills, Education, Experience, Knowledge.

Post lunch, the competition began. It was an online simulation competition. The crux of the competition was a sales goal where we were to sell a product in a market for 12 successive quarters with the other teams as business rivals in a virtual market. The consumer base was simulated by the program and the performance of the teams were measured with a performance index generated by the program itself. The game involved various market factors like Publicity, Research and Development, Cost Estimation, Price Decisions and many others. We gave a tough competition to the other teams but narrowly missed out in the end. Well, that’s business - you win some, you lose some. ;)

The competition was very exciting and got our pulse going up every time the quarter closed and results were being declared. Play the game at - http://titan.ja.org/

On a whole, we had a great time and were able to learn a lot about business ventures and their management.

Wednesday, February 24, 2010

The Interview

I am sure a lot of you are curious to know how I got into Capital IQ. Read on.

The placement season at our college was pretty dull in the beginning. The first company which came to us was CommVault Systems, I didn't apply for it. CommVault Systems took two of my friends, Roopak and Ratna Paul.

Soon after CommVault, Capital IQ came to our college. Capital IQ was the second company this placement season and almost everybody in my class who was eligible, applied for it. It was announced that Capital IQ would be coming to our college on 13th of August 2009.

Then began my struggle for the job. I started going through my C, C++, DS, OS and DBMS text-books (actually, had to spend some time searching for them at my house). In the beginning, everything seemed Greek and Latin, but after some time, things started coming back on my mind. Pointers, Inheritance, Trees, Scheduling Algorithms, SQL and what not. Then came the twist, Capital IQ tests the aptitude and verbal ability of students in the exam besides their technical ability. Though I had experience with aptitude before, the pressure of technical questions and aptitude questions was over-whelming. I almost thought of giving up, but later decided that I won't go down without a fight. I studied everything what I could in the short span of time and hoped that it was sufficient.

The D-day finally came. Dressed in formal clothing, wearing polished black formal shoes, my friends and I were ready for the interviews. I couldn’t believe that we were the same students who hang out at our department parking, bunking classes. ;)

The placement process of Capital IQ started with a pre-placement talk about their company. In this presentation they explained us about McGraw Hill companies, about Capital IQ and their work culture. They introduced the various work positions that were available at their company. They gave a clear view of what each job profile does and asked the students to make their choices. I felt that this concept was very good as they allowed the student to decide what he/she wants to be - Developer (Software Engineer), Database Administrator, Business Analyst, Quality Analyst and System Administrator. I was certain that I wanted to be a Developer, but as I had some amount of exposure to Databases, I thought I might be able to do justice to the role of a DBA too. They also mentioned that they primarily work with .NET and SQL Server.

The selection process started off with a written test which consisted of a lot of technical and aptitude questions. One boon was that there wasn't a verbal section. The paper was segregated into five sections - the first one was completely to test the quantitative ability of the student. It was reasonable and for students preparing for management exams, it was a cake-walk. Then there four other sections which tested programming capability; SQL and database concepts; the ability to comprehend and explain business requirements; and the ability to generate test use-cases. That’s one section for every job profile. This was a great approach as it would indicate the strengths of a student.

They eliminated a few students in the written round and proceeded to the next round – Group Discussions. This was where most of the screening was done. They divided all the shortlisted students into 3-4 groups and gave each group a topic to discuss on. The topic which I got was - "Has the Satyam scandal tarnished the image of India". I always believed that it hasn’t and supported my viewpoint.

After the group discussions, the technical rounds began. I went through two technical rounds at my campus.

In the first round, I was asked mostly about Data Structures, SQL and OO Concepts. They also asked me a few basic questions about AJAX and ASP.NET as I put them in my resume. There was also an analysis on a few questions from the written test.

The second technical round was with Mrs. Nalini, a senior architect at Capital IQ. I concentrated mainly on my 3-2 project - "Synchronous and Asynchronous Database Replication" in this round, emphasizing on why it was done and its modular approach.

That was the end of Day 1. They didn’t announce the results that day. 4 days later, i.e. 17th August 2009, they informed the placement office that around 7 of us were shortlisted for the next rounds which were to be held at their campus on 19th.

19th was a big day for all of us. Initially there was a technical interview with Mr. Krishna Kant, the director of Capital IQ, Hyderabad. This time I started off with my projects and gave a brief overview on my 3-2 project and my 4-2 project - "Cloud Computing Portal for SMEs". The interview also stressed on why I wanted to be a developer and the various small tools I built before.

Finally, there was a video conference with Mr. Jeff, a senior employee at Capital IQ, New York. This was a new experience as I was never a part of a video conference before. However I quickly got tuned to it as it was pretty similar to a telephonic conference. Here, I was asked about "Service Oriented Architecture" and my presentation at Transition '09, the technical event of CTS and my experiences as a Sun CA.

So finally, after a written test, a group discussion, three technical interviews and a video conference, the good news rolled in on 9th September.

I was delighted to hear that I got into Capital IQ as a Software Engineer, but at the same time was sad that only two students from my college were placed into Capital IQ. However I am glad that as of today, the placement season is on a full swing and almost all my friends have been placed.

Along with me, V.V. Aishwarya, a classmate of mine was also selected as a Software Engineer.

Honestly speaking, I never expected that I would get into Capital IQ in the beginning of this process. But at the end, it was a pleasant surprise. :)

Friday, February 19, 2010

Capital IQ - A New Chapter In My Life

I recently joined Capital IQ as an intern. This blog-post gives a brief overview of Capital IQ. In my subsequent posts, I will be explaining how I got into CIQ and my experiences there.

Before I tell my story, I should introduce Capital IQ to all my readers who don’t know it yet. To know about Capital IQ, you should know "The McGraw Hill Companies Inc."

The McGraw Hill Companies Inc. traces back to 1888. Its primary areas of business are education, publishing, broadcasting and financial and business services. In India it is popular in the educational sector as Tata McGraw Hill. I am sure most of us have grown up studying the text-books published by TMH. Know more about the McGraw Hill companies at http://www.mcgraw-hill.com/

In the financial sector, McGraw Hill shines as Standard & Poor's (S&P). S&P is the division that publishes financial results and analysis on stocks and bonds. S&P traces its history back to 1860 and was acquired by The McGraw Hill companies in 1966. Know more about Standard & Poor’s at http://www.standardandpoors.com/

Capital IQ is a provider of information and analytical tools for investment bankers, money managers and other financial professionals. Capital IQ was founded in 1999 and currently operates as a division of Standard & Poor's after its acquisition in 2004. The company's headquarters is located at New York City and has several regional offices in various places in the world like Boston, San Francisco, Canada, London, Argentina, Hyderabad, Gurgaon, etc. Know more about Capital IQ at https://www.capitaliq.com/

If you want to know how I got into Capital IQ, please read my subsequent posts.

Thursday, February 18, 2010

The Shining Sun

Well, I am sure by this time you would have come to know that I was working at Sun Microsystems Inc. as a Campus Ambassador. This blog-post gives a brief overview of my experiences as a Sun CA.

If you have already gone through my Sun Blog, this post may seem redundant.

I joined Sun Microsystems Inc. in September 2006 as a Campus Ambassador for my college, Osmania University. The job profile was primarily of a technical evangelist at my college. I loved the job as it would give me an opportunity to learn new technologies and at the same time give me experience in event co-ordination and crowd management. So, I applied for the position and after a telephonic interview, I got into Sun.

January 18th was my last day at Sun. The entire Campus Ambassador had been closed that day and I out of Sun now. It was a wonderful and memorable journey. While working as a CA, I got a chance to meet a lot of like-minded people from various parts of the world and had a wonderful time working with them. At the same time, I could learn a lot about the technical products of Sun Microsystems Inc.

During these 17 months, our college reached new heights in the open source world. Here are a few of the major mile-stones reached by my college -

  • Inauguration of S.O.U.R.C.E
  • Software Freedom Day 2008
  • The Ref Contest (Received accolades from several people and the idea was replicated in many countries)
  • Establishment of Sun FTP Server at Osmania University
  • Sun Tech Days 2009
  • Sun support in Infinity 2009
  • 18 internships from Sun Microsystems Inc. as a part of Industry Association Program
  • Software Freedom Day 2009

Besides these major mile-stones, Osmania University was a part of several competitions and technical sessions in this period.

My recognitions as "Sun CA of the month" and "Sun CA of the quarter" were the biggest honors for me at Sun. I also got myself certified as a SCJP and as a SCWCD during this period.

Before I conclude, I would like to thank Sun Microsystems Inc. on behalf of Osmania University for giving us this opportunity and at the same time thank Osmania University on behalf of Sun Microsystems Inc. for their unvarying support and cooperation to the open source community.

If you would like to know more about my experiences with Sun, visit http://blogs.sun.com/gautam and in case Oracle pulls it out, I will replicate it elsewhere and provide the link here. Here is a beautiful picture from James Goslings blog showing the emotion of every Sun employee after the acquisition.

Thursday, January 21, 2010

A Journey Ends

Hello Everyone!

With a heavy heart, I have to state that this will be my last blog-post as a Sun Campus Ambassador. January 18th 2010 was a sad day here, at Sun Microsystems Inc. The Sun Campus Ambassador program has been closed all over the world as of Monday.

This announcement ended my wonderful 17 month journey in Sun as a CA. I joined in September 2008 and was a part of Sun till January 2010. The experience is unforgettable and is one of the best parts of my college life.

It would be very ungrateful on my part if I don’t express my gratitude to all the people who have helped me in this journey. I would like to thank everybody who has supported me throughout this program directly or indirectly.

Here is a brief review of my journey of 17 months in Sun.

All this started a year and half ago when my senior and the previous Sun CA of my college, Anil Kuppa graduated and inspired all of us to continue the legacy of the Sun Campus Ambassador program at our campus. He helped us to get in touch with Sun personnel and got interviews fixed for the interested students of my class. I would like to thank him for his guidance and his inspiring aura.

Initially I was guided by Ankit Srivastava and after he left, I came under Rajesh Uma Shankar. Rajesh was a big support in Sun Microsystems for me. Any problem, issue or question, a mail to him was enough. Rajesh has always been there for us and supported us at every moment. In this period I got an opportunity to meet other coordinators like Abhishek Kumar, Anuradha ma’am, etc. who have always led us in the right direction and have taken the Sun CA to a completely new level. Thank you everybody for your constant support and guidance. And a special thanks to Rajesh for everything he did for my college during IAP.

It would be incomplete to talk about the Sun CA program without mentioning Mr. Ganesh Hiregoudar, the program manager for the academic programs (APAC). Ganesh sir was a wonderful mentor and was very understanding. He always motivated us to reach new heights and taught us how to think out of the box. Thank you for everything, sir.

The best part of the Sun CA program was that we could meet a lot of like-minded people. We had an opportunity to collaborate with students from all parts of the country. We all were a team and took the CA program and OSUM forward at our colleges. I made a lot of friends and got to know a lot of people. On this parting day, I wish everybody the best of luck in their future endeavors and hope that someday our paths will cross and we will work together. I will miss you all. :(

One of the biggest element of my term as a Sun CA was OSUM. Big thanks to Gary, Tzel, Cecilia and Eze who have always supported us through OSUM and helped me complete my SCJP and SCWCD through the vouchers.

Throughout my phase as a Sun CA, my biggest support and the back-bone of my tenure as a CA was my college. During my first month, a new open source group, S.O.U.R.C.E, was started at my college with the support of Sun Microsystems Inc. We are greatly indebted to Prof. Venu Gopal Reddy, the principal of my college; Prof. S. Ramachandram, the head of my department when I started my tenure and Prof. Lakshmi Rajamani, the current head of the department for their cooperation in building up a vibrant open source community at my college.

My classmates are a few of the best people I have ever seen. I am extremely grateful to them for extending their helping hand in every event/competition at my college and standing by me at every moment in the past 17 months. I am also thankful to my seniors for their timely advices and great suggestions. My juniors have always been a great support and gave me the courage to do things as a Sun CA and I appreciate their help a lot. Thank you all for your incredible support and cooperation in helping me sustain Osmania University’s reputation at Sun Microsystems Inc. and bringing me to this position. If you go through my blog-posts here, you will realize how much Osmania University has done for me and the open source community.

Before I conclude, I would like to thank my parents from the bottom of my heart for their inspiration and unbeatable guidance and support throughout this period. I am grateful to God for giving me this opportunity and hope I have done justice to my role.

Finally, I will quickly list out the important mile-stones reached in the last 17 months -

  • Inauguration of S.O.U.R.C.E
  • Software Freedom Day 2008
  • The Ref Contest (Received accolades from several people and the idea was replicated in many countries)
  • Establishment of Sun FTP Server at Osmania University
  • Sun Tech Days 2009
  • Sun support in Infinity 2009
  • 18 internships from Sun Microsystems Inc. as a part of Industry Association Program
  • Software Freedom Day 2009

Besides these major mile-stones, Osmania University was a part of several competitions and technical sessions in this period.

My recognitions as "Sun CA of the month" and "Sun CA of the quarter" were the biggest honors for me at Sun.

Well, before I say goodbye, I would like to thank Sun Microsystems Inc. on behalf of Osmania University for giving us this opportunity and at the same time thank Osmania University on behalf of Sun Microsystems Inc. for their unvarying support and cooperation to the open source community.

You can reach me at 14gautam@gmail.com and read my technical articles at http://gautam-m.blogspot.com/. And in case Sun pulls out this blog, I will replicate it elsewhere and provide the link at my tech blog.

Good bye.

Monday, January 11, 2010

Deploying Servlets & JSPs

Java Servlets & JavaServer Pages (JSPs) form the backbone of Web Application Development in Java. Java Servlet Technology and JSP are a part of the Java Platform, Enterprise Edition (JEE). The latest release of JEE (version 6), which was released a few days ago supports Servlets 3.0 and JSP 2.2. I am not going to emphasize the changes made in these versions here, but a quick Google search should give you an idea on the enhancements made.

A Java Servlet is primarily a class which conforms to the Java Servlet API, a protocol by which a Java class may respond to HTTP requests. A servlet may be used to add dynamic content to a Web Server using the Java platform. The generated content is commonly HTML, but may also be other data such as XML, etc. Similar non-Java technologies are CGI and ASP.NET.

JSP is a server side technology similar to that of Servlets. Like Servlets, it is also used to create dynamically generated web pages with HTML, XML, etc. in response to Web client requests. Architecturally, JSP may be viewed as a high-level abstraction of Java Servlets.

Though Servlets and JSPs are used to achieve the same goal, they were designed for two different profiles - developers and designers respectively. A well designed JSP may serve dynamic content using Java without any actual Java code in the JSP; this is achieved using other technologies of Java EE like Expression Language, Custom Tags, etc. Such a model was built to help Web page designers, who are good at HTML, build JSP pages without any need to understand the Java code involved. The developers can support these designers by building custom tags, developing the servlets in patterns like MVC, etc. If you are new to the world of Web Application Development in Java, this concept may seem a little overwhelming in the beginning, but as time progress you will understand this approach better.

To accept HTTP request and to give the users the required responses, a web/app server is used. A web server primarily accepts request and gives responses along with optional data content like images, etc. An extension to the web server is the app server. An app server can also expose business logic and business processes for third-party applications. Further, app servers have features like transaction management, security, etc. Apache Tomcat is a popular web server with Tomcat as the servlet container and GlassFish is a popular app server. Servlets and JSPs have to be deployed on these servers for the outside world to communicate with them. This post will be covering both these servers.

In this blog-post, I will be covering only the deployment phase of Servlets and JSPs. It is assumed that the reader is comfortable with Java and is well acquitted with the basics of JSPs and Servlets. I won’t be explaining any code in this post as most of it is self-explanatory.

Software needed

Note - Installing Java EE 6 will also install GlassFish v3.

To help the readers get a better understanding of the entire process, I will be developing a simple Hello World Application with a Hello World JSP and a Hello World Servlet here.

Here are the source codes of the JSP and the Servlet -

Compile the servlet using the javax.servlet.jar available in glassfishV3\glassfish\modules directory, which is obtained after installing JEE 6 with the following command -

javac HelloWorld.java -classpath install_path\ glassfishV3\glassfish\modules\javax.servlet.jar

Understanding the directory structure

Every web application has a typical directory structure. The JSPs and Servlets along with the required descriptors have to be placed in this directory structure. I will emphasize this structure using the Hello World example. The structure is as follows -

Any file/folder present in the root of the Web Application (like helloWorld.jsp) here is directly available to the client. Even folders present here (except WEB-INF and META-INF) are available directly to the users.

The root also contains a directory called the WEB-INF. This is a required directory and contains three important sub-folders - classes, lib and tags. Every web application also has a deployment descriptor (web.xml). This is also placed here.

The classes directory contains the .class files. The servlet class files are also placed here (like HelloWorld.class).

The lib directory contains any external JAR files that are used in the web application. In this example we have no files in this directory.

The tags directory contains the TLD along the .tag files. As this is an introductory example, we will keep this directory empty. If there are any custom tags being developed in the web application, they should be placed here.

The deployment descriptor defines the mapping between the servlet name and the servlet class.

Download the entire application here.

Deploying the application in Apache Tomcat

Copy the directory HelloWorldApplication built in the above step to the webapps directory of Tomcat i.e. install_path\Apache Software Foundation\Tomcat 6.0\webapps.

Start Tomcat from install_path\Apache Software Foundation\Tomcat 6.0\bin\tomcat6.exe.

To view the JSP page, type http://localhost:8080/HelloWorldApplication/HelloWorld.jsp in the browser and to view the servlet page type http://localhost:8080/HelloWorldApplication/HelloWorld in the browser.

Shut down tomcat6.exe to stop the server.

Deploying the application in GlassFish V3

Start GlassFish using install_path\glassfishV3\glassfish\bin\startserv.bat.

Open http://localhost:4848/ in the browser.

Login with the admin password and navigate to Applications Task in the left-side panel. Click on deploy and select "Local Packaged Directory" and specify the directory built above.

Select the type as "Web Application" and click on "Deploy".

To view the JSP page, type http://localhost:8080/HelloWorldApplication/HelloWorld.jsp in the browser and to view the servlet page type http://localhost:8080/HelloWorldApplication/HelloWorld in the browser.

Stop GlassFish using install_path\glassfishV3\glassfish\bin\stopserv.bat.

That’s it. We have written a web application and deployed it on Apache Tomcat and GlassFish. Still there is one more catch - what if I have to move the web application from one physical server to another physical server? Do I have to build the directory structure again? Well look for the solution in my next blog-post - Building Java Web Archives (WARs).

Monday, January 04, 2010

Sun Certified Web Component Developer

I recently attempted the "Sun Certified Web Component Developer for the Java Platform, Enterprise Edition 5" exam and passed it flawlessly.

The SCWCD exam is primarily for developers specializing in the application of JavaServer Pages and Servlet technologies used to present Web Services and Dynamic Web Content.

The certification tests the developer if he/she understands the basics of JavaServer Pages and Servlet technologies along with the best practices of the Web Application development. The exam also covers a few extreme features like JSTL, EL, design patterns, etc.

The certification, as of today is available in only one flavor - 5 (also known as 1.5). However to attempt the SCWCD exam, one must be a SCJP. Know more about SCWCD at http://www.sun.com/training/certification/java/scwcd.xml

The "Sun Certified Web Component Developer for the Java Platform, Enterprise Edition 5" exam covers objectives like -

  • The Servlet Technology Model
  • The Structure and Deployment of Web Applications
  • The Web Container Model
  • Session Management
  • Web Application Security
  • The JavaServer Pages (JSP) Technology Model
  • Building JSP Pages Using the Expression Language (EL)
  • Building JSP Pages Using Standard Actions
  • Building JSP Pages Using Tag Libraries
  • Building a Custom Tag Library
  • Java EE Patterns

The exam actually costs Rs.7200, but being a Sun employee I got it for free under SAI. :)

A minimum of 70% (49 questions out of 69) is required to clear the exam. And the time duration for the exam is 3 hours.

For preparation of the exam, here is the material that I followed; I think this should be enough to get a respectable score -

Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam - Kathy Sierra & Bert Bates

This is a comprehensive book for the SCWCD 5 exam, it covers all the objectives of the exam in a structured approach. Anybody attempting the exam should go through this book at least once.

Buy the book from Amazon.com at http://www.amazon.com/Head-First-Servlets-JSP-Certified/dp/0596005407

Wednesday, December 16, 2009

Remote Desktop Services Using RDP

If you love the data on your desktop, and want it on the move, then this blog-post is for you. In this post, I will emphasize the Remote Desktop Protocol (RDP) of Microsoft using the Remote Desktop Services/Terminal Services.

Remote Desktop Protocol (RDP) is primarily a proprietary protocol developed by Microsoft, which focuses on providing user with a graphical interface to another computer.

Notable features of RDP include -

  • 32-bit color support
  • A 128-bit encryption algorithm and protection from vulnerabilities like the man-in-the-middle
  • Audio redirection
  • File System Redirection
  • Port Redirection
  • Support for Aero Glass Theme and ClearType font smoothing technology
  • Support for Transport Layer Security
  • Multiple monitor support

Remote Desktop Services, formerly known as Terminal Services, is one of the components of Microsoft Windows that allow a user to access applications and data on a remote computer over the network. It is built on the RDP protocol.

The RDP Desktop Services segregates the systems into two groups - the servers and the clients. RDP Servers and Clients exist for several versions of Microsoft Windows, Linux, UNIX, Mac OS X, etc.

This article will focus on configuring both, the RDP Servers and RDP Clients. The configuration steps mentioned here are restricted to the Windows line of Operating Systems - XP, Vista, etc; and for illustration purposes, I will be using Windows 7 as my server and Windows XP running on VirtualBox as my client.

Besides Windows, RDP servers are available for the UNIX Operating System in the form of several open-source projects. UNIX based RDP clients also exist, like the rdesktop.

Configuring RDP Servers

A RDP server is the heart of the RDP protocol. Once a system has been configured as a RDP server, any user with sufficient privileges can log into the system from any terminal and perform their tasks.

Configuring the RDP Server on Windows 7 involves the following steps -

  1. Right-click Computer and select Properties
  2. Click on Remote Settings link present in the left panel
  3. If you want to allow connections from any version of Remote Desktop, select the second option. This is a less secure configuration. However this will allow users from other versions of Windows and UNIX to connect to the system. For e.g. if a system with Windows 7 has been setup as a server, this option will allow older versions of Windows like XP and 2K to access it
  4. On the other hand if you are sure that you want users to connect from the same version of Remote Desktop, select the third option. This is a more secure configuration

Configuring RDP Clients

Once the server has been setup, any RDP Client can hook up to it from any system connected to it in the network.

Establishing a connection to a RDP Server from a system running Windows XP involves the following steps -

  1. Go to All Programs -> Accessories -> Remote Desktop Connection
  2. If the RDP Server has a computer name, enter the name. Else enter the IP address of the RDP Server
  3. Login with the proper username and password; and you are ready to work
  4. At the end, remember to log off and not shut down, because shutting the system down would require a physical startup the next time whereas logging in again can be done remotely

Remember - According the EULA of Microsoft Windows, only a single user can use the copy of Windows at a time. So there can be only one RDP Client active for a particular RDP Server. If another RDP Client logs in, the existing user will prompted to log off.

Facts and Features of RDP

  • RDP uses presentation virtualization to enable a much better end-user experience, scalability and bandwidth experience. RDP plugs into the Windows graphics system the same way a real display driver does, expect that, instead of being a driver for a physical video card, RDP is a virtual display driver
  • RDP usage of bandwidth is far less than expected. This is important as bandwidth is a very big constraint in networking. However, the bandwidth usage varies from the application to application being used. E.g. A slideshow in PowerPoint will drive more bandwidth than a simple movement of the mouse
  • RDP can be tuned as per the requirements of the user. Factors like user-experience can be compromised to reduce the usage of bandwidth. RDP can be configured to give better performance too
  • Color depths have no effect on the user-experience of RDP. Though the initial versions only supported 8bpp (bits per pixel), the newer versions support 32bpp, and in fact Aero needs 32bpp to function properly
  • RDP is highly secure as it supports strong encryption and uses Keberos or TLS/SSL for authentication
  • RDP is not only used in Remote Desktop Services, it is used in several applications like Windows Media Center Extenders (including Xbox 360), Windows Live Mesh, etc.
  • The RDP protocol is completely publicly documented. To understand the internal working of RDP, you can visit - http://msdn.microsoft.com/en-us/library/cc240445(PROT.10).aspx

Well that’s it for a simple RDP Server-Client setup. Do check back soon for my next article on Windows Meeting Space, which is another part of the Remote Desktop Services using the RDP.

Thursday, December 03, 2009

Reset Linux Root Password Using The GRUB

Before I start the central aspect of this article - resetting the Linux root password, let me quickly introduce you to boot loaders and the GRUB.

A boot sequence is the initial set of operations that the computer performs when the power of a computer is switched on. A boot loader typically loads the main Operating System for the computer.

A computer's central processor can only execute program code found in the Read-Only-Memory (ROM) and Random-Access-Memory (RAM). However, when the computer is switched on, it does not have an Operating System in its ROM or RAM. So a computer initially executes a small program stored in a ROM, which in-turn loads the required code and data into the RAM for execution.

This small program which performs this process is known as a bootstrap loader, bootstrap or a boot loader. This program is generally not the Operating System, but a miniature program which will load the required Operating System into the RAM from the non-volatile storage.

There are several popular boot loaders used today - GRUB, BOOTMGR, LILO and NTLDR. The GNU GRUB (GNU GRand Unified Bootloader) is a boot loader package from the GNU Project and is one of the most popular boot loaders available today. LILO (LInux LOader) is a generic boot loader for Linux. NTLDR (NT Loader) is the boot loader for all releases of Microsoft’s Windows NT Operating System. In later versions of Windows like Vista and Windows 7, NTLDR was replaced by the Windows Boot Manager (BOOTMGR).

In this article, we restrict ourselves to the GRUB loader. Typically, a few dual-boot environments and a few Linux based Operating Systems use the GRUB as their boot loader. Here is a screen-shot of the GRUB loader of Red Hat Enterprise Linux 5 -

There are many scenarios where we might need to reset the root password of our Linux system. Consider you have been assigned to a Linux system to work with and the previous owner forgot to give you the root password; maybe you are in the middle of an important project and you don’t have the root password of the system when you need it urgently and the worst part - the system administrator is not in sight; or maybe you just forgot it. The possibilities are limitless.

But remember, before you attempt to change or replace the password of any machine, make sure you have the necessary permissions from the management authorizing it. If not, it can be mistaken as an attempt to hack into the machine, which is not ethical.

  • Start the system, when the selection screen comes up, navigate to the line for Linux and press 'e'
  • Now, select the entry that begins with the word - 'kernel' and again press 'e'
  • Append 'single' to the end of the existing line. Make sure there is a space between the existing content and 'single'
  • Press 'b' to boot into Linux as the root

You are now in the special mode called the "Single-User Mode".

If prompted for the root password here, restart the system and in the previous step, append 'init=/bin/bash' after 'single'

  • Use 'passwd' to specify the new root password

I am sure that reading this procedure would have caused apprehensions in the minds of several readers about the security of their systems. Using this method, anybody can hack your system. So if you want to be careful and avoid such situations, you will need to restrict any modifications to the GRUB. This can be done by protecting the GRUB by using a password.

  • Open the shell prompt and login as the root
  • Use the 'grub-md5-crypt' command to get the MD5 hash of your GRUB password
  • Open '/boot/grub/grub.conf' and add 'password -md5 ' below the timeout field
  • Save and exit

From next time, if you want to edit the GRUB, you will have to press 'p' followed by the GRUB password. The downside of this is that there is an extra password for you to remember. Well, accessibility has always been a trade-off in security.

Note - Changing passwords of a system without proper permissions is unethical and illegal, which may lead to legal complications. So always follow a proper authorization channel before changing the passwords.