If the words
have to be Java types
], as your usage sample suggests, there is no way around using a real parser that can parse the Java language. If the words can appear in any context you could go after them with regular expressions
] making sure that the words you are searching for are delimited by word boundary characters ("\b").
This site can help you build a Java parser as there are already samples for the complete Java grammar: http://www.antlr.org/
If you have any doubts or questions, feel free to leave a comment.