Java code to test if a string is a valid java identifier.

public class IdentifierTest {
 
    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
        for(String arg : args) {
            boolean start = true;
            boolean validIdentifier = true;
            arg.toCharArray() 
            // commenter pointed out my error
            //for(byte b : arg.getBytes()) {
            for(char b : arg.toCharArray()) {
                if(start) {
                    validIdentifier = validIdentifier && Character.isJavaIdentifierStart(b);
                    start = false;
                } else {
                    validIdentifier = validIdentifier && Character.isJavaIdentifierPart(b);
                }
            }
            System.out.println("Identifier ""
            + arg + "" is "
            + (validIdentifier ? "" : "not ")
            + "valid");
        }
    }
}

Output:
>java IdentifierTest Test $ds ds$ 2" is not valid