Starting from macOS Big Sur (ver. 11.2.3), macOS doesn’t include pre-installed Java any more, the best option is to install AdoptOpenJDK.

You can download the OpenJDK pkg binary and install it manually like here,

or install AdoptOpenJDK via brew in your favourite terminal:

brew install --cask adoptopenjdk

Hope it helps.