public int firstOccurrence(int input[], int x){
        int low = 0;
        int high = input.length-1;
        
        while(low <= high){
            int middle = (low + high)/2;
            if(input[middle] == x && (middle == 0 || input[middle-1] < x)){
                return middle;
            }else if(input[middle] < x){
                low = middle+1;
            }else{
                high = middle-1;
            }
        }
        return -1;
    }
http://www.geeksforgeeks.org/check-for-majority-element-in-a-sorted-array/
src/com/interview/binarysearch/FirstOccurrenceOfNumberInSortedArray.java