Q:

updating variable values with the same name

Could someone please advise me if the below is correct?
I want to use the same variable in the private method isThisValid() for two different tasks. Will the below update the values as as I need them?
public boolean validateDate(String dateForValidation, String format) {
    this.dateFormat = format;
    this.dateToValidate = dateForValidation;
    isThisValid();
    if(isThisValid() == true)
    {
    return true;
    }
    else{
        throw new IllegalArgumentException(
                dateToValidate + "did not match expected" + dateFormat);
    }
}
public boolean validateTime(String TimeToValidate, String TimeFormat){
    this.dateFormat = TimeFormat;
    this.dateToValidate = TimeToValidate;
    isThisValid();
    if(isThisValid() == true)
    {
    return true;
    }
    else{
        throw new IllegalArgumentException(
                dateToValidate + "did not match expected" + dateFormat);
    }
}

private boolean isThisValid(){
    if (dateToValidate == null) {
        logger.info(dateToValidate + "was equal to null");
        return false;
    }
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
    sdf.setLenient(false);

    try {
        // if not valid, it will throw ParseException
        Date date = sdf.parse(dateToValidate);
        System.out.println(date);

    } catch (ParseException e) {
        logger.info(dateToValidate + "did not match expected" + dateFormat + "throw ParseException");
        logger.trace(
                dateToValidate + "did not match expected" + dateFormat + "so it was not valid, so throw ParseException");
        e.printStackTrace();
        return false;
    }

    return true;
}

Will this work?

A:

Will this work?

Maybe, under certain circumstances. It really depends upon what you are trying to do, which isn't clear in your question.
If it is invoked by multiple threads, it will do very strange and unpredictable things.
You generally don't want to be using mutable state like this: instead, pass the things that you need in isValid into isValid:
public boolean validateTime(String timeForValidation, String format) {
    if(isThisValid(timeForValidation, format) == true) {
      return true;
    }
    throw new IllegalArgumentException(...);
}

public boolean validateDate(String dateForValidation, String format) {
    if(isThisValid(dateForValidation, format) == true) {
      return true;
    }
    throw new IllegalArgumentException(...);
}

private boolean isThisValid(String timeToFormat, String timeFormat){
  // ...
}

The reason why it doesn't work in a multi-threaded environment is that one invocation of validateTime (or validateDate) doesn't necessarily complete before the next invocation occurs. The next invocation will stomp on the values of this.dateFormat and this.dateToValidate, meaning that the already-in-flight invocation will (may) start using the updated values from the second invocation, leading to unpredictable results.

