public static boolean isJavaIdentifier(final String str){
  if (str == null || str.length() < 1) {
    return false;
  }
  if (!Character.isJavaIdentifierStart(str.charAt(0))) {
    return false;
  }
  for (int i=1; i < str.length(); i++) {
    if (!Character.isJavaIdentifierPart(str.charAt(i))) {
      return false;
    }
  }
  return true;
}

public static boolean isJavaIdentifier ( final String str ) { if ( str == null || str . length ( ) < 1 ) { return false ; } if ( ! Character . isJavaIdentifierStart ( str . charAt ( 0 ) ) ) { return false ; } for ( int i = 1 ; i < str . length ( ) ; i ++ ) { if ( ! Character . isJavaIdentifierPart ( str . charAt ( i ) ) ) { return false ; } } return true ; }
check if a string is a valid java identifier . spaces are not allowed fore or aft .
