Add following dependency to your maven project or download jar and add to class path
<dependency>
<groupId>com.warrenstrange</groupId>
<artifactId>googleauth</artifactId>
<version>1.4.0</version>
</dependency>
then add follwoing code
GoogleAuthenticator gAuth = new GoogleAuthenticator();
var totpcode = String.valueOf(gAuth.getTotpPassword(totp_key));
pass this totpcode to method