Posted in ASP .Net, C#, Core Java, Design Pattern, Framework, Inversion of Control, Java EE, Library

Library vs Framework

The key difference between Library and Framework is in IoC (Inversion of Control)

  • by using a feature from a Library you are in control.
  • The Framework include some abstract design with built-in behaviors. Control is inverted and the framework calls you; framework code will call the code at those various points that behavior has inserted. The Hollywood principle: Don’t call Us, we’ll call You.



A certain set of reusable functions of an application (mostly organized into classes) As a skeleton of an application
A collection of class definitions A collection of patterns
You call the library APIs in your code A framework calls your code
The control is always with you The control in with the framework if you’re using it
Libraries meant to do some specific tasks only Framework is a predefined design
You need to scaffold your project manually Super easy to scaffold




Posted in Core Java, Groovy, Java EE

Groovy vs Java

  Java Groovy
Access modifier (by default) package public
getters and setters Need to provide for fields Are automatically generated for class members
Utility methods System.out.println println
Support substitution   Can print dynamic content without string concatation

Println(“Hello $name !”)


Specifying type definition   Instead use keyword def

Mandatory for methods, optional for method arguments

Using semicolons Every statements end with semicolon optional
main method To make a class executable Don’t need
Initializing String arrays, static arrays Curly braces { “abc”, “dfg”} Square brackets [“abc”, “dfg”]
autoboxing/unboxing/conversion of primitives yes No, everything is Object and uses only Objects
Inner static classes yes no
Anonymous classes yes no
Posted in Core Java, Object Oriented Programming


A class, interface or method that declares one or more type variables (type parameters).


  • Type-Casting
  • Type-Safety (single type of objects)
  • compile-time checking

public Class Box{                                     ——–>              public Class Box<T>{

private Object obj;                                                                              private T t;

public void set (Object obj){                                                             public void set(T t){

this.obj=obj;                                                                                          this.t=t;

}                                                                                                        }

public Object get(){                                                                               public T get(){

return obj;                                                                                              return t;

}                                                                                                           }

}                                                                                                          }

Posted in Core Java, Design Pattern, Object Oriented Programming

Singleton Pattern

A Singletone class;

Only one time in JVM per class loader would be instantiated. Same instance would be use for repeated calls.

public class OnlyOne {

            private static OnlyOne one = new OnlyOne();

            // private constructor, so this class cannot be instantiated from outside and prevents


private OnlyOne();

//a global point of access

public static OnlyOne getInstance() {

            return one;



To use it:

OnlyOne myOne = OnlyOne.getInstance();


Posted in Core Java, Object Oriented Programming

String vs StringBuffer == and .equals methods

  str1==str2 str1.equals(str2)
String Compares Objs location Compares Objs String contents
StringBuffer, StringBuilder Compares Objs location If and only if str1==str2 would be True.


So if we need to compare or sort in StringBuffer / StringBuilder we need to turn them into String first. For example:

if (str1.ToString() = str2.ToString())   {


}   else   {




Posted in Core Java

Java – Abstract class vs Interface


Abstract class


Have abstract & non-abstract methods Only abstract methods
Not support multiple inheritance Supports multiple inheritance
Can have final/non-final/statis/non-static variables Only final & static variables
Can have:

·         static methods

·         main method

·         constructor

Cannot have




Can provide implementation of interface Cannot provide implementation of abstract class
When we want to add new methods When we want to have multiple inheritance
We extend it We implement it