For Each loop in java 1.5

The for-each loop, or enhanced for loop, is new feature in JDK 1.5 to remove clutter and possible errors, in iterating over collections.This will not provide any new functionality .It is just making our code more easy.It allow to create one variable which will iterate over array or collection.By this we can do nested iteration.

JDK 5.0 provides a special kind of for loop for access through all the elements of it.

 
Syntax 

For(vaiable : collection){ Statements; } 
Example:

  int[] a={1,2,3,4,5,6,7,8,9,0};
Using for Each loop :-

  for(int i : a){
    System.out.println(i);</em>
  }  

using Simple for loop :-

for(Iterator itr = a.iterator(); i.hasNext(); ) {
  String item = i.next();
  System.out.println(item);one more example will clear you more on this.

Using Foreach with Arrays  :-

String[] letters = { "v", "i", "n" , "a" , "y" };
for (String letter: letters)
   System.out.println(letter.charAt(0));

Unexpected Null pointer exception in Oracle ADF

Recently I faced an issue in Adf application. The .jspx page giving null pointer exception after doing some operation in page. And every variable have contain their value. I have try to run application many time in debug mode to replicate the problem but not able to find. Then I find in ADF application when ever You make any Input or Output text in jspx. page it automatically make validator. af:validator is automatically generated when you create a form component. You can check that validator by clicking the Source button. Solution of the problem is – to comment the validator part in xml part.
You will find error in ADF class like this.

java.lang.NullPointerException
at oracle.jbo.uicli.binding.JUCtrlValueBinding.validateAttributeValue(JUCtrlValueBinding.java:757)

For Solution you should go to seach option and Search for af:validator in full application.Where you can find this tag. Make it comment like example I have given below.

null1

After applying the solution application doesn’t give Null pointer exception

Autoboxing In java

Automatic conversion of primitive types and their corresponding object wrapper classes (eg, int and Integer, double and Double, etc).
Autoboxing is a new feature java 1.5 . It is a capability to convert or cast between object wrapper and it’s primitive type.it was necessary to wrap a primitive type to a Wrapper class before adding it to a collection i.e is called Boxing and to unwrap it back to the primitive when it came out of the collection i.e unboxing.

Auto-boxing and Auto-Unboxing enables the primitive types to be converted into respective wrapper objects and the other way around.
Before jdk 1.5 we need to manual boxing.We have to write tedious coding for that.

example-
Integer vinay();

int i = vinay();

Difference between autoboxing and Casting

Boxing – Boxing is when you use or make primitive type to a reference type
Casting – Casting is when you want one type to treated as another type, between primitive types and reference types