public final static boolean isValidJavaIdentifier(String s){
  if (s == null || s.length() == 0) {
    return false;
  }
  char[] c=s.toCharArray();
  if (!Character.isJavaIdentifierStart(c[0])) {
    return false;
  }
  for (int i=1; i < c.length; i++) {
    if (!Character.isJavaIdentifierPart(c[i])) {
      return false;
    }
  }
  return true;
}

public final static boolean isValidJavaIdentifier ( String s ) { if ( s == null || s . length ( ) == 0 ) { return false ; } char [ ] c = s . toCharArray ( ) ; if ( ! Character . isJavaIdentifierStart ( c [ 0 ] ) ) { return false ; } for ( int i = 1 ; i < c . length ; i ++ ) { if ( ! Character . isJavaIdentifierPart ( c [ i ] ) ) { return false ; } } return true ; }
check whether the given string is a valid identifier according to the java language specifications . see the java language specification second edition , section 3 . 8 for the definition of what is a valid identifier .
