I have written below code using stanford nlp packages.
GenderAnnotator myGenderAnnotation = new GenderAnnotator();
myGenderAnnotation.annotate(annotation);
If your named entity recognizer outputs PERSON
for a token, you might use (or build if you don't have one) a gender classifier based on first names. As an example, see the Gender Identification section from the NLTK library tutorial pages. They use the following features:
Though, I have a hunch that using character n-gram frequency---possibly up to character trigrams---will give you pretty good results.