An easy way
Install OpenJDK with:
sudo apt install default-jre
Enter in the terminal:
sudo nano /usr/share/applications/java.desktop
Copy the following content:
[Desktop Entry]
Encoding=UTF-8
Name=Java
Comment=Java Virtual Machine
Exec=java -jar
Icon=java
Terminal=false
Type=Application
NoDisplay=true
Categories=Applications;
MimeType=application/x-java-archive;application/x-jar;
Note: Don't worry about putting the full path of java in the exec= line as it is not necessary since the system detects it automatically.
and paste it into nano using "Ctrl + V", then press Ctrl + O (Control and O at the same time) to save the changes, nano will ask for confirmation of the file name, press Enter to confirm writing to the file: /usr/share/applications/java.desktop and press ENTER. Then press Ctrl + X (Control and X at the same time) to exit the nano editor.
Papirus icon theme
Additionally, I need to use the icon theme:
Papirus
https://github.com/PapirusDevelopmentTeam/papirus-icon-theme
Install and use it
This theme has Java icons in:
/usr/share/icons/Papirus/16x16/apps/java.svg
/usr/share/icons/Papirus/16x16/apps/java.svg
/usr/share/icons/Papirus/22x22/apps/java.svg
/usr/share/icons/Papirus/24x24/apps/java.svg
/usr/share/icons/Papirus/32x32/apps/java.svg
/usr/share/icons/Papirus/48x48/apps/java.svg
/usr/share/icons/Papirus/64x64/apps/java.svg
That's why in the java.desktop file, the Icon= line has java. This will enable right-click functionality in file managers.