The documentation of the DateFormat#parse() method clearly says that the complete input
string might not be processed. So, from your "input" string only, "01.01.1" portion is parsed, and since it satisfies the
pattern - "dd.MM.yyyy", it will not give you "null".
If you want to return "null" from the method, if the date is not valid as per the pattern, then you can check the index of the ParsePosition. If it is at the end, then it has parsed complete string, and hence date is valid, else date is invalid, and return null:
Some Points:
I've changed the return type of method to "Date", as it's better to return the parsed date from the method, rather than printing it there only.Also, it's better to pass the "input" and "pattern" string as argument to this method. That way, you can re-use this method.Also, I would rather throw an exception, in case of invalid date, rather than returning "null".And, the method is better named as "parseDate" than "dateParse".