How to install JDK 11 under Ubuntu?

To install Openjdk 11 in Ubuntu, the following commands worked well.

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt install openjdk-11-jdk

sudo apt-get install openjdk-11-jdk

after this, try

java -version

to make sure java version is 1.11.x, if found old one or different, check below command to see the available jdks,

update-java-alternatives --list

you should see something like below,

java-1.11.0-openjdk-amd64      1111      /usr/lib/jvm/java-1.11.0-openjdk-amd64 

java-1.8.0-openjdk-amd64      1081      /usr/lib/jvm/java-1.8.0-openjdk-amd64

you can see java 1.11 available from above list, use below command to set java 11 to default,

sudo update-alternatives --config java

for above command, you will get something like below and also, will ask for an option to set,

There are 3 choices for the alternative java (providing /usr/bin/java).
   Selection    Path   Priority   Status

 ------------------------------------------------------------   

 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
  
 1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode

 *2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081    manual mode 

 3            /usr/lib/jvm/jdk1.8.0_211/bin/java  0         manual mode 

 Press <enter> to keep the current choice[*], or type selection number:

you can select desired selection number, my case it's 0

for javac,

sudo update-alternatives --config javac

will result something like below,

 There are 3 choices for the alternative javac (providing /usr/bin/javac).

 Selection    Path                     Priority  Status

 ------------------------------------------------------------   

 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/javac   1111      auto mode   

 1           /usr/lib/jvm/java-11-openjdk-amd64/bin/javac   1111      manual mode

 *2            /usr/lib/jvm/java-8-openjdk-amd64/bin/javac    1081      manual mode   
 3            /usr/lib/jvm/jdk1.8.0_211/bin/javac        0         manual mode
 
 Press <enter> to keep the current choice[*], or type selection number:

in my case, it's 0 again

after above steps, try

java -version

it will display something like below,

openjdk version "11.0.4" 2019-07-16 

OpenJDK Runtime Environment (build
 11.0.4+11-post-Ubuntu-1ubuntu218.04.3) 

 OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed > mode, sharing)

Now it is possible to install openjdk-11 this way:

sudo apt-get install openjdk-11-jdk

(Previously it installed openjdk-10, but not anymore)