While working with regular expressions, you need quantifiers to specify the number of occurrences to match against. The 3 used quantifiers are ?, + and *.

? means 0 or 1 occurrence
+ means exactly one occurrence
* means 0 or more occurrences

Java Code:
String patternStr = "Java?"; // last a can have zero or 1 occurrence
String patternStr = "Java+"; // last a can have one or more occurrence
String patternStr = "Java*"; // last a can have zero or more occurrence