The Answer
You can update Java by downloading the newer version from Oracle directly When you install the installer would delete the older version for you.
The OLD Answer (no longer works)
Or you Mac has built in system that would fetch and update java from Oracle for you for you. Go to System Preference > Java > Update > Update Now. It would also be a good idea to turn on "Check for Updates Automatically" that way when a newer version of Java comes out your Mac would ask you to install it and it becomes a simple one click install.

How to update my installed Java version? The “install now” button doesn’t do anything.
I ported Mac OS X to the Nintendo Wii
How update Java 11? - Apple Community
macos - Java Update not working on Macbook - Ask Different
Videos
The Answer
You can update Java by downloading the newer version from Oracle directly When you install the installer would delete the older version for you.
The OLD Answer (no longer works)
Or you Mac has built in system that would fetch and update java from Oracle for you for you. Go to System Preference > Java > Update > Update Now. It would also be a good idea to turn on "Check for Updates Automatically" that way when a newer version of Java comes out your Mac would ask you to install it and it becomes a simple one click install.

Just go to the java page and download the latest version. Upon starting the installation process, the installer automatically detects your current java version, either deletes it and does a complete reinstall or just updates your version.
This is the latest for Mac OS 10.6.x
http://support.apple.com/kb/dl972
Or, for Mac OS 10.5.x
http://support.apple.com/downloads/Java_for_Mac_OS_X_10_5_Update_7
To download/update Java for different versions of Mac OS X you will need to go to Apple’s Developer Connection site for Java.
Apple's Developer Connection Site
Apple stopped supplying Java after Java 6. The Java control Panel was used to control Apple's Java releases and so does not provide later updates.
To get Java 8 you need to install from Oracle's Java pages. Note that the licence for these might involve some restrictions.
For later Java versions there are several other sources e.g. OpenJDK Azul
An easier way to install these versions might be to use a package manager like HomeBrew(although only for the most recent MacOS versions) or Macports.
There were an issue with the Update feature for your verion. Manually updating to a newer version will fix it.
I had the same problem fixed based on the advice in the article below. The update now work again.
"This article applies specifically to Oracle JRE 8u331 through 8u351 on macOS. Note that Oracle JDK 8 does not provide auto-update and thus this notice does not apply. Some users who installed Oracle JRE 8 on macOS (on any hardware platform) may experience issues with the Java auto-update feature. This affects Java versions 8u331 through 8u351 (April 19, 2022 through January 16, 2023)."
ref: https://www.java.com/en/download/help/java8_manual_update_macos.html
