Another O(log n) easy to understand solution using binary search:
public class Solution {
static int findClosest(int arr[], int n, int target)
{
int l=0, h=n-1, diff=Integer.MAX_VALUE, val=arr[0];
while(l<=h)
{
int mid=l+(h-l)/2;
if(Math.abs(target-arr[mid])