Example java code for Patterns