Thursday 30 January 2014

Annotations in action

Introductions:

Annotations is not new to JEE programmer, we are often using annotation while coding in spring or hibernate or simple servlet-3 or  EJB-3. Day by dat the popularity of annotations goes increasing. One line annotation can reduce 10 line of XML configuration.In other word the popularity of java is because of annotation.

So before using annotations we should know and understand it better.This blog will cover  what is annotation how to use it effectively and how to create and use your own custom annotation.

At the end of session we attached some source code of spring-MVC related annotation like @Controller, @ResuestMapping etc.

What is Annotation?

Java annotations are used to provide meta data for Java code, data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code they annotate.

Uses/Purposes of annotation:

  • Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings.
  • Compile-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth.
  • Runtime processing — Some annotations are available to be examined at runtime.

Create your custom annotation:

It is possible to create your own annotations. Annotations are defined in their own file, just like a Java class or interface. Here is an example:

@interface MyAnnotation {

    String     value();
    String      name();
    int           age();
    String[]   newNames();

}

This example defines an annotation called MyAnnotation which has four elements.
Notice that each element is defined similarly to a method definition in an interface. It has a data type and a name. You can use all primitive data types as element data types. You can also use arrays as data type. You cannot use complex objects as data type.
To use the above annotation, you do like this:

@MyAnnotation(
    value="123",
    name="Jakob",
    age=37,
    newNames={"Jenkov", "Peterson"}
)
public class MyClass {


}
As you can see, I have to specify values for all elements of the MyAnnotation annotation.

Annotation Default Values:

You can specify default values for an element. That way the element becomes optional and can be left out. Here is an example of how the annotation definition looks with a default value for an element:
@interface MyAnnotation {

    String   value() default "";

    String   name();
    int      age();
    String[] newNames();

}
The value element can now be left out when using the annotation. If you leave it out, it will be considered as if you had used the default value for the value element. Here is an example:
@MyAnnotation(
    name="Jakob",
    age=37,
    newNames={"Jenkov", "Peterson"}
)
public class MyClass {


}
Notice that the value element is no longer present.

@Retention

You can specify for your custom annotation if it should be available at runtime, for inspection via reflection. You do so by annotating your annotation definition with the @Retention annotation. Here is how that is done:
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)

@interface MyAnnotation {

    String   value() default "";

}
Notice the annotation added above the MyAnnotation definition:
@Retention(RetentionPolicy.RUNTIME)
This is what signals to the compiler and JVM that the annotation should be available via reflection at runtime. Accessing annotation at runtime is covered in my Java Reflection and Annotations tutorial, which is part of my Java Reflection Tutorial.
The RetentionPolicy class contains two more values you can use:
RetentionPolicy.CLASS means that the annotation is stored in the .class file, but not available at runtime. This is the default retention policy, if you do not specify any retention policy at all.
RetentionPolicy.SOURCE means that the annotation is only available in the source code, and not in the .class files and not a runtime. If you create your own annotations for use with build tools that scan the code, you can use this retention policy. That way the .class files are not poluted unnecessarily.

@Target

You can specify which Java elements your custom annotation can be used to annotate. You do so by annotating your annotation definition with the @Target annotation. Here is an example:
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

@Target({ElementType.METHOD})
public @interface MyAnnotation {

    String   value();
}
This example shows an annotation that can only be used to annotate methods.
The ElementType class contains the following possible targets:
ElementType.ANNOTATION_TYPE
ElementType.CONSTRUCTOR
ElementType.FIELD
ElementType.LOCAL_VARIABLE
ElementType.METHOD
ElementType.PACKAGE
ElementType.PARAMETER
ElementType.TYPE
Most of these are self explaining, but a few are not. Therefore is here an explanation of the few that are not obvious.
The ANNOTATION_TYPE target means annotation definitions. Thus, the annotation can only be used to annotate other annotations. Like the @Target and @Retention annotations.
The TYPE target means any type. A type is either a class, interface, enum or annotation.

@Inherited

The @Inherited annotation signals that a custom annotation used in a class should be inherited by subclasses inheriting from that class. Here is an example:
java.lang.annotation.Inherited

@Inherited

public @interface MyAnnotation { }


@MyAnnotation
public class MySuperClass { ... }
public class MySubClass extends MySuperClass { ... }

In this example the class MySubClass inherits the annotation @MyAnnotation because MySubClass inherits from MySuperClass, and MySuperClass has a @MyAnnotation annotation.

@Documented

The @Documented annotation is used to signal to the JavaDoc tool that your custom annotation should be visible in the JavaDoc for classes using your custom annotation. Here is an example:
java.lang.annotation.Documented

@Documented
public @interface MyAnnotation {

}

@MyAnnotation
public class MySuperClass { ... }
When generating JavaDoc for the MySuperClass class, the @MyAnnotation is now included in the JavaDoc.
You will not use the @Documented annotation often, but now you know it exists, if you should need it.

Spring related annotation:

Source code for @RequestMapping:

Eg:

@RequestMapping(value = {"/markcompleted","/updateinteractionbyuniqueid"},method = {RequestMethod.POST,RequestMethod.GET})

Source code:


@controller:


For more spring related annotation you can form the spring source code form Github


Saturday 4 January 2014

All About Object

Introduction:

In an object oriented environment like java it's a common requirement to create object(instantiating a class), which is the basic building block. So we have to know the object better before creating and using them.

In a complex object oriented environment lot's of object will be there. Each object will have some role and responsibility, it's as simple as team work. For example DAO, BO, DTO etc. A DAO acronym as data access object, only know how to communicate with back-end which may not known to BO(Business object) because BO will have some different role and responsibility and so on.

This blog will explain you what is the necessity of creating a object, what happens internally when we are creating object. How many different way's are there to create object in java etc.

How an Object is different from a Class!!!

It seems lot's of professional is having same doubt and many of them are thinking that both object and class are same.

Conceptually both are different. A class is a blueprint to create object, there is no existence of class without object in other word object is representing a class.

For instance consider Animal. In particular there is nothing called animal it's just a common terminology which indicates to a group or category or class of leaving being.If I will tell dog or cat then it's existing and you can feel yes dog or cat is a prototype of an animal and in this case dog is an Object which represents Animal class.

So under a class we can create lot's of Object where as vice-versa is not applicable conceptually.
Hope you got a clear picture about object and class.

Does object and instance are same in java

Here we will discuss how object and instance are related as per java is concerned. 
Technically instance is a variable to hold an object. In other word instance is a handler for object.

          ABC  instance1 = new ABC();

 here ABC  >> is class, 
[new ABC();] >>as a whole it is a object 
instance1 >> is a instance or variable of type(user defined datatype) ABC.

In the above case new ABC()  is enough to create a object, technically we don't need  ABC  instance1  but for further use we have to store/assign the state of object to a particular instance/variable because in java each and every object is unique. later on we will discuss about this (hashcode, hashvalue etc).
In common practice you can consider instance is a alias for object hence both are same as per java is concerned different story for c and cpp.

Take the advantage of instanceof operator:

instanceof is a keyword using which you can able to check whether an instance is belongs to a particle object or not.



Why and when to create Object?

Basically in programming we are using lot's of veritable and blocks. Each veritable and block need some amount of memory. Memory is a resource of operating system so as a java programmer we don't have direct access to memory, it's highly encapsulated.

JVM is allocated few amount of RAM based on OS specification which is well know as runtime area and all static and non static member will use this based on demand and requirement. 

As per class member is concerned, we can divide the memory allocation into two parts. First one is Static members which will allocation memory while class loading by class-loader itself(an operation done by JVM to make the programme into process, if you want then you can implement your custom class loader) .

Then second one is allocating memory to non-static member, where we have to create object for allocating memory, in other word we will allocate  memory on demand dynamically. So the benefit is, no need to load all the member statically  like "C programming" because we may not use all member at time so unnecessarily it's wasting of memory which can be used by some other resource.



Object Internals/How Object works:

From previous discussion we came to know that, to assign memory dynamically we need to create object. But now question arises how the internal process is carried out and what actually happens Technically.

Brilliant question, we have answer for your question. OK to understand the answer you have to know your constructor better(We are assuming you have basic knowledge about Inheritance).

Role of Constructor  on Object Creation:

Not to forget, as per  java is concerned, the super class of all class is Object class, in simple if a class doesn't extends any class then by default it extends Object class.

For example i can write>> class A{...} equivalent to Class A{...} extends Object{...}

OK before proceeding further about "role of constructor on object creation" please solve the following debugging problem.




If you could observe the above programme then you must got the following output
        First
        Second

You must wander by looking at the output.
Yes whenever you are creating object you are calling the constructor. In the above  snippet

      ObjectAndConst objectandConst = new ObjectAndConst();

ObjectAndConst() means we are calling to a constructor. if already a constructor is there then jvm will pick that one or else default constructor will come into action.

While creating object for a class first it will call to that particular class constructor and as you know that the first line of each and every constructor is super keyword as hidden hence it will call to the super class constructor.

In our case ObjectAndConst class's super class is ObjectAndConstBase and again ObjectAndConstBase will call to Object class constructor(super class of all class is object class if that class doesn't not extends any class). After completely executing the object class constructor the control will come to calling place i.e ObjectAndConstBase class and it will execute the rest of code and again the control will call back to ObjectAndConst as the execution started form that place. 

In this whole process we are not only creating Object of ObjectAndConst class rather we are creating 3 object, first one is for Object class which will create first, second one is ObjectAndConstBase and finally ObjectAndConst which mean we create 3 different object(chain of Object) and assign to the instance of ObjectAndConst class



Different possible way to create Object:

There are several different way to create object, here we will discuss 5 different way of creating object

1. Using new keyword

    This is the most common way to create an object in java. I read somewhere that almost 99% of objects are created in this way.

    ABC object = new ABC();

2. Using Class.forName()

    If you know the name of the class & it has a public default constructor we can create an object in this way.

     ABC object = (ABC) Class.forName("org.JavaInCloud.java.ABC").newInstance();

 3. Using clone()

    The clone() can be used to create a copy of an existing object.

    ABC anotherObject = new ABC(); 
    ABC object = anotherObject.clone();

4. Using object deserialization

   Object deserialization is nothing but creating an object from its serialized form.

   ObjectInputStream inStream = new ObjectInputStream(anInputStream ); 
   ABC object = (ABC) inStream.readObject();

5. Using factory method

    Basically we are using this object creation method in  singleton designing pattern where we can't 
    directly create one object using new operator inter one static method will be there which will create 
    object and return the class instance which  is known as factory method.

Conclusion

I know you will have lot's of question in your mind. It's not feasible to write everything in a single post. So gradually we will add post by post. Feel free to comment in case of any question or suggestion.
Hope you enjoyed :)

 









Saturday 21 December 2013

Refresh java 7


It's not too late to Explore java7!!!

It's not too late to Explore java7.Update yourself by 55 hidden features of java7 before #Java8 releases. Slide by slide around 55 slide which covers maximum part of new feature added in java-7.




Sunday 27 October 2013

Collection Framework Part-1

Introduction:

This blog is about java collection framework. We designed this post by keeping beginner and intermediate learner in mind.

Joshua Bloch
Joshua Bloch
For collection framework  you no need to add any external jar file. it's an inbuilt feature in java since JDK 1.2 release.You can find  source code of collection in rt.jar(inbuilt jar). Collection framework is also know as Java Data Structure as we can find almost all data structure implementation in this library.

The chief design and implementer of collection framework is Joshua Bloch and currently he is associated with Google a former employee of
Sun Microsystem.

As Collection  Framework is a big part so we thought of dividing it into 3 part and this is the first part.

What is Collection Framework?

In simple Collection Framework is a library to handle group of object

As you know java is Object Oriented. So it's a common requirement to play with object like make them in a single group based on type, Storing  them not only that after storing we need to retrieving them when ever we need and performing some basic task like searching and sorting etc. These are few most common requirement we need.

So in case of c and c++ you have to define and write your own  algorithm and logic in order to full fill the above requirement. But fortunately java is API based and everything is readily available . The only thing we need to know is, how to use it. In other word we have to know how to store and get object from Collection.

All common used collection members you'll find in java.util package.

Why Collection Framework?

 As we told this is a library to handle group of object, so definitely you may rise a question like why not object array why all the useless stuff. Of course you are right you can handle a group of object using object array but the problem with  array is
  • Array is not allowing to store dissimilar type of object in other word we can not store different class object into the same array which is frequent requirement in Java(of course you can do it using an object array but its some what lander).
  • Adding object at the end of array is easy but inserting and deleting the element in middle of the array is difficulty. In this case we have to re-arrange all the element.
  • Retrieving the element from an array is easy but after riveting the element , if we want to process them, then there are no method available to carry out this.
Due to these problem programmer want a better mechanism to store a group of object. The alternative is using an object to store a group of object. It means that we can use a class object as an array . Such an object is called as Collection Object.

Advantage of using  Collection Framework.

Collections framework is worth your effort and will benefit your programming in many ways. Below i listed few benifity
  • As it's API based(a predefined library) so no need to write your own logic to store and retrieve element, the only thing you want to do is call a predefined method to store or retrieve object.
  • It dramatically increases the readability of your collections by providing a standard set of interfaces to be used by many programmers in many applications.
  • It makes your code more flexible by allowing you to pass and return interfaces instead of concrete classes, generalizing your code rather than locking it down.
  • You can customize  searching and sorting as per your requirement.

 

Overview about java.util package.

 As we already told collection framework is a library and in this library you can find a lot of common used class and interface which is inside java.util package. 

Overview about java.util package
Overview about java.util package.


The main interface of the collection framework is java.util.Collection. Here I am assuming that you are strong in java interface. java.util.Collection internally extends another interface known as java.lang.Iterable. 

By implementing/extend Iterable interface an object can take the advantage of "foreach" statement, we'll discuss about it in next heading.

So all classes and intefaces comming under java.util , we can brodly catagories inot two part
  • Collection by value(java.util.List, java.util.Set and implementation Classes)
  • Collection by key and value pair (java.util.Map and implementation Classes)

 Collection by value:

Using this type of collection we can  store only value and basically it's index based like Array.

Under this java.util.List, java.util.Set and Java.util.Queue. All 3 are interface are directly extending Java.util.Collection. All other classes and interfaces of java.util capable to store value will come under these parent interfaces.

Collection by key and value pair:

Using this type of collection we can store value corresponding to a key where key will be unique and not null.

Under this java.util.Map(an interface) will come which isn't a chile of java.util.Collection Interface and it is a parent interface for key value pair of collections.In other word  all other classes/interfaces capable to store key and value will come under Map interface.

Package Hierarchy for Java Collection Framework
Package Hierarchy for Java Collection Framework

 

How to store and retrieve from Collection.

 To store element in a collection several predefined method are there and it depends upon which collection you are using. In case of set and list add() method  whereas in case of map put() method.

Similarly to retrieve element we have get(int index) method for value pair and get(Object key) for key value pair.But using this mechanism you can retrieve a specific element you can't retrieve all the element.To retrieving all element  you have to user following ways.

In general there are 4 different way to retrieving elements form collections
  • For-each loop.
  • Iterator interface.
  • ListIterator interface.
  • Enumeration interface.
  • For loop(not a wise solutions)

For-each loop :

For-each loop is live for loop which repeatedly executes a group of statement for each element of the collection.Unlike for loop you no need to give any interment or end limit.
Syntax:

for(Variable : Collection-object)
{
      Statement
}

Iterator interface:

Iterator is an interface that contains method to retrieve elements one bu one from a collection object.It has 3 method.
  • boolean hasNext() - This method returns true if the iterator has more elements.
  • element next()- This method returns the next element in the iterator.
  • void remove()- This method will remove the last element return by the iterator from the collection. 

ListIterator interface:

ListIterator is an interface that contains method to retrieve elements from a collection object both in forward and reverse direction.It has many method but below we listed few important methods
  • boolean hasNext() - This method returns true if the ListIterator has more elements while traversing in forward direction.
  • boolean hasPrevious() - This method returns true if the ListIterator has more elements while traversing in reverse direction.
  • element next()- This method returns the next element in the iterator.
  • element previous()- This method returns the previous element in the iterator.
  • void remove()- This method will remove the last element return by the next or  previous method .

Enumeration interface:

The functionality of this Enumeration interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.

It has two method
  • boolean hadMoreElements()- This method returns true if the iterator has more elements.
  • element nextElement()- This method returns the next element in the Enumeration.

 For loop:

For loop is as usual.

 

How to work with java.util.List. 

List is an interface which will allow you to store collection of value.The followings are list of classes which implements List.

Interface List<E>

E - the type of elements maintained by this List

All Known Superinterfaces:

Collection<E>, Iterable<E> 

All Known Implementing Classes:

AbstractList, AbstractSequentialList, ArrayList, AttributeList, CopyOnWriteArrayList, LinkedList, RoleList, RoleUnresolvedList, Stack, Vector.

Properties of List:

  • An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.
  • Unlike sets, lists typically allow duplicate elements. More formally, lists typically allow pairs of elements e1 and e2 such that e1.equals(e2), and they typically allow multiple null elements if they allow null elements at all.

An overview about different  methods of List:

The List interface provides following method to insert element/Object
  1. add(E e): Appends the specified element to the end of this list (optional operation).
  2. add(int index, E element): Inserts the specified element at the specified position in this list (optional operation).
  3. addAll(Collection<? extends E> c): Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).
  4. addAll(int index, Collection<? extends E> c): Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
The List interface provides following methods to access  list elements
  1. get(int index): Returns the element at the specified position in this list.
  2. iterator(): Returns an iterator over the elements in this list in proper sequence.
  3. listIterator(): Returns a list iterator over the elements in this list (in proper sequence).
The List interface provides two methods to search for a specified object.
  1.  indexOf(Object o):Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
  2. lastIndexOf(Object o): Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
 The List interface provides following method to remove element/Object
  1. remove(int index): Removes the element at the specified position in this list (optional operation).
  2. remove(Object o):Removes the first occurrence of the specified element from this list, if it is present (optional operation).
  3. removeAll(Collection<?> c):Removes from this list all of its elements that are contained in the specified collection (optional operation).
  4. retainAll(Collection<?> c)Retains only the elements in this list that are contained in the specified collection (optional operation).
Other Methods.
  1. isEmpty(): Returns true if this list contains no elements.
  2. contains(Object o): Returns true if this list contains the specified element.
  3. clear(): Removes all of the elements from this list (optional operation).
  4. size(): Returns the number of elements in this list.

Examples:

Source code: http://ideone.com/cgNBex
List Demo
How to use List
 Source code: http://ideone.com/p0uGMk
Common operation on List
Common Operation With List

 

How to work with java.util.Set.

Set is an interface which is allowing to store collection of unique value. The followings are list of classes which implements Set

General deceleration: Interface Set<E>
E - the type of elements maintained by this set 

All Known Subinterfaces: NavigableSet<E>, SortedSet<E>

All Known Superinterfaces: Collection<E>, Iterable<E>

All Known Implementing Classes: AbstractSet, ConcurrentSkipListSet, CopyOnWriteArraySet, EnumSet, HashSet, JobStateReasons, LinkedHashSet, TreeSet

Properties of Set:

  • A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.
  • Some set implementations have restrictions on the elements that they may contain. For example, some implementations prohibit null elements, and some have restrictions on the types of their elements. 

An overview about different  methods of Set:

The Set interface provides following method to insert element/Object
  1. add(E e): Adds the specified element to this set if it is not already present (optional operation).
  2. addAll(Collection<? extends E> c): Adds all of the elements in the specified collection to this set if they're not already present (optional operation).
  3.  
The Set interface provides following methods to access  list elements
  1. iterator(): Returns an iterator over the elements in this set. 
The Set interface provides following method to remove element/Object
  1. remove(Object o): Removes the specified element from this set if it is present (optional operation).
  2. removeAll(Collection<?> c): Removes from this set all of its elements that are contained in the specified collection (optional operation).
Other Methods.
  1.  retainAll(Collection<?> c):Retains only the elements in this set that are contained in the specified collection (optional operation).
  2. size(): Returns the number of elements in this set (its cardinality).
  3. clear(): Removes all of the elements from this set (optional operation).
  4. contains(Object o): Returns true if this set contains the specified element.
  5. isEmpty(): Returns true if this set contains no elements.

Examples:

How to use Set
How to use Set
Common operation on Set
Common operation on Set

 

How to work with java.util.Map. 

Map is an interface which will allow us to store in key and value pair.The followings are list of classes which implements Map.
General deceleration: public interface Map<K,V>
K - the type of keys maintained by this map.
V - the type of mapped values .

All Known Subinterfaces: Bindings, ConcurrentMap<K,V>, ConcurrentNavigableMap<K,V>, LogicalMessageContext, MessageContext, NavigableMap<K,V>, SOAPMessageContext, SortedMap<K,V>

All Known Implementing Classes: AbstractMap, Attributes, AuthProvider, ConcurrentHashMap, ConcurrentSkipListMap, EnumMap, HashMap, Hashtable, IdentityHashMap, LinkedHashMap, PrinterStateReasons, Properties, Provider, RenderingHints, SimpleBindings, TabularDataSupport, TreeMap, UIDefaults, WeakHashMap 

Properties of Map:

  • Map is an collection object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
  • This interface takes the place of the Dictionary class, which was a totally abstract class rather than an interface.
  • The Map interface provides three collection views, which allow a map's contents to be viewed as a set of keys, collection of values, or set of key-value mappings.
  • The order of a map is defined as the order in which the iterators on the map's collection views return their elements. Some map implementations, like the TreeMap class, make specific guarantees as to their order; others, like the HashMap class, do not.
  • Some map implementations have restrictions on the keys and values they may contain. For example, some implementations prohibit null keys and values, and some have restrictions on the types of their keys.

An overview about different  methods of Map:

 The Map interface provides following method to insert element/Object
  1. put(K key, V value): Associates the specified value with the specified key in this map (optional operation).
  2. putAll(Map<? extends K,? extends V> m): Copies all of the mappings from the specified map to this map (optional operation).
The Set interface provides following methods to access  list elements
  1. entrySet(): Returns a Set view of the mappings contained in this map.
  2. keySet(): Returns a Set view of the keys contained in this map.
  3. values(): Returns a Collection view of the values contained in this map.
 The Set interface provides following method to remove element/Object
  1. remove(Object key)Removes the mapping for a key from this map if it is present (optional operation).
 Other Methods:
  1. containsKey(Object key): Returns true if this map contains a mapping for the specified key.
  2. containsValue(Object value): Returns true if this map maps one or more keys to the specified value.
  3. isEmpty(): Returns true if this map contains no key-value mappings.
  4. int    size(): Returns the number of key-value mappings in this map.

Examples:

Different way of iterating a Map
Different way of iterating a Map
Common Operation With Map
Common Operation With Map

 

Which collection is the best for your Requirement. 

 

What to use when
What to use when

Assignment for you!!!(Comment Your Answers)

  1. Why do we need iterator, ListIterator,  Enumeration even though for loop is there. We can user add() remove() etc to do all common operation with collections?
  2. How does the following two line differs:                                                                                  >>ArrayList<String> bird = new ArrayList<String>();
            >>List<String>  bird  = new ArrayList<String>();
  3. What is the new feature added in JDK 1.7 w.r.t collection deceleration and initialization.
  4. How to  get a specific element form a Set e.g in case of  List we are using get(...)?
  5. Why Set doesn't have any method to get the element by index?
  6. Is it possible to use listIterator w.r.t Set. yes or no answer with reason?
  7. How ArralyList is differs from Vector?
  8. How HashMap is differs from HashTable.

 

Reference:

 

Saturday 19 January 2013

CRM Terminology


Are you searching for  getting few domain knowledge about CRM?
If yes then this is the right blog you choose, hope you will like it.

==========================================================


what exactly CRM is?

  • CRM is nothing but customer relationship management basically by sales department of the Organisation in order to do business for maximising the benefit
  • And CRM software are the application software which helps to automate the sales department work. 
Examples:


Customer:

  • Customer is a person or organisation that buys goods or services from a store or other business.
  • CRM system will help to maintain the relationship with customer in order to maximise your benefits by automating maximum sales flow

Leads:

  • Leads are the individual or representative of organisation who shows interest in your product or services
  • Or in other word leads are the potential customers self registered online.

Deals:

  • Deals are the qualified/selected customer contacted by the sales team.
  • by the way the dictionary mining of deal is "An agreement entered into by two or more parties for their mutual benefit, esp. in a business or political context."

Opportunity/Potentials:

  • Opportunities are the hot Leads from where the Organisation can get more revenue by converting them into Deals.
  • Or you can say Opportunities are the sales and pending deals that you want to track; may be for making deal with them.
  • Potentials are the business deals with organisation or peoples that generates revenue for your  organisation.

Cases:

  • Cases are the feedback that are received from the customer on various issue by using your product or services.

Activities:

  • Activities are the process to keep track of business interaction including task(eg. phone call or email)  and calendar events (eg presentation or business meetings).

Task:

  • Task is an activity which is having due date.

Events:

  • Event is an activity which is having start and end time.

Contacts:

  • Contacts are the peoples in the company with whom you communicate and interact in pursuit of a business.

Accounts:

  • Accounts are companies or department in a company, with which you make business dealings.

Forecasts:

  • Forecasts are nothing but the predict and plan your sales cycle from pipeline to close sales and manage sales expectation  throughout your organisation

Campaigns:

  • A campaigns is a marketing effort to increase  the sales through planned, executed, distributed and analysed marketing activity.
  • The Goal of the effort is to often generate new Leads and help converting them to Deal.
  • A campaigns may have other goal like to awareness and brand to the company.
  • A CRM system can help for manage, execute and monitor marketing campaigns.

Products:

  • A product is a business offering form a business to it’s customer.
  • A CRM system should allows a business to record it’s product and related information so sales staff and other CRM users can use product information fully and correctly in their business activity.

Vendors:

  • Vendors are the companies, individuals or contractors from whom your organisation gets products/services.

Invoice:

  • Invoice are the bills generated by the vendor along with the goods/services with the purpose of procuring payments.
  • Or in a more general way you can say a commercial document issued by a seller to the buyer

Purchase Order:

  • Purchase Orders are legally bound order-placing documents for procuring products or services from vendors.

Price Book:

  • Price Books are the agreed price for selling a product to a customer. Based on the agreed terms, the prices can even vary for different customers.

Skype Me™!

Wednesday 24 October 2012

Develop cool apps in Facebook

Overview:

Stop using others app on Facebook!!! This is the right time to develop your own app in Facebook, "the largest social networking media" so that others can get service from  your app as till  now you are getting it from other developers.
Facebook give the facility to take the data by user permission so that the developers can use it for their app development.
From Facebook you can access data like your birthday,your email id,you and yours friends education detail,you and yours friends work history ,your and yours friends status and photo updates and so on..(Click hear for Details).
After receiving the data from user, you can use any computer programming language to develop the app viz java. php, cpp,.Net etc.

Here i get only basic permission details, for more browse on Facebook Developer  page.You can get like button you can also get post and feeds automatically.check it out for more....

Supporting Example:

1> Recruitment:
 >>Last time i visited to vmware careers.Actually i was interested for one of the job post. so when i click apply now they redirect me towards Facebook.What they are doing is, they are tracking all the details like your email,name,dob,Education details,Work history from  Facebook account and maintaining in their own data store.If you are looking suitable for that job then  you will get a mail from their automated system.you can do it by using java mail api in-case of java or any other api in other platform.
>>Similarly i experience  the same with ZOHO career and approximately all mnc and mulit port companies are collecting data from Facebook(first one is Linked in) for their hiring process as you know Facebook is the largest social networking media.
2>Utility/security
For example to check whether all  posted link are trusted or not Norton security develop one facebook app.It will scan all link posted by your friends and detect the status etc
3>Shopping(AmeriCommerce Store)
4>Advertising(Facebook advertise )
6>Sex and Romance etc
To know more about category of app that you can develop go to

How to Prepare yourself for developing your own app:

1.You have to strong in one or  more programming language
2.You have to get one Idea on which domain exactly you want to develop your app
3.You have to have knowledge of parsing and preparing the json .

Put your First Step:

1. Register your self in Facebook Developer page with your existing credential.

2.Verify your account by using your mobile number(100% confidential)

3.click on create app(Here)

4.As soon you click on create app one pop-up will come, which will ask  App name that you wanted to     develop and App namespace which is optional one

5.Important!!!Decide on which server you will host your application, if you don't have plan then check the web Hosting box.
with this hosting server you can deploy only php, Ruby, Python, Node.js etc.If you are planning to develop your app in any other language like java,.Net,cpp etc then choose your own hosting server viz Cloud computing environment.In my case i use Google cloud.
6.Note down the app id,App secrete which you will use it on your app development


Getting start with my application:

In order to complete the blog i display user details from basic permissions only infect you can use more by following the above guide line.

Basically i did it by using java(spring, jsp, GAE, json, oauth protocol).
i use spring-mvc and for injection dependency you can use ioc.
in my app total 4 files are there;-
   1.BasicFacebookApp.java(I implimanted my business logic hear using Spring-mvc)
   2.UserDetails.java(it is one of the data transfer object you can say a pojo)
   3.userdetails.jsp(for displaying the details)
   4.welcome.jsp(user will get it in first hit)


Explanation and Details:

Here i just present few line of code snippet from my application but not the total application,So try to customize it according to you r requirement.
By using this example code you can fetch your details like mail,dob, first name, last name etc

step-1:redirect to Facebook using following URL
url=https://www.facebook.com/dialog/oauth/?" +
"client_id=copy your app id&" +
"redirect_uri=copy your redirect uri&" +
"response_type=code&" +
"state=litu101&"+
"scope=mention details permission separated with ,

Stpe-2:Get the code send by facebook as a query string
Step-3:By using the code send the url to get access_token
String url_For_AccesToken= "https://graph.facebook.com/oauth/access_token?client_id=COPY THE APP ID&" +
            "redirect_uri=http://facebookoauthforbasicinformati.appspot.com/gettingCode&" +
            "client_secret=COPY THE APP SECRATE&" +
            "code="+code;
Step-4: Exchange  the access_Token  to access Graph-api which will return the required details in the form of  json. For this you have to prepare one URL and send it to Facebook server with access_token
To prepare the URL refer to Graph API Explorer
Step-5: Parse the json using json parser 

BasicFacebookApp.java
======================================
package com.acti.controller;

import ...;

@Controller
public class BasicFacebookApp {
//this is hte welcome file
@RequestMapping(value="/", method=RequestMethod.GET)
public String homeController(){
return "welcome";
}
//Step-1
//this is the rediracted uri if user will allow then it will access data otherwise not
@RequestMapping(value="/sendfb",method=RequestMethod.GET)
public void rediredttoFacebook(HttpServletRequest request,HttpServletResponse response) throws IOException{
HttpSession session=request.getSession(true);
String redirest_Facebool="https://www.facebook.com/dialog/oauth/?" +
"client_id=copy your app id&" +
"redirect_uri=copy your redirect uri&" +
"response_type=code&" +
"state=litu101&"+
"scope=mention details permission separated with ,";
response.sendRedirect(redirest_Facebool);
}
//callback functionality
@RequestMapping(value="/gettingCode",method=RequestMethod.GET)
public String postProcessingfb(HttpServletRequest request){
HttpSession session=request.getSession(false);
if(session!=null){
UserDetails user=new UserDetails();
//step-2
String fb_code=request.getParameter("code");
String accessToken="";
System.out.println("code::"+fb_code);
//http://facebookoauthforbasicinformati.appspot.com
//http://localhost:8888/gettingCode
try {
//step-3
        String inputLine;
        String url_For_AccesToken= "https://graph.facebook.com/oauth/access_token?client_id=COPY THE APP ID&" +
            "redirect_uri=http://facebookoauthforbasicinformati.appspot.com/gettingCode&" +
            "client_secret=COPY THE APP SECRATE&" +
            "code="+fb_code;
            URL url=new URL(url_For_AccesToken);
            HttpURLConnection connection=(HttpURLConnection)url.openConnection();
            BufferedReader bufferReader=new BufferedReader(new InputStreamReader(connection.getInputStream()));
            StringBuffer stringBuffer=new StringBuffer();
            while ((inputLine=bufferReader.readLine())!=null)
            stringBuffer=stringBuffer.append(inputLine+"\n");
            bufferReader.close();
            accessToken=stringBuffer.toString();
        }catch (Exception token_Exception) {
// TODO: handle exception
        //your reeor handling code
}
        System.out.println("acces token::"+accessToken);
//step-4
        String graph = "";
        try{
        String graph_Inputline;
        String graph_requestURL="https://graph.facebook.com/me?fields=id,name,link,gender,first_name,last_name,username,locale&"+accessToken;
        URL graph_URL=new URL(graph_requestURL);
        URLConnection graph_urlConnection=graph_URL.openConnection();
        BufferedReader graph_bufferReader=new BufferedReader(new InputStreamReader(graph_urlConnection.getInputStream()));
            //StringBuffer graph_stringBuffer=new StringBuffer();
        String graph_stringBuffer = "";
            while ((graph_Inputline = graph_bufferReader.readLine()) != null)
                //graph_stringBuffer.append(graph_Inputline + "\n");
            graph+=graph_Inputline;
            graph_bufferReader.close();
            //graph=graph_bufferReader.toString();
        }catch (Exception graph_Exception) {
// TODO: handle exception
        your erroe handling code
}
        System.out.println("json::"+graph);
//step-5:
        //prese the json
        try{
        JSONObject json=new JSONObject(graph);
        user.setId(json.getString("id"));
       
        user.setName(json.getString("name"));
       
        user.setLink(json.getString("link"));
       
        user.setGender(json.getString("gender"));
       
        user.setFirst_name(json.getString("first_name"));
       
        user.setLast_name(json.getString("last_name"));
       
        user.setUsername(json.getString("username"));
       
        user.setLocale(json.getString("locale"));
       
        session.setAttribute("user",user);
        return "userdetails";
       
        }catch (Exception e) {
// TODO: handle exception
        //your own error handling code
}
}
return null;
}
}

======================================

.UserDetails.java
===========================
package com.acti.dto;

import java.io.Serializable;

@SuppressWarnings("serial")
public class UserDetails implements Serializable{
private String id;
private String name;
private String first_name;
private String last_name;
private String link;
private String username;
private String gender;
private String locale;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
}

===========================

userdetails.jsp
==========================
<%@ page language="java" import="com.adaptavant.dto.UserDetails;" session="true" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="user" class="com.adaptavant.dto.UserDetails" scope="session"/>
 <table border="0"  cellpadding="0" cellspacing="0" 
height="40%" width="40%">
          <tr>
             <td><FONT SIZE="4" COLOR="#333399">We fetch the Following Information from FaceBook</FONT><BR></td>
          </tr>
          <tr>
             <td><B>Name:</B></td>
             <td> <%=user.getName() %></td>
          </tr>
          <tr>
             <td><B>FirstName</B></td>
             <td> <%=user.getFirst_name()%></td>
          </tr>
          <tr>
             <td><B>LastName</B></td>
             <td> <%=user.getLast_name() %></td>
          </tr>
          <tr>
             <td><B>Id</B></td>
             <td><%=user.getId()%></td>
          </tr>
           <tr>
             <td><B>Location</B></td>
             <td> <%=user.getLocale()%></td>
          </tr>
           
           
           <tr>
             <td><B>Click To view</B></td>
             <td><a href="<%=user.getLink()%>">Click</a></td>
          </tr>
           <tr>
             <td><B>Gender</B></td>
             <td><%=user.getGender()%></td>
          </tr>
          
</table>
</body>
</html>
==========================

Welcome.jsp
==============================
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<style type="text/css">
div#body1{
position:absolute;
top:400px;
left:600px;
}

</style>
</head>
<body>
<div id="header1">
<font " size="4" style="top: 351px;left: 452px;position: absolute; color:rgb(16, 65, 168);">Click Below Image to Fetch details from Facebook account</font>
<div id="body1">
<a href="/sendfb"><img src="http://commondatastorage.googleapis.com/conversionsupportimages/cswebsiteimages/facebook.gif"></a>
</div>
</div>
</body>
</html>
=============================


Finally i would like to thank you for your patience.if you like this then don't forgot  to post comment,complement or suggestion which will inspire me for further posting.



















Skype Me™!