I found I had to do this because I was having difficulty installing JetBrains' WebStorm on Ubuntu. In fairness I'm an Ubuntu neophyte. My exposure to Linux is generally small tasks done in a terminal on servers.
Mistake: Just Installing Oracle Java
The first thing I tried to do was just install Oracle Java. This would complete, but I would still have the wrong version of Java when I typed java -version in Terminal. This confused me for hours. I googled, and googled, and found about 20 different solutions that didn't work. Finally ran into one answer that gave me a clue (I need to dig up the link, sorry). OpenJRE was gunking things up.
OpenJRE on Ubuntu
Ubuntu comes with OpenJRE stuff installed on it by default. I'm not at all sure what "OpenJRE" is or why it exists. It seems to be some sort of licensing issue deal were Oracle had a disagreement with Ubuntu and some weird new Java baby was born.
Either way, I want "real" Java, not whatever this is.... so let's get rid of it.
Answer: First remove OpenJRE, then install Oracle Java!
Here are the commands I ran to fix up Java on my machine. Annotated: