Please check the commented line

public class Insertionsort
{
public static void main(String[] args)
{
int[] array={88,77,66,55,44};
insertionsort(array);
display(array);
}
public static void insertionsort(int[] arr)
{
for(int counter=1;counter<arr.length-1;counter++)
{
int val=arr[counter];
int j=counter-1;
while(j>=0 && arr[j]>val) // while(arr[j]>val && j<=0) doesn’t work. Why is that so?
{
arr[j+1]=arr[j];
j–;
}
arr[j+1]=val;

    }
}
public static void display(int[] arr)
{
    System.out.println("sorted elements are ");
    for(int i=0;i<arr.length;i++)
    {
        System.out.println(arr[i]);
    }
}

}

Hey @jdkatti
just a changes for(int counter=1;counter<=arr.length-1;counter++) instead of for(int counter=1;counter<arr.length-1;counter++)
// while(arr[j]>val && j<=0) doesn’t work. Why is that so?
Answer :
In Case j is -1
you are checking arr [j] >val , you get array index out of bound exception
so, j>=0 It will come first
correct code :

public class Main {
public static void main(String[] args) {
int[] array = { 88, 77, 66, 55, 44 };
insertionsort(array);
display(array);
}

public static void insertionsort(int[] arr) {
	// outer arr.length-1 
	for (int counter = 1; counter <=arr.length - 1; counter++) {
		int val = arr[counter];
		int j = counter - 1;
		while (j >= 0 && arr[j] > val) {

// while(arr[j]>val && j<=0) doesn’t work. Why is that so?

			arr[j + 1] = arr[j];
			j--;
		}
		arr[j + 1] = val;
	}
}

public static void display(int[] arr) {
	System.out.println("sorted elements are ");
	for (int i = 0; i < arr.length; i++) {
		System.out.println(arr[i]);
	}
}

}

How to write the code for Hackerblock?

just open challenges ,
You can see the compiler,
Start writing code,
ya You can write code on eclipse and just copy past then click on submit button( Make sure Class name must be Main)