Want to learn Java programming on Linux?
Then this is the right article for you.
In this article, I will discuss the preparation of the tools used for Java programming on Linux.
Besides that, later we will try to make a simple program.
Ready…?
Let's start.
tools preparation
The tools that need to be prepared to learn Java programming on Linux are as follows:
1. Text Editor
Text editor is used to write code.
Also read:
Please use your favorite text editor.
2. JDK (Java Development Kit)
JDK or Java Development Kit is used for compiling, debugging(checking errors ), and running java programs.
In the JDK there are two things that need to be known:
- Compiler: Task to translate java code into bytecode ;
- Debugger : The task is to check for errors in the code.
On the Windows operating system, we can use JDK from Oracle. Whereas in Linux, we use openJDK.
The name of the openJDK package on Linux is openjdk . Use the facility
apt-cache search
to find out which openjdk is available on the repository server .petanikode@imajinasi:~$ apt-cache search openjdk
. . .
openjdk-7-jdk - OpenJDK Development Kit (JDK)
...
openjdk-6-jdk - OpenJDK Development Kit (JDK)
...
openjdk-8-jdk - OpenJDK Development Kit (JDK)
. . .
There are three openJDK available , which one should I install?
I myself chose the latest one, which is openjdk 8 .
If you haven't used Linux on version 8, I recommend using version 7 only.
To install Openjdk 8 type the following command.
sudo apt-get install openjdk-8-jdk
When installed, check what version is installed.
Use the command below:
java -version
3. JRE (Java Runtime Environment)
Meanwhile, JRE or Java Runtime Environment is used to run java programs.
This JRE is installed by the user if you want to run a java program or application.
JRE on Linux can be installed via the terminal.
As far as my experience, after installing OpenJdk , JRE was also installed.
But if it's not already installed, please install it.
The following is the command to install JRE version 8:
sudo apt-get install openjdk-8-jre
Make the first program
After everything is ready, let's try making a program.
The program that we will create is a program
Hello World
. This program is very famous in the world.
Prospective programmers must be able to make this program.
Because all great programmers must have made this program.
So, get ready!
Soon you will be a great person.
1. Write a program
Open the text editor, then write the program below.
class HelloWorld{
public static void main(String[] argumen){
System.out.println("Hello World!");
}
}
Save by name
HelloWorld.java
.
Where to save?
I myself save it in the home directory for easy access.
2. Compile the code
It's time to compile program code that has been written.
Now open the terminal and type the following command to copy:
javac HelloWorld.java
Because terismpan in the home directory , so just live directly compiled.
If there is no error , it means the program code has been compiled successfully.
After that a new file will be created called HelloWorld.class .
This file contains the bytecode that will be executed by JRE.
3. Run the program
Run the program, use the command
java NamaKelas
.Java Programming on Linux Using Netbeans
So far, we have successfully created a Java program by compiling via the command line or terminal.
As if it will feel a little tiring if we continue to do this process.
Because of this, Netbeans is here to help us.
Installing Netbeans on Linux
After that, we will get the Netbeans installer script.
Now our job is to execute the script.
Open the terminal and type the following command:
cd Dwonloads
sudo bash netbeans-installer.sh
Just follow it like this:
Until the welcome window from Netbeans appeared.
Click Next to continue.
Please check "I accept ..." to agree to the Netbeans license agreement.
Then click Next to continue.
Check "I accept ..." again to approve the Unit license.
Then click Next to continue.
After that, select the installation location and the JDK to be used.
Usually the JDK is detected immediately.
Click Next to continue.
Then a location selection window will appear, install Glassfish. Just click Next .
After that, a summary window will appear.
Please click Install to begin the installation process.
The installation process is ongoing, please wait ...
When finished, click Finish .
Congratulations!
Netbeans already installed.
How to use Netbeans
Please open Netbeans, go to Menu > Programming > Netbeans .
Well, let's try making a program.
To create a program in Netbeans, we must create a new project.
Click the File > New Project menu to create a new project.
After that, select Java Application and click Next .
Then fill in the application name with
HelloWorld
and click Finish .
Write the Hello World code , then run it.
To run, click the Run button .
See!
Now we don't need to compile manually. Everything has been handled by Netbeans.
When we press the Run button , Netbeans automatically compiles and executes the program.
0 Komentar untuk "Learning Java on Linux: Prompt Preparation"
Silahkan berkomentar sesuai artikel