If you have multiple versions of java running on your machine and wanted to use specific version of java for appServer, then you can declare the JAVA_HOME variable and export the variable in the startup script (standalone.sh or domain.sh)
JAVA_HOME="path to java"
Does it mean everytime we upgrade the JDK version, we have to change the variable in the startup script under bin folder of Wildfly 11?
Do you mean we have to run the above in command prompt?
Declaration of variable is needed only when you have multiple versions of java installed and need to use specic version.
If you have only one version of java then updating environment variables should be enough.