Sunday, October 27, 2013

Come, let's build this great nation!

My dear friends,

I know most of you who read this note are in the age group 18-35 years. Nevertheless all Indians can read this. Friends, we have a herculean task in hand - building this great nation. So come, let's build this great nation!

How long should we keep lamenting the poor performances of successive governments? Why don't we take greater interest in throwing away a bad government by casting our votes without fail? Don't we wait patiently to buy tickets for a movie? Don't we wait patiently for food that we order in the restaurants? Then why not wait patiently in a queue to vote for a suitable candidate? Come, let's build this great nation!

Now, don't say all politicians are unfit to be elected, and so there is no use casting vote. There are people and there are governments which have performed well, more so in the recent past. Surprising right? It is true. Now, Ill not get into details about people and governments who have done well, for I fear that would divert the course of the discussion intended. So come, let's build this great nation!

Though we have a not-so-good political culture, (which I am sure would improve in the years to come) we have one of the best electoral processes and civil liberties when compared to other countries. India is one of the few countries which gave voting rights to all its citizens. So why not use it effectively? So come, let's build this great nation!

The earth's population was about 7.046 billion in 2012. With growth rate of 1.5%, India alone contributes 17% of world's population. It is predicted that by the year 2030, India would surpass China's population and we would be the most populous country in the world. With so many skilled, industrious labors why should India have problems on various fronts? This also means, if population is not managed effectively, it would turn be a big liability. So isn't our duty to be a part of India's growth story? So come, let's build this great nation!

Now let’s talk about our GDP growth. GDP growth in 2012 was estimated to be just 3.2%. Why are we still not able to cross a double digit growth rate? We need more economic reforms and a boost to infrastructure development to accelerate growth. So come, let's build this great nation!

As per the World Bank reports, 32.7% of Indian population still suffer from poverty. Why have we not been able to bring down this figure to a single digit even after 66 years of independence? This in turn needs an elaborate discussion on economic and political policies. So, shouldn't we need to send the right Netas to the Vidhan Sabhas and Sansad? So come, let's build this great nation!

60 years is a long time in a human's life and that's why people retire at this age. But for a nation, that's too complex like India, 60 years time of parliamentary democracy is too less. She has a very long way to travel, and that requires the co-operation of all her citizens. So come, let's build this great nation!

Friends, this note on facebook is not written for earning likes. This was written by a concerned citizen of a great nation, to tell you all that elections are round the corner; we all must get ready to discharge our duties as responsible citizens. SO PLEASE DO VOTE IN THE UPCOMING ELECTIONS. If you do not possess a voter's ID, please do apply for it and ensure you obtain one. Do not blame the process for not giving one; it is your duty to get one. Come, let's build this great nation!

Voting in elections is not just your right; it is your duty as well!

Let me throw out a question to all of you out here. How many of you are promising me that you would definitely vote in the upcoming election and in the years to come?

Please spread the news if possible!

Bharat Mata Ki Jai!!


Thanks,
Srikrishnan S

Friday, August 23, 2013

Spring Form with Checkboxes

In this post, I shall explain how to create a Spring form with check boxes. Additionally, we will learn how to make a list of items checked by default.

web.xml : 

1:  <web-app id="WebApp_ID" version="2.4"  
2:    xmlns="http://java.sun.com/xml/ns/j2ee"   
3:    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
4:    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   
5:    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
6:    <display-name>Spring MVC Application</display-name>  
7:    <servlet>  
8:     <servlet-name>HelloWeb</servlet-name>  
9:     <servlet-class>  
10:       org.springframework.web.servlet.DispatcherServlet  
11:     </servlet-class>  
12:     <load-on-startup>1</load-on-startup>  
13:    </servlet>  
14:    <servlet-mapping>  
15:     <servlet-name>HelloWeb</servlet-name>  
16:     <url-pattern>/</url-pattern>  
17:    </servlet-mapping>   
18:  </web-app>  

HelloWeb-servlet.xml :

1:  <beans xmlns="http://www.springframework.org/schema/beans"  
2:    xmlns:context="http://www.springframework.org/schema/context"  
3:    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
4:    xsi:schemaLocation="  
5:    http://www.springframework.org/schema/beans     
6:    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
7:    http://www.springframework.org/schema/context   
8:    http://www.springframework.org/schema/context/spring-context-3.0.xsd">  
9:    <context:component-scan base-package="com.sri.test" />  
10:    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
11:     <property name="prefix" value="/WEB-INF/jsp/" />  
12:     <property name="suffix" value=".jsp" />  
13:    </bean>  
14:  </beans>  

Subject.java :

1:  package com.sri.test;  
2:  import java.io.Serializable;  
3:  public class Subject implements Serializable{  
4:      /**  
5:       *   
6:       */  
7:      private static final long serialVersionUID = 7135393884889475409L;  
8:      private int subjectId;  
9:      private String subjectName;  
10:      public Subject() {  
11:          super();  
12:      }  
13:      public Subject(int subjectId, String subjectName) {  
14:          super();  
15:          this.subjectId = subjectId;  
16:          this.subjectName = subjectName;  
17:      }  
18:      public int getSubjectId() {  
19:          return subjectId;  
20:      }  
21:      public void setSubjectId(int subjectId) {  
22:          this.subjectId = subjectId;  
23:      }  
24:      public String getSubjectName() {  
25:          return subjectName;  
26:      }  
27:      public void setSubjectName(String subjectName) {  
28:          this.subjectName = subjectName;  
29:      }  
30:      @Override  
31:      public boolean equals(Object obj) {  
32:          if (this == obj)  
33:              return true;  
34:          if (obj == null)  
35:              return false;  
36:          if (getClass() != obj.getClass())  
37:              return false;  
38:          Subject other = (Subject) obj;  
39:          if (subjectId != other.subjectId)  
40:              return false;  
41:          if (subjectName == null) {  
42:              if (other.subjectName != null)  
43:                  return false;  
44:          } else if (!subjectName.equals(other.subjectName))  
45:              return false;  
46:          return true;  
47:      }   
48:  }  

Student.java :

Student has one-to-many association with Subject:

1:  package com.sri.test;  
2:  import java.io.Serializable;  
3:  import java.util.List;  
4:  public class Student implements Serializable{  
5:      /**  
6:       *   
7:       */  
8:      private static final long serialVersionUID = -779930820340758193L;  
9:      private int studentId;  
10:      private String studentName;  
11:      private List<Subject> subjectList;  
12:      public Student(int studentId, String studentName, List<Subject> subjectList) {  
13:          super();  
14:          this.studentId = studentId;  
15:          this.studentName = studentName;  
16:          this.subjectList = subjectList;  
17:      }  
18:      public Student() {  
19:      }  
20:      public int getStudentId() {  
21:          return studentId;  
22:      }  
23:      public void setStudentId(int studentId) {  
24:          this.studentId = studentId;  
25:      }  
26:      public String getStudentName() {  
27:          return studentName;  
28:      }  
29:      public void setStudentName(String studentName) {  
30:          this.studentName = studentName;  
31:      }  
32:      public List<Subject> getSubjectList() {  
33:          return subjectList;  
34:      }  
35:      public void setSubjectList(List<Subject> subjectList) {  
36:          this.subjectList = subjectList;  
37:      }      
38:  }  

HelloController.java :

allList is a list of all the subjects available; enrolledList is a list of subjects that a student has enrolled. We simply add student object and allList to the ModelMap and return the view.

1:  package com.sri.test;  
2:  import java.util.ArrayList;  
3:  import java.util.List;  
4:  import org.springframework.stereotype.Controller;  
5:  import org.springframework.ui.ModelMap;  
6:  import org.springframework.web.bind.annotation.RequestMapping;  
7:  import org.springframework.web.bind.annotation.RequestMethod;  
8:  @Controller  
9:  @RequestMapping("/")  
10:  public class HelloController{  
11:    @RequestMapping(value = "", method = RequestMethod.GET)  
12:    public String printHello(ModelMap model) {  
13:     model.addAttribute("message", "Hello Spring MVC Framework!");  
14:     List<Subject> allList = new ArrayList<Subject>();  
15:     allList.add(new Subject(1,"English"));  
16:     allList.add(new Subject(2,"Maths"));  
17:     allList.add(new Subject(3,"Science"));  
18:     allList.add(new Subject(4,"Social"));  
19:     allList.add(new Subject(5,"Tamil"));   
20:     List<Subject> enrolledList = new ArrayList<Subject>();  
21:     enrolledList.add(new Subject(1,"English"));   
22:     enrolledList.add(new Subject(3,"Science"));  
23:     Student student = new Student(1,"SRI",enrolledList);  
24:     model.addAttribute("student", student);   
25:     model.addAttribute("allSubjectList", allList);  
26:     return "home";  
27:    }  
28:  }  

home.jsp : 

This holds the spring form. commandName is the model attribute which is used to fill the form, the path is the model to be used to pre-populate data, items point to list of all the subjects available and path to the subjects taken by the student model.

1:  <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>  
2:  <html>  
3:  <head>  
4:  <title>Hello World</title>  
5:  </head>  
6:  <body>  
7:      <h2>${student.studentName}</h2>  
8:      <form:form method="POST" action="save" commandName="student">  
9:          <form:checkboxes title="Subjects taken" path="subjectList"  
10:              items="${allSubjectList}" itemLabel="subjectName" element="div" />  
11:      </form:form>  
12:  </body>  
13:  </html>  

Output:


Cheers!

S. Srikrishnan

Sunday, August 4, 2013

Thiruvilayadal with Java


Q. Pirikka vendiyathu ennavo?
A. Model-um View-um

Q. Piriya koodathathu?
A. Spring-um Hibernate-um

Q. Sernthe iruppathu?
A. JSP-um JSTL-um

Q. Seramal iruppathu?
A. Service-um DAO-um

Q. Parthu rasippathu?
A. Javadoc comments

Q. XML ku?
A. JAX-B library

Q. JSON ku?
A. Jackson library

Q. Library-il siranthathu?
A. Apache Commons

Q. SDLC-il siranthathu?
A. Agile Methodology

Q. Lead-ku?
A. Naan!

Q. Developer-ku?
A. Nee!

Aiyaaa, ala vidu!



Saturday, May 18, 2013

Model – View Separation




Our team was waiting outside a food stall starring at the list of snack items that was put up on the board. I read one by one that was listed, and at one point my eyes stopped at “Cutlet”. “I will go with cutlet”, I said. The billing person (Lets call him the controller for now; as to why so, will be told shortly) nodded his head and proceeded to bill it. Then there came a notification from someone from the kitchen premises that cutlets were all over. Now, if the cutlets represented the actual “model”, the display board was the view. So, now I’ve explained why the billing person is the “controller”. Now if the controller had promptly informed the view about the change in the model, things would not have gone for a toss. (I know it is not something that is catastrophic, but still)

Model – View - Controller (MVC) pattern is awesome I tell you. When I was new to this pattern, I saw MVC as one among the many patterns available, but now I see it as a master pattern, the pattern that solves “data-here-display-how” problem. Let us see how MVC applies to different problems.

Firstly, I’ll talk about the files in a file system. We get to see many views of the file system- one as a general file system explorer, one as a tree structure, one as a file picker / saver dialog et al. The model is the same – the file system; the views are different.


(The tree view and the flat view of the file system)

(The file saver/picker view of the file system)

PhpMyAdmin, a tool to handle the administration of MySQL provides a view of the data in the database system. You may also wish to open a console and connect to the MySQL server. My aim here, is to explain how the model being same, is rendered in different views.

Let’s move on to few real life examples. The cutlet-board-hotel thing was one. Now, let me talk about, hmm say X-rays? X-ray gives a “view” of the actual model, the bone. 



We need to keep in mind that only “updatable” views result in change of the model information. Now, if your hand is broken, and you think you can change the X-ray image to fix the broken hand, my friend, it’s an epic fail attempt. And when you work on say, PhpMyAdmin, you can update a table, by updating the view (Hey not the SQL view, I am talking about the front end view you see on the browser), of course if only you got the permission for it. (Forget Jee-Boom-Bah pencil now)

My message to the computer science world: apply MVC pattern, it makes life simple and easy. Long live MVC! Long live MVC!

Cheers!

- ∫.∫rikrishnan

Sunday, March 3, 2013

Separation of concerns



A concern, however trivial it might seem to be, needs our immediate attention, as it might grow to something catastrophic if not tackled properly. We see people, who while talking let their ‘concerns’ interfere with the lucidity of their thought process. If one is able to distinguish the concerns involved and address each one of them separately, the problem is solved.

A computer science engineer by now would have guessed that I am talking about Aspect Oriented Programming and weaving. Well, I am not going to stick to that ‘aspect’ alone. Ok, let me hit it straight. There are things that always need to be separate initially, resolved individually and then ‘weaved’ carefully. That means, they have to live separately and carry out their work in tandem.

The separation of business logic from presentation logic is an important concern in software development. This enhances pluggability. Have we not seen electronic media reporting a piece of information in a variety of ways? Model being the same, we get to see different views. Well, this is one natural advantage of Model-View separation; lucky media people! Now, take the example of HTML, CSS separation. While HTML is all about document structure, CSS is about offering styles to the document. The same is the case with LaTeX, where the presentation of content and the content itself are separate. This tool is popular over WYSIWYG editors for the very reason- the concerns are separately addressed.

Earlier during king rule, judiciary and executive were one. These concerns are now separate in our country. Rulers and their parties are separate concerns. There needs to be a perfect co-ordination between the two, but at the same time, they should not interfere with each other’s business. Well, it is the duty of the leader to ensure that; in other words, a good leader is one who ensures that with sincerity. People misusing cars provided by their workplaces for personal use, usually for dropping their kids in school are not a rarity. Clearly, separation of concerns rule is violated.

The philosophy part starts here. Body and soul are also separate. Body is dead, once the soul departs. Body is perishable, soul is not. Body and soul are separate concerns. Body is something temporary. To accuse someone of being short is not right as it is not his / her posession. For that matter, one cannot claim posession of anything in this world. We come empty handed; we leave empty handed; however, we quarrel stupidly for things that are not ours.

Cheers.

Thursday, February 7, 2013

Acharya Devo Bhava


Kid 1: No!, give it to me its mine!!
Kid 2: Definitely not! It is mine.. Go away!
Kid 1: Can't you see its blue in colour..
Kid 2: Hey you! Its my blue colour pencil box! My mom got it for me.
Kid 1: No way! It is a double-back box, which only belongs to me...
Kid 2: Hey let's look at the label on the box. Haa do you see? It has my name written on it. See. See. See.
Kid 1: Huh??? Mummmyyyy! My box is missingg....

Interesting conversation right?? Immature kids squabble to find out who the rightful owner is. They start by comparing the properties of the box; the issue is resolved when they find a property (the label which has a name) being different. So, what it all ammounts to, is an invocation to overriden equals method of box class!

public class PencilBox {

    private Color boxColor;
    private boolean isDoubleBack;
    private String ownerName;
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof PencilBox)) {
            return false;
        }
        PencilBox other = (PencilBox) obj;
        if (boxColor == null) {
            if (other.boxColor != null) {
                return false;
            }
        } 
        else if (!boxColor.equals(other.boxColor)) {
            return false;
        }
        if (isDoubleBack != other.isDoubleBack) {
            return false;
        }
        if (ownerName == null) {
            if (other.ownerName != null) {
                return false;
            }
        } 
        else if (!ownerName.equals(other.ownerName)) {
            return false;
        }
        return true;
    }
}

The point that I am making is... Why cant professors include such anologies during the course of the lectures? These are simple tricks to make a class interesting. Sadly, there are very few who do that. Taking into account a student's difficulties in sitting in a class for an hour, why shouldn't a prof aim at keeping the class enthusiastic. I would deliver such a lecture if only I were a prof.

Say I would have to lecture on Comparable interface, the conversation I would provide is this:

Dad: Only 87?? Why??? Why didn't you score a 100?
Son: Dad, only 5 people have got above 80 and only 1 above 90! No 100s this time dad.
Dad: Don't you say that! Why were you not that person who scored 90.
Son: Dad!!
Dad: Are you aware of something? At your age, Einstein was a brilliant student!
Son: Dad, at your age, Nehru was the Prime Minister of India. Please don't compare me with others!

Hmm.. that's right... To all parents out there, don't ever compare your kids with their friends. Well, students do not implement Comparable interface; so you cant do that!

Here is a report on "The Teaching-With-Analogies Model" :

"An analogy is a similarity between concepts. Analogies can help students build conceptual bridges between what is familiar and what is new. Often, new concepts represent complex, hard-to-visualize systems with interacting parts. Analogies can serve as early “mental models” that students can use to form limited but meaningful understandings of complex concepts. Analogies can play an important role in helping students construct their own knowledge, a process that is encouraged in the Standards and consistent with a constructive view of learning. As students' develop cognitively and learn more science, they will evolve beyond these simple analogies, adopting more sophisticated and powerful mental models. The model has been validated in formal experiments and classroom settings in which the strategic use of analogies has been found to increase students’ learning and interest."

I wish to stress on the point that to be or not to be a good lecturer completely depends on the way a professor carries himself in the class. India has produced great gurus – Dronacharyar, Ramanujar, Adisankarar, Dr. Radhakrishnan, Dr. A.P.J. Abdul Kalam, the list is actually endless. Who would forget the famous story of Dr. Radhakrishnan's carriage being pulled by students with cries of 'Radhakrishnan ki jai', when he left the Calcutta university. Devotion towards to gurus is absolutely essential for a student to progress. We learn this from many - Vishwamitra - Rama, Krishna - Arjuna, Satakopar - Madurakavi, Ramanujar - Ananthazhwar etc. Acharya Devo Bhava!

Professors can bring about a significant change in students lives. Professors, inspire and carry them with you, for they will bring all laurels back to you!

ReferenceThe Teaching With Analogies Model, http://www.coe.uga.edu/twa/PDF/Glynn_2007_article.pdf


Tuesday, January 22, 2013

Dear Rain, where are you??




People say a disaster like flood is manageable; not drought. But a disaster is a disaster, so why say drought is even more disasterous. The reason they give is that flood can be mitigated to some extent; it is not so easy in the case of a drought. People of Tamil Nadu, especially Chennai know that better. TN was hit severely both by drought (From 2001 to 2004) and floods (In 2005-2006).

With soaring prices of metro water, the struggle we had to put as a result of water scarcity in the city was profuse. Scenes of women squabbling on the streets were quite common; there were instances where the local police had to arrive, to settle the issue smoothly. I still remember this: we were advised by the apartment association to use only 3/4th a bucket for bathing, and only a mug for a face wash!

It was in the year 2003 that the government of TN made the rainwater harvesting scheme mandatory : 

"Through an ordinance titled Tamilnadu Muncipal Laws ordinance, 2003, dated July 19, 2003, the government of Tamil Nadu has made rainwater harvesting mandatory for all the buildings, both public and private, in the state. The deadline to construct rainwater harvesting structures is August 31, 2003. The ordinance cautions, "Where the rain water harvesting structure is not provided as required, the Commissioner or any person authorised by him in this behalf may, after giving notice to the owner or occupier of the building, cause rain water harvesting structure to be provided in such building and recover the cost of such provision along with the incidental expense thereof in the same manner as property tax". It also warns the citizens on disconnection of water supply connection provided rainwater harvesting structures are not provided."

MTC buses plying across the metro carried advertisements urging the need for rain water harvesting. Slowly it became a people's movement.  After the implementation of this scheme, a significant increase in both the quality and level of ground water was noted. The water quality in Chennai is a long way to reach International standards. After an Indian Ocean tsunami lashed the shores of TN, the weather pattern changed drastically. Bay of Bengal which could withstand not more than one or two cyclones, witnessed 4 to 5.  During the year 2005-2006, the highest rainfall of 2356.5 mm was recorded in Chennai district.

2012 was a disappointment for Chennai. TN is one of the states which receives rain from both South-West and North-East monsoon. Usually when the city records less rainfall, the south-west monsoon bridges the gap. This year it fell short by nearly 7 cm of the season’s normal of 41 cm. Overall shortage is estimated to be 33%.

I was taken aback when people were literally praying that it should'nt rain during the ARR concert or during the cricket matches. Short-term pleasures, unmindful of long term ones, seem to be the need of the hour. People, its high time we change our mindset. Why do we often hear the king in dramas uttering the words "நாட்டில் மும்மாறி பொழிகிறதா  அமைச்சரே ??" (Minister, is there enough rainfall in our country?) 

Although water provides no calories or organic nutrients, it is essential for every known form of life. It is considered as a purifier in most religions, philosophy and literature. For the crops to grow, for the agriculture and plains to flourish and for us to sustain on this planet we need water. And what is the purest form of water? Rain.