I was asked to figure out how to reinstall Java on a Mac without reinstalling the OS. Apparantly the user was complaining that Java would not work in Safari and, while trying to fix the problem, the Help Desk deleted enough required files that Java was completely trashed. Here's what I did to completely reinstall it:
Download (from Apple's Support Downloads page) but do not install the latest Combo Update for OS X, as well as all of the JavaForMacOSX10.5s you see there. (I used Updates 1, 2, adn 3, even though 1 was not a prerequisite for 2). Save these files in an accessible place -- you'll use them later.
Next, make sure you have the latest-available shrink wrap version of OS X (it was 10.5.6 when I did this). Now, after this next step, you will be beyond the point of no return...
Delete /Library/Java, /Library/Internet Plug-ins/JavaPluginCocoa.bundle, /System/Library/Java, /System/Library/Frameworks/Java/* and your user's Library/Caches/Java folder (not sure whether this mattered). You may have to use Terminal and sudo to delete the folders in /Library and /System.
Open Terminal and run sudo pkgutil --packages. With the results from the above command, use the pkgutil --forget command to "forget" about all of the Java packages in the list. I used forget the following com.apple.pkg packages: Java, JavaSE6, JavaToolsLeo, JavaUpdateForMacOS10.5Update2, and JavaUpdateForMacOS10.5Update3. So each command looked like this: sudo pkgutil --forget com.apple.pkg.Java.
Next, insert the Leopard disk and run the following in Terminal to reinstall Java:
$ installer -verbose -pkg "/Volumes/Mac OS X Install Disk/System/Installation/Packages/Java.pkg -target /Volumes/Macintosh HD"
$ installer -verbose -pkg "/Volumes/Mac OS X Install Disk/System/Installation/Packages/JavaTools.pkg -target /Volumes/Macintosh HD"[robg adds: There's an earlier hint here that discusses a simpler fix, but one that probably won't work for this problem (deleted files). If there are easier ways to reinstall Java from scratch, please post in the comments.]

