java - How to install the JDK on Ubuntu Linux - Stack Overflow
Java compiler in Ubuntu for Windows
I want to know if there is a way to add the compiler that I downloaded from apt-get to the Windows path
There isn't. If your windows based editing environment requires you to have a java compiler installed then you need to install a compiler on windows. It's one of the major annoyances of wsl programming.
That said, I probably wouldn't use wsl at all for java programming. It's one of the few languages that doesn't feel annoying to program on windows at all. It has great windows tooling and build scripts.
More on reddit.comCan someone please guide me through the installation of JDK on Linux?
If it's based on Ubuntu you'll be able to install it via the package manager.
Go to your shell and type
sudo apt-get install openjdk-8-jdk
This will install OpenJDK, not Oracle JDK. For the Oracle JDK you need to add a PPA first:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
How do i install Java on Xubuntu?
Videos
To compile the file, open your terminal and type
javac filename.java
To run the generated class file, use
java filename
But to do this you need to have the Java JDK installed in your computer. You can install it with the instructions in How do I install Java?.
OpenJDK works best for me. It's simple and I have never faced any problem with it. Just follow these simple steps:
From Terminal install open jdk
sudo apt-get install openjdk-7-jdkWrite a java program and save the file as filename.java
Now to compile use this command from the terminal
javac filename.javaIf everything works well then a new "filename.class" file should be created.
To run your program that you've just compiled type the command below in terminal:
java filename
NOTE
You can use any text editor (like gedit) ,
replace the filename with watever name you want
you need to be on same directory as the "present working directory" (got by running pwd) while running the command from terminal.
Referring to Ask Ubuntu question How to set JAVA_HOME for OpenJDK?,
How to install Open JDK (Java developement kit) in Ubuntu (Linux)?
Open Terminal from Application Dash or press Ctrl+Alt+T
Update repository:
sudo add-apt-repository ppa:openjdk-r/ppa # only Ubuntu 17.4 and earlier sudo apt updateOptional: To search available distributions of
openjdk, use the following command:apt search openjdkInstall the appropriate version with the following command:
sudo apt install openjdk-8-jdk sudo apt install openjdk-8-source #this is optional, the jdk source codeFor
JAVA_HOME(Environment Variable) type command as shown below, in "Terminal" using your installation path...export JAVA_HOME=/usr/lib/jvm/java-8-openjdk(Note:
/usr/lib/jvm/java-8-openjdkis symbolically used here just for demostration. You should use your path as per your installation.)For
PATH(Environment Variable) type command as shown below, inTerminal:export PATH=$PATH:$JAVA_HOME/binTo check your installation:
java -version
The following used to work before the Oracle Java license changes in early 2019.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
The PPA is discontinued, until the author finds a workaround for the license issues.