Programs that will be made simple, only display messages to the screen.
This program is usually called the Hello World program .
Ready…?
Before Starting, Understand First the Concept
Java programming is actually very simple.
We only do this:
- Write code : Write code with Netbeans or other editor text.
- Compilation : Change the code to bytecode .
- Execution : Run the program
Now, Let's Start ...
First we have to make a project first in Netbeans.
Please follow the steps below:
- Navigate to the File menu then select New Project . In the window that appears, select Java Application then click next .
- Fill in the project data, just replace the project name (Java Lab) and 'Create Main Class' do not need to be checked. After that click finish .
Making the Biar Rapi Package
We will save each java code in a package so that it is neatly organized and easy to find.
The package name will always change every time you meet. At this first meeting the package name is
pertemuan1
.
Making a package can be done by right clicking on the Source Package . Then select New > Java Package .
In the window that appears, fill in the name of the package with
pertemuan1
. After that, click Finish .Creating a Program Code
Java programs are created in a class (class) .
Make a new class (Java Class) on the package
pertemuan1
.
In the window that appears, fill in the name of the class with
Perkenalan
. After that click Finish .
Make sure : Use uppercase / capital letters at the beginning of the class name.
Then a new class will be named
Perkenalan
.
The gray text is a comment.
Just ignore it, because it doesn't affect the program that we make.
Usually used as additional information for programmers.
Meanwhile, it
package pertemuan1
indicates that this java code is in the package pertemuan1
.
The introductory class starts with "
{
" brackets then closes with " }
" brackets .
In that we will write the program code.
For example, please create a function
main()
in the class Perkenalan
, it contains introductory text.
Function
main()
is the main function in a program. Functions that are mandatory in every Java program.
Function
System.out.println("...");
to display text to the screen.
We will use this function a lot to display output.
Now ... let's try execution.
Press
Shift
+ F6
to execute.
Well! easy right?
When we press
Shift
+ F6
, Netbeans automatically compiles and executes the program.
This is the advantage of using Netbeans.
We don't have to bother compiling it ourselves with the Command Line command.
0 Komentar untuk "Learning Java: The First Java Program You Must Create"
Silahkan berkomentar sesuai artikel