Blog for Learning

This blog contains lesson material, material summary, questions and answers, definitions, types and examples, and others.

Advertisement

Powered by Blogger.

Visitors

Flag Counter

Pages

Learning Java on Linux: Prompt Preparation

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.
Text editor on Linux
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:
  1. Compiler: Task to translate java code into bytecode ;
  2. 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 WorldThis 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.
Save the Java Program

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.
Compile Java Programs
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.
File compiled by java program

3. Run the program

Run the program, use the command java NamaKelas.
Java Program Execution

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

First, please first download the Netbeans installer file at netbeans.org .
Download Netbeans for Linux
After that, we will get the Netbeans installer script.
Netbeans installer file for Linux
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:
Execute the installer script
Until the welcome window from Netbeans appeared.
Welcome Window
Click Next to continue.
Please check "I accept ..." to agree to the Netbeans license agreement.
Netbeans License Agreement
Then click Next to continue.
Check "I accept ..." again to approve the Unit license.
Unit License Agreement
Then click Next to continue.
After that, select the installation location and the JDK to be used.
Usually the JDK is detected immediately.
Selection of JDK
Click Next to continue.
Then a location selection window will appear, install Glassfish. Just click Next .
Glass Location Installation
After that, a summary window will appear.
Installation Summary
Please click Install to begin the installation process.
The installation process is ongoing, please wait ...
Currently installing Netbeans
When finished, click Finish .
Installation Complete
🎉 Congratulations!
Netbeans already installed.

How to use Netbeans

Please open Netbeans, go to Menu > Programming > Netbeans .
Open Netbeans from the Menu
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.
Creating a New Project in Netbeans
After that, select Java Application and click Next .
Making New Projects in Netbeans
Then fill in the application name with HelloWorldand click Finish .
Creating a Java Project in Netbans
Write the Hello World code , then run it.
To run, click the Run button .
Creating a Java Program and Running it in Netbeans
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

 
Template By Kunci Dunia
Back To Top