Monthly Archives: April 2013

key board raise and hide in Android

// -key board raise–
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);

if (imm.isAcceptingText())
} else
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

// -key board hide–

How to inflate Layout and menu Xml ?

1)For Layout xml:
LayoutInflater layout=getLayoutInflater();
2)For Menu xml:
MenuInflater mxml=getMenuInflater();
mxml.inflate(, menu);

Autoboxing and Unboxing

The Autoboxing and Unboxing  was released with the Java 5.


During assignment, the automatic transformation of primitive  type(int, float, double etc.) into their object equivalents or wrapper type(Integer, Float, Double,etc) is known as Autoboxing.


Integer intObject = 5; // autoboxing


During assignment or calling of constructor, the automatic transformation of wrapper types into their primitive equivalent  is known as Unboxing.

int inative = 0;
inative = new Integer(5); // auto-unboxing

Autoboxing also works with comparison
int a = 10;
Integer b = 10;
System.out.println(a==b); // true

How to create read only List, Map and Set in Java

// creating List in Java
List<String>  names= new ArrayList<String>();

// initializing List in Java

Set<String> readOnlySet = new HashSet<String>(names);

 //Set is not yet read-only you can still add elements into Set
//making Set readonly in Java – no add remove or set operation permitted
readOnlySet = Collections.unmodifiableSet(readOnlySet);

//trying to add element in read only Set – java.lang.UnSupportedOperationException
readOnlySet.add(“You can not add element in read Only Set”);

//trying to remove element from read only set

//you can not remove elements from read only Set

Map<StringString> agesmap = new HashMap<StringString>();
agesmap.put(“raja”, “24”);

//Map is not read only yet, you can still add entries into
agesmap.put(“ramesh”, “22”);

System.out.println(“Map in Java before making read only: ” + contries);

//Making Map read only in Java
Map readOnlyMap = Collections.unmodifiableMap(agesmap);

//you can not put a new entry in read only Map in Java
readOnlyMap.put(“ra”, “33”); //java.lang.UnSupportedOperation 

//you can not remove keys from read only Map in Java
readOnlyMap.remove(“raja”); //java.lang.UnSupportedOperation

Why is Java not a pure OOP Language?

Java is a OOP language and it is not a pure Object Based Programming Language.

Many languages are Object Oriented. There are seven qualities to be satisfied for a programming language to be pure Object Oriented. They are:

  1. Encapsulation/Data Hiding
  2. Inheritance
  3. Polymorphism
  4. Abstraction
  5. All predefined types are objects
  6. All operations are performed by sending messages to objects
  7. All user defined types are objects.

Java is not because it supports Primitive datatype such as int, byte, long… etc, to be used, which are not objects.

Contrast with a pure OOP language like Smalltalk, where there are no primitive types, and boolean, int and methods are all objects.

%d bloggers like this: