Wednesday, August 27, 2014

Web Applications, Java Servlets: A Conceptual Introduction

I am happy to launch a unique kind of conceptual video course on web applications: “Web Applications, Java Servlets: A Conceptual Introduction.” Check it out -- whether you are new to web development or not, and whether you are a hardcore programmer or not, you will love it!

For limited time, I am now offering free lifetime access to it! Follow this link to grab it: https://www.udemy.com/web-application-and-java-servlet-concepts/?couponCode=ALVAX

Feel free to share it with your friends and colleagues, it might be helpful to them!

Tuesday, August 12, 2014

Up And Running With Spring Framework 4 In Five Hours

Independence day offer valid till August 15 only: Get 80% off ($19 only!) on my "Up And Running With Spring Framework 4 In Five Hours" video tutorial.

Your friends might appreciate you sharing this post with them!

Sunday, July 27, 2014

Video on basic concepts of web applications, how they work and the HTTP protocol

Here is the first of a series of conceptual videos I have planned to make on web application development using Java Servlets. When the course gets ready, I shall be announcing it here at my blog with some free and heavily discounted coupons. So, if you like this video, please subscribe to my blog to see more free videos by me and know when the course comes out.

Would be glad to hear any feedback. And, if you liked the video, your friends might appreciate you sharing it with them!

Sunday, July 06, 2014

Up And Running With Spring Framework 4 In Five Hours

[Moved from my previous blog]
I recently released a video tutorial on the awesome Spring Framework 4 and its new projects like Spring Boot. Whether you are new to Spring or are already a spring 3 developer, you would like it if you intend to learn Spring 4.
It is priced at $98, but you can get it now at $29 by clicking here. Check it out!

Saturday, July 05, 2014

Spring Controllers as JSON API

[This is a post dated June 9, 2013 from my old wordpress blog]

I am currently working on a couple of projects which are single page web applications, where the clients interacts with spring controllers using JSON. Also, in one project we have a wordpress plugin which interacts with our controllers from wordpress sites.

Thought to summarize what all I needed to get this working.

First, let’s look at an example controller method:

The object returned by the method is converted to JSON by Jackson object mapper. For this to work, you have to have an ObjectMapper in your application context. To have it, first include it in your project. That means having this in your pom file, assuming you are using maven:

Then, create an object in your application context. If you are using Java configuration, this should do:

Instead of simlple form fields, request-params or path-variables, sometimes you might need to receive complex JSON data from the client. For that, the client code would look like:

and the controller code like this:


You have to define a SomeClass with fields corresponding to the structure of the data being received.

Finally, if you are switching between http and https protocols, or using your JSON API from a different place, as we do from our wordpress plugin, you will have to circumvent the Javascript Same Origin Policy. For that, I use CORS, or the cors-filter to be specific. To use that, include the following in your pom:


And, have this in your web.xml:


At the client side, my ajax setup, called before any ajax call is made, looks like this:


Please let me know your comments! Hope this would be useful as a quick reference to some (including me) in future.

Monday, June 18, 2012

Agile Rapid Application Development


I have been developing software since long. Most of the projects I have worked on relied heavily on agile development processes. Over these years, I have always tried to learn refining agile methodologies to achieve more and more smooth and rapid development experience.
Let me take a moment to record my generic experiences here, at least for my reference.

Key guiding factors

There are some well known influencing factors, e. g. “requirements evolve over time” and we should respects them. However, some of those factors I have learned to respect a lot - to achieve more RAD, are
  • Trying to do thing right at one or two shots is much more painful than evolving with multiple iterations.
  • People give most output when they are given the work they like most. At early stages, people don’t like writing documentation and test cases
  • You may not be able to hire all genius developers. Project should succeed with people of mixed talent.
  • An average developer gives most output when the plumbing code and develompent patterns are already well set.
Keeping all these factors in mind, I see a normal project having these phases:

The Inception Phase

The objective of the inception phase is to arrive at an estimate and go/no-go decision with minimal effort. Inception phase aims to deliver the following.
  1. One para summary about the product, its objective and the scope of the project
  2. One or two page elaboration on the domain and project scope in plain English
  3. System overview or broad architecture and deployment scenario. Should indicate volume and load.
  4. Summary of user stories as themes. No need to elaborate.
  5. Broad domain entity model (without attributes and complex associations)
  6. List of non functional requirements like response time.
  7. List of technology / legal risks, proof-of-concept tasks and mitigation plans. No need to mention common risks such as attrition.
  8. List of cross cutting / non functional tasks.
  9. List of third party tools and libraries needed.
  10. Effort / Time / Cost estimation based on story points method.
For a medimu-sized project, these things are typically jotted following a one or two hour discussion among the customer, a functional analyst and a software architect. Many times, only either the functional analyst or the software architect takes the call and then explains the other one.
Note that all these happen before the project is signed off, and hence, no need to devote considerable effort into this. For a medium-sized project, typically, half-a-day to two days should be sufficient.
Agile methodologies suggest to add about 40%-50% contingency to the estimates, and RADLite respects that. However, many of the times the estimate is driven by budget constraint or competition. In that case, limiting the estimates to some feasible figure, keeping in mind feature trade-off is the only way. By the way, feature trade off is not a bad idea at all. Standish Group [2001] research shows that on average only 20 percent of software features in existing applications are “always or “often” used, 16 percent are “sometimes” used, 19 percent are “rarely” used and 45 percent are never used. Great relieving information for we software estimators!
Note that in some projects there might be some uncertainities which may need investment in a feasibility study before the sign-off.

The Preparation Phase

Once the project is signed off, it enters the preparation phase. The preparation phase sets up the platform for the developers, arming them for action - i.e. to gobble up the user stories.
The following jobs are addressed in the preparation phase:
  1. Resource arrangement
  2. Development environment setup
  3. Ensuring that there are no show stopper risks. Doing proof-of-concept of risky techincal features
  4. Development framework and patterns setup. Includes designing UI Templates and patterns, establishing coding patterns, coding base classes for entity and service classes, coding utility classes, coding cross cutting concerns etc.
  5. Skeleton entity model setup
  6. Place holder classes which would be expanded later
  7. User story expansion and elaboration. Division into must-have, should-have, could-have categories. No need to go into depth - agile methodologies defer going to the depth until development phase.
  8. Coding convention establishment
  9. Developers’ training

The development phase

The development phase is sub-divided into three phases, namely must-have, should-have and could-have phase. Each of these phases address their own set of user stories.
Each of these is again sub-divided into these phases:
  1. Development of working prototype, side-by-side elaboration of user stories (could be high level pseudo-code) and business rules: This phase is important whenever the requirements are not clear. It gives the customer a full cycle to revisit his requirements, business rules and stories. This is done in multiple iterations of fixed length, typically two weeks, prioritizing key and uncertain requirements. Development of working prototype aims to develop all the UI and flow, but can skip time taking, changeable business rules, security constraints etc. The objective of this phase is to demonstrate the customer the full functionality, so that he can re-visit the requirements, if any. For my Java projects, I find the best place for documenting the elaborated user stories to be the JavaDoc, with a custom CSS for generating the docs for non-coders. For traceability, you can maintain sequence numbers in a Google spreadsheet, and use those numbers in the JavaDoc business rules. Those numbers could be then used in test cases. In summary, I like to depend on the JavaDoc and in line documentation for maintaining much of the documentation at a single place. So, going by this, modular coding and strong in-line documentation should be done while designing/coding. Don't consider coding of a ticket complete unless you have finished doing enough in-line documentation - note that in RADLite this is the only place where requirements, HLD and LLD are being documented. Document in a way which can be processed using a document generator tool, like JavaDoc, as much as possible.
  2. Development in multiple iterations of fixed length, typically two weeks.
    1. Base test data and acceptance test case preparation: This is done by the onsite customer or functional analyst on spreadsheet format.
    2. Code Refractoring.
    3. Development: Developers prepare detailed design (e.g.) refer the base test data and acceptance test cases while coding.
    4. Acceptance test automation: By looking at the base test data and the acceptance test case prepared by the onsite customer, developers record the test cases just after developing an user story. The recorded cases are coded in proper format and put into the automated test case repository.
Development of working prototype is more important in the must-have phase than the should-have and could-have phases. The rule of thumb is that, if the requirements are not clear to such an extent that it may need one of more cycles of revisit, we should have development of working prototype.

The transition phase

RADLite does not deviate here from well established standard methodologies.

Summary

RADLite is a methodology successfully followed by me in multiple projects. It’s uniqueness are:
  1. More specific about estimation strategy on inception phase
  2. A preparation phase to give the developers a solid platform before attacking user stories
  3. A specific testing strategy different from TDD
Let me know your views!

Thursday, October 30, 2008

Learning Computer Programming - Page 6

We are now getting a feel of how to tame the computer. Some important notes:
  • The computer is very foolish. It does not understand any other thing except a few words and symbols. Hence, while reading a programming book, use only the words and symbols taught, and do not assume any thing more.
  • The computer does not know what it is doing. It is entirely up to you to write whatever statements you need and get the work done by the computer.
  • We have chosen the names of variables as sum_till_now and next_number, but these could be anything of your choice.
  • Empty lines or spaces in the program is just for the nice look and feel. It does not mean anything to the computer.
Okay. Now, if the problem would have been to add from ¨1 to n, n to be available at the time of execution,¨ the program would be something like:

1. #include <stdio.h>
2. int main()
3. {
4. int sum_till_now = 0;
5. int next_number = 0;
6. int last_number;
7.
8. printf(¨What is the last number?¨);
9. scanf(¨%d¨, &last_number);
10.
11. while (next_number < last_number)
12. {
13. next_number = next_number + 1;
14. sum_till_now = sum_till_now + next_number;
15. }
16.
17. printf(¨The result is %d\n¨, sum_till_now);
18. }

Statement 9 reads a number from input and puts it in the variable last_number. If you execute the program, it will ask for the last_number, which you have to normally type from the key board.

Now that the scanf statement is in your bag, let's attempt a program for adding a few numbers to be input at the time of execution. Program should stop adding and display the result when 0 is input. The program is given below.

1. #include <stdio.h>
2. int main()
3. {
4. int next_number = 1;
5. int sum = -1;
6.
7. while (next_number != 0)
8. {
9. sum = sum + next_number;
10. printf(¨Enter the next number?¨);
11. scanf(¨%d¨, &next_number);
12. }
13.
14. printf(¨The result is %d\n¨, sum);
15. }

Conclusion

You now have got a feel of what programming is and how to tame it. Remember that this was just to show you the approach. You have a long and fascinating way to go. While studying programming, give enough time to understand all the constructs you come across, and never skip a single word from your programming book.

Happy programming! Please post all your queries and feedbacks at http://groups.google.co.in/group/sanjaypatel?hl=en

Please give a little effort to recommend this article to all who need this.

Previous

Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6

Learning Computer Programming - Page 5

Coming back to our program. Let's try to execute it manually, using our old rough pad. After statement 4, our rough pad looks like this:


After statement 5, our rough pad becomes:


Now to statement 7. It is a while statement. The condition is next_number < 10, which is true because next_number is now 0 (see our rough pad). Because the condition evaluates to true, execution enters the next code block, i. e. to statement 9. After statement 9 is executed, our rough pad looks like:


Then comes statement 10. After statement 10 is executed. The rough pad looks like:


Now, after statement 10 is executed, execution again continues from the while statement, i. e. statement 7.

In statement 7, the condition evaluates to true, because next_number is now 1, which is less than 10. So, execution enters into the next block, i. e., statement 9 is executed. After execution of statement 9, the rough pad looks like this:


Then, statement 10 is executed. Then execution goes to the while statement, i. e. statement 7.

If you carry on this process, after sometime, you will find that the condition will become false. The rough pad would be looking like this then:


At this point, the next code block, i. e. statements 8 through 11 will be skipped and execution will continue from statement 12. Statement 12, being blank, statement 13 will be executed, which will display sum_till_now, which contains the desired result.

Done! This explains the use of loop. If now you are asked to write a program to add up to 10000, or 1000000, you need only to change at one place, i. e. in the condition in the while statement.

Previous | Next

Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6

Monday, October 27, 2008

Learning Computer Programming - Page 4

You must have observed that many steps in this program are similar and repetitive. Particularly, statements 7 to 14 are quite similar. It would be great if we could express it in some better way. Something like below.

1. #include <stdio.h>
2. int main()
3. {
4. int sum_till_now;
5.
6. sum_till_now = 1 + 2;
7. Repeat the step below till we have added 10:
8. sum_till_now = sum_till_now + 3;
9.
10. printf(¨The result is %d\n¨, sum_till_now);
11. }

See statement 7 above. We have expressed it in plain English, which the computer does not understand. What it understands is something perfectly formal, as below:

1. #include <stdio.h>
2. int main()
3. {
4. int sum_till_now = 0;
5. int next_number = 0;
6.
7. while (next_number < 10)
8. {
9. next_number = next_number + 1;
10. sum_till_now = sum_till_now + next_number;
11. }
12.
13. printf(¨The result is %d\n¨, sum_till_now);
14. }

Statements 7 introduces the while statement. Let's understand how a while statement works.

Whenever the while statement is executed, the condition in the statement is evaluated. If it is true, the code block (i. e. the set of statements in the curly braces) following the while statement is executed. After this, in stead of moving to the next statement, the execution again continues from the while statement.

If the condition in the while statement evaluates to false, the following code block is skipped, i. e. execution continues at the next statement after the code block.

Previous | Next

Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6

Learning Computer Programming - Page 3

Now, let´s teach this to a computer, i. e. write a computer program for this, using the C language. The program is given below. Note that the line numbers are given just for our reference. They are not part of the program.

1. #include <stdio.h>
2. int main()
3. {
4. int sum_till_now;
5.
6. sum_till_now = 1 + 2;
7. sum_till_now = sum_till_now + 3;
8. sum_till_now = sum_till_now + 4;
9. sum_till_now = sum_till_now + 5;
10. sum_till_now = sum_till_now + 6;
11. sum_till_now = sum_till_now + 7;
12. sum_till_now = sum_till_now + 8;
13. sum_till_now = sum_till_now + 9;
14. sum_till_now = sum_till_now + 10;
15.
16. printf(¨The result is %d\n¨, sum_till_now);
17. }

Let's understand the logic.

We shall not dig into the syntax, or grammar of C, and just try to understand the logic.

A program is executed step by step, from top to bottom.

Statement number 4 is similar to your drawing a box named sum_till_now in rough pad. Computer uses its internal memory as its rough pad. sum_till_now is called a variable. Similar to a box in your rough pad, a variable can hold a value.

See statement 6. It is called an assignment statement. ¨=¨ is called the assignment operator. When an assignment statement is executed, whatever is in the right side of ¨=¨ is evaluated and put into the variable in the left side. That means, after executing statement 6, the value of sum_till_now becomes 3.

Statement 6 can be read as ¨1 + 2 is assigned to sum_till_now.¨ Never confuse ¨=¨ with the equality operator as in common mathematics. Both are different.

Statement 7 is also an assignment statement. Evaluating the right side (i. e. sum_till_now + 3) results in 6 (remember that sum_till_now is now holding 3). So, 6 is assigned to the left side, i. e. sum_till_now.

Hence, after execution of statement 7, sum_till_now holds 6.

Carrying on, after execution of statement 14, sum_till_now holds 55, which is the desired output.

Done. But the program seems long. What if the problem were to add from 1 till 10000!

Previous | Next

Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6

Wednesday, October 22, 2008

Learning Computer Programming - Page 2

Let's write a program for adding the numbers from 1 to 10 (i. e. 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10).

Let's first try to do it ourselves, manually. Be patient not to miss a single step written below. Every word below is quite important.

We shall be using a rough pad and pencil. The rough pad will be used to scribble the intermediate results that we need to remember temporarily while solving the problem. As you shall see, in stead of scribbling on the pad directly, we shall be drawing some boxes and write inside the boxes. We shall give unique names to the boxes so that we can refer those.

So, start following the steps below.

Add 1 and 2 and note the sum in a box in your rough pad. Name the box as, say, sum_till_now. Or you can choose any name you like. So, your rough pad now looks like this:


Add 3 to the value stored in sum_till_now, and write the result back in sum_till_now. Note that as the box sum_till_now can contain only one value at a time, and hence you have to erase or cross the previous value. So, now your rough pad looks like:


Now, add 4 to the value stored in sum_till_now, and write the result back in sum_till_now. After this, your rough pad would look like:


Repeat these steps till you have added 10, and then your rough pad looks as below.


You get the desired result written in sum_till_now.

Previous | Next

Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6

Monday, October 20, 2008

Learning Computer Programming

I regard computer programming as the most interesting subject to learn on the earth. But to my dismay, most of the freshers I come across exhibit programming skills much below my expectations.

I think this happens because students miss the right approach to learn programming. Also, surprisingly, most of the programming courses I have seen begin abruptly, without addressing this first.

So, in this article, I will attempt to give a needed start to the students, so that they catch the train smoothly. Everyone who is thinking to learn programming should read this article.

What is Programming?

In simple terms, programming is teaching somebody how to do a task. Obvious examples are
  • teaching a child how to add some numbers
  • teaching a housewife how to prepare some recipe
  • any teaching under the earth that you can imagine
For programming human beings, we use some language, such as English, French, Hindi. For programming computers, we use some language the computers understand. Some examples of computer languages are C, Pascal, Python, Java.

Human beings are very intelligent and hence human languages like English are extremely complex. The same statement might mean different things in different scenario in English. In contrast, computers are the stupidest beings in the world, and so the language used to teach them are quite simple. So, for a human being like you, learning a computer language is really easy and fun. And, once you know one computer language, learning another is as easy as knowing few more words.

Enough theory. Now, let´s dive into and attempt some computer programs. We shall be using the C language. However, you need not know C. Of the programs that I shall be presenting, just focus on whatever we discuss and ignore the undiscussed parts. Our objective here is not to learn programming, but to learn the approach to learning programming, so that you can learn programming from any other course material smoothly.

Next

Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6

Friday, July 27, 2007

Why I chose Turbogears

Before I express why I chose Turbogears, I must confess that I am essentially a business application developer and not an expert in python or web technologies. I do not claim my choice to be the right one, and comments are most welcome.

In the beginning of 2006, I had to explore some rapid application development tools. That time I was a jack of all trades and master of none, and was thinking to consolidate myself on .NET.

But, to my surprise, I was totally knocked down by the development productivity some FOSS RAD frameworks were offering. The potential of the MVC frameworks on dynamically typed languages (Python and Ruby) affected me so much so that I did not mind leaving everything else.

So, I planned to practice one such framework, leaving .NET.

The crucial task before me then was to choose the framework to focus on. Although people say that it should depend on requirements, being a beginner, I did not have that skill and time to learn unfocused.

There were a lot of MVC frameworks, and my rough search hinted me that the leaders were RoR, Django, Turbogears, Pylons and Zope.

I tried using Zope for a couple of weeks, but it seemed too complex to me, and then I left it and switched over to RoR.

I was happy evaluating RoR, until I found out that the default ORM of RoR does not support certain things like composite primary keys, and hence it might be difficult for me to integrate to existing enterprise databases, or develop complex applications.

Then I pondered over Django. But I quickly discovered that although it seemed as the most popular framework on Python, it was having the same ORM problem as RoR.

This left me with Turbogears and Pylons. Among these two, Turbogears seemed more complete, having many readily available/integrated components like identity management and widgets.* I felt that if I went with Pylons, I might still have to write some top level layers or plumbing code, which Turbogears could readily provide. Also, Turbogears was much more mature and popular, having a big user group, from which I guessed that development and debugging would be faster.

So, I chose Turbogears.

Today, I feel happy to be with Turbogears. With some experience, I had further discovered the following points to support my choice:

1. It readily supports SQLAlchemy, which seems as the best of the ORMs in its class. One might argue that nothing prevents me from intergating SQLAlchemy with Django, but being a novice business application developer with tight schedule, I am afraid of such system coding.

2. It is on Python. Python is much more widely used than Ruby, and has a lot of FOSS tools and frameworks I can take benefit of.

3. It's a collection of many best-of-the-breed components. That means, there goes a huge amount of collective effort in the background.

4. It's forward looking in terms of technology.

5. The future version of Turbogears, 2.0, aims to be a thin layer on the top of Pylons. What I understand by this is that I would have the best of both worlds.

6. Some benchmarks say that the performance of Django is better, but performance being a solvable problem, does not bother me much.

Comments are welcome.

Sanjay

* As of this writing, I think Pylons has identity management and widgets, although in some early stage.