Search This Blog

Thursday, April 29, 2010

Scope of Smartcard Application In India

There is lot of opportunity in India for smartcard based application development and integration project.For brief history about smart card refer my previous post

History of Smartcard

How does smartcard going to be a part in our life In India:

In the form

  1. Driving license
  2. Passport
  3. Debit/Credit card in Bank
  4. In hospital for Identifying there Patient with there existing disease.
  5. Even the call taxi operator are planning to issue the smartcard to there customer for minimize the fraud in vary amount charged to the same trip and safe of the customer(where they are departure and boarding details are captured)
  6. Retails owner are also going to issue the smartcard to the customer for introducing different scheme for there retain customer.

So there is lot of other project also in pipe line …

What are the threats are involved:

  1. Theft of smartcard
  2. fraudulent
  3. multiple smartcard( multiple passport, multiple driving license) for the same user
  4. No Centralized authentication server for identifying & verifying the person.

What is the solution for all above threats?

UIDAI-Unique Identification authority of India

1. This authority is going to capture Demography, Bio-metric, Iris details of the entire citizen in India

2. Its check the de-duplication of user details and provide AADHAAR id to the all citizen

3. This project is in pilot version now. I hope this AADHAAR ID going to change our living style in India.

We can use this AADHAAR ID for identifying the person.

Even they ready with all the details and online verification of bio-metric details like finger print verification already in pilot.

Conclusion:

Who ever planning to do smart card based application development in India please keep your eye in each and every movement of UIDAI.

So we can deliver very robust & secure application to end user.

Difference Between Interface and Abstract Class in Java

Java Abstract Class & Interface:

I am admire always about java classes and Interface.
Did any(normal) software developer think about why Class and Interface.
I have started discover about the need of class and Interface after joining in software development company.
That time i don't have deep knowledge about the Java, So i have used to ask all doubt to my Team lead ,he has only 2 year Exp. He teach ed me about all technique behind Java.

What is Class?
All are used to define class is the collection of instance variable and different methods for
different operation.
As of my knowledge and understandable class is a entity in real world is nothing but the one Real object (ie. Human is a entity ) and that object is have set of property(ie., Gender,Height,weight,country) are called attribute(Instance variable).
Same Real Object has set of operation (Speak,Read,Write) are called Methods in Java

So class declaration will as follow in java.
package com.blogspot.microtechinfo;

/**
*
* @author root
*/
public class Human {

char Gender;
int Height;
int weight;
int country;
public void Read()
{System.out.println("Read Up");}
public void Write()
{System.out.println("Write");}
}

Where the Reusability will come into pictures of Java?
All we used to think that java provides more re usability than C. How Java achieving reusability answer is using inheritance.
Inheritance is possible for both class and Interface.

What does means Inheritance?
Inheritance its the process to get the property & operation from the inherited class. The inherited class are called Parent class.
The inheritance class is called Child class.
We have class called Human. All employee of the organization are human and has some set operation(methods) and Property(atribute).
In java we can achieve the inheritance using two key word are extends for class and implements for Interface.
With example ::
package com.blogspot.microtechinfo;

/**
*
* @author root
*/
public class Employees extends Human {
String designation="";
double salary;
///for overduty calculation
public int getOverDuty()
{
return 5;
}
public static void main(String str[])
{
System.out.println("With in Employee");
Employees employees=new Employees();
///////Miracle start here ///
////How Read& Write method is visible here????
employees.Read();
employees.Write();
System.out.println("GetOverDuty:::"+employees.getOverDuty());
///////All credit goto the extends keyword in java.
}

}
output:::
With in Employee
Read Up
Write
GetOverDuty:::5

Its all about Inheritance and Re usability are achieved in java.
Before need to know the Difference between abstract class and Interface we must familiar with the inheritance.

Interface in Java:
Its a type of class only has the declaration of methods and Definition of the the property(Instance variable).
In more technical :
Its a set of predeclared rules that should be implemented by the followers(Class) of the interface.
In our example I am going to declare that every employer should have set of functionality like isTeamLead,isIIMorIITStudent, isIndianCitizen,totalInvestMent



Interface for rules defined for Employer:

package com.blogspot.microtechinfo;

/**
*
* @author root
*/
public interface EmployeerInter {
public boolean isTeamLead(boolean set);
public boolean isIIMorIITStudent(boolean set);
public boolean isIndianCitizen(boolean set);
public void totalInvestMent(int InvestAmt);

}

employer class should implements as follow::

package com.blogspot.microtechinfo;

/**
*
* @author root
*/
public class Employeer implements EmployeerInter {

public boolean isIIMorIITStudent(boolean set) {
return set;
}

public boolean isIndianCitizen(boolean set) {
return set;
}

public boolean isTeamLead(boolean set) {
return set;
}

public void totalInvestMent(int InvestAmt) {
System.out.println("InvestAmt::"+InvestAmt);
}
public void OwnMethod()
{
System.out.println("I am from Employeer");
}
public static void main(String arg[])
{
Employeer employeer=new Employeer();
employeer.OwnMethod();
///////Statr the Magic Here
System.out.println("isITTMorIITStudent::"+employeer.isIIMorIITStudent(true));
System.out.println("isIndianCitizen::"+employeer.isIndianCitizen(false));
System.out.println("isTeamLead:::"+employeer.isTeamLead(true));
/////////Here the Employeer Can define there own functionality for Implemented class
//////The Magic is fully depends upon the Implement key word

}


}

Output::
I am from Employeer
isITTMorIITStudent::true
isIndianCitizen::false
isTeamLead:::true

Now we have understand the concepts of re usability clearly so we can move to the concept of
abstract class.
Requirement::

Parent class should have implemented method and set of Rules for child class in that case which will be supported.
1.Interface does not support because only declaration is possible.
2.Inherited Class method should have definition always.
So java introducing the concept of Abstract class.

What is abstract Class:
Its has both Implementation and declaration of methods(i.e. Rules for the child class).
Abstract class Syntax
abstract class SampleAbstract{}
method declaration::
abstract public void abstractMethod();

Sample Code:::
package com.blogspot.microtechinfo.abstractpkg;

public abstract class SampleAbstract {

abstract public void abstractMethod();
public void MethodDef()
{
System.out.println("Method Definition");

}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("with in Main");


}

}

package com.blogspot.microtechinfo.abstractpkg;

public class AbstractMethodImp extends SampleAbstract {

@Override
public void abstractMethod() {
// TODO Auto-generated method stub
System.out.println("I am implemented abstract method..");

}

public static void main(String arg[])
{

AbstractMethodImp abstractMethodImp=new AbstractMethodImp();
abstractMethodImp.abstractMethod();
abstractMethodImp.MethodDef();
}
}


Conclusion is very simple:




These are main difference between abstract class and Interface abort from Inheritance and abstract class. If any other difference please leave as comments.

Sunday, April 11, 2010

How to get second largest salary from employee table?

Here I am going to narrate about one of frequent interview question. Get second largest salary from employee table.

I am planning to explain this topic with 6 steps:

Reader must familiar with Mysql database. Otherwise directly look the step 4 & 5 to know about the logic.

1. Software:

Database: Mysql 5.1

Query Browser: mysql command Line Client (come with mysql setup installation)

2. Database & Table ( DDL)

Database: test (Mysql in-build database so no need the query for database creation).

Table Name:employees

Query:

create table employees(emp_no integer primary key,name varchar(100),salary double);

3. Insert records into the employees table. (DML)

Query:

· insert into employess values(1,'Muthu',20000.00);

· insert into employees values(2,'Raj',18000.00);

· insert into employees values(2,'Jack',18000.00);

· insert into employees values(4,'Bala',16000.00);

Summary

mysql> select *from employees;

+--------+-------+--------+

| emp_no | name | salary |

+--------+-------+--------+

| 1 | Muthu | 20000 |

| 2 | Raj | 18000 |

| 3 | Jack | 18000 |

| 4 | Bala | 16000 |

+--------+-------+--------+

4. Answer 1:

select max(salary) from employees where salary not in(select max(salary) from employees);

This query is portable across the all other databases.

Result:

| max(salary) |

+-------------+

| 18000 |

+-------------+

Explanation:

· First execute the where condition select query (sub query) ie. Query become

select max(salary) from employees where salary not in(20000)

· Next execute the above formed query with “not in key word”.

· Not in key word exclude the ‘20000’ salary from table and select second largest query.

5. If they ask to gets the number of employees getting the second largest salary than what will be the query.

Answer:

You have to make one more sub query with “in key word”

Select count(*) from employees where salary in(select max(salary) from employees where salary not in(select max(salary) from employees));

Now you will get 2 as answer.

+----------+

| count(*) |

+----------+

| 2 |

+----------+

6. other way to get second largest salary is:

Query is::

select salary,emp_no,name from employees order by salary desc limit 1,1;

This query only work with mysql but logic is very simple

Make the descending order of the table and select the second record from table.

Descending Order: order by salary desc

Select Second record: limit 1,1;

Using this we can get the remaining details of the employees.

+--------+--------+------+

| salary | emp_no | name |

+--------+--------+------+

| 18000 | 2 | Raj |

+--------+--------+------+

I going to give the option to reader to find the how many employees are getting second largest salary using 6th step.