Membuat Program Aplikasi HelloWorld Di Java Dengan NetBeans IDE

download Membuat Program Aplikasi HelloWorld Di Java Dengan NetBeans IDE

of 15

Embed Size (px)



Transcript of Membuat Program Aplikasi HelloWorld Di Java Dengan NetBeans IDE

Membuat Program Aplikasi HelloWorld di Java dengan NetBeans IDEDIPOSKAN OLEHMADI ANDIDI00.000 KOMENTARBASICHalo, Selamat datang diblog saya ini,Pada artikel sebelumnya telah dibahas mengenaiSyntak Penulisan Program Aplikasi dengan Java. Untuk tahap selanjutnya ini, akan dibahas mengenai cara membuat program aplikasi HelloWorld di Java dengan NetBeans IDE.

Langkah yang harus dilakukan sebelum menuliskan kode program aplikasiny adalah sebagai berikut : Berdoa, semoga diberikan kemudahan dalam segala hal. amin Jalankan NetBeans IDE nya, yang telah didownload ditahap sebelumnya. jika belum memiliki silahkanKlik Disiniuntuk mendownloadnya. Jalankan NetBeans IDE nya sampai muncul seperti gambar dibawah ini :

Klik menu FILE-NEW PROJECT, setelah itu akan muncul PROJECT WIZARD yang sangat memudahkan untuk membuat Java Project Pada bagian CATEGORIES, pilih JAVA, pada bagian PROJECT, pilih JAVA APPLICATION

Klik Next Beri nama Projectnya, misalnya : HelloWorld, serta tentukan path untuk menyimpan projectnya

Klik FINISH Setelah itu, NetBeans IDE ini secara otomatis akan menyiapak sebuah source program yang sudah lengkap strukturnya, dan tinggal melakukan modifikasi beberapa perintah sesuai yang diinginkan dan dibuat pada bagian :

Karena pada materi artikel ini membahas tentang Membuat Program Aplikasi HelloWorld. Maka tambahkan perintah berikut ini, untuk menampilkan pesan `HelloWorld`.System.out.println("Hello World");Sehingga tampilan Source sebagai berikut :

Kemudian silahakan tekan pada tombol yang dilingkari warna merah seperti gambar dibawah ini

Setelah itu maka akan didapatkan hasil berupa tulisan Hello World seperti gambar dibawah ini

Selamat, program aplikasi Hello World dengan bahasa pemprograman Java telah selesai dibuat. Disini ada hal yang perlu digaris bawahi yaitu,Bahwa untuk terminal pada Bahasa Pemprograman Java menggunakan ; (titik koma).Untuk pembuatan aplikasi yang selanjutnya silahkan baca artikel selanjutnya.

Running NetBeansNetBeans is available on the Ubuntu Linux workstations in the School of Computer Science & Informatics.Press the left mouse button over theApplicationsmenu and select theProgrammingcategory from the menu.

From the sub-menu chooseNetBeans.

NetBeans begins and shows asplash screenwhile it starts up.

After some question about providing anonymous usage data and registering (which you can say ``No'' to), the first NetBeans screen has a Welcome panel with links to news, tutorials, help, blogs and examples. Clicking on one of the links, will open a default Web browser (e.g.Firefox) to display the documents.

To show online documents forNetbeans, chooseOnline Docs and Supportfrom theHelppull-down menu.

A web page opens in your web browser.

Detailed documents and training can be found through the links on this page.

One option is to use theNetBeans IDE Quick Start Guideto learn how to use NetBeans.

Beware that the Quick Start Guide may refer to a different (later) version of NetBeans (so some things may not be the same).

The following section shows you how to use Netbeans to create a Java program.Creating a Simple Java Program

To begin with, chooseNew Project...from theFilemenu.

In theNew Projectdialogue, you may choose appropriate project type. For the simple Java program, chooseJavafrom the categories list andJava Applicationfrom the projects list. Click on theNextbutton to continue.

ANew Java Applicationdialog panel appears.

In the dialogue, put a project name (for exampleHello) inProject Name. The Project Folder will be updated accordingly.

By default,Create Main Classis selected (ticked) andhello.Mainwill be automatically created.

WithSet as Main Projectselected, the newly created project will be chosen as the main project (meaningful only when you are developing a large application comprising multiple projects).

Click on theFinishbutton to complete the project creation.

A the packagehello) is provided for start up:/* * To change this template, choose Tools | Templates * and open the template in the editor. */

package hello;

/** * * @author scmxxx */public class Main {

/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here }}

Java syntax is automatically highlighted, making it much easier to read and understand.

To create a simple Java program, add the follow line of code after the line starting with// TODO:System.out.println("Hello, World!");During the typing process, syntax hints are provided by default.ChooseSave Allfrom theFilemenu to save all the modified files.

TheProjectspanel shows the file structures of all the projects. For this example, projecthellocontains a single packagehellowhich then contains a single Java source

TheNavigatorpanel shows the classes and members within the current item. Here theMain.javacontains a single classMainwhich then has a member methodmain(String[] args).

You can use these panels to locate quickly different classes and their members if you are editing a large application.

Running the Java ProgramBy default, you don't need explicitly to compile (or build) the project before you run it. Of course, internally, the Java program needs to be compiled before it is ready to run. The NetBeans IDE takes care of this process. Simply choosingRun Main Projectfrom theRunmenu will run the program (after building if necessary).

The program output will appear in the Output panel.

The NetBeans SoftwareWhen you first run NetBeans, you'll see a screen something like this one:The NetBeans Software - First Start (38K)You may have to drum your fingers and wait a while, as it's not the fastest thing in the world.To start a new project, click onFile > New Projectfrom the NetBeans menu at the top. You'll see the following dialogue box appear:

We're going to be create a Java Application, so selectJavaunder Categories, and thenJava Applicationunder Projects. Click the Next button at the bottom to go to step two:

In the Project Name area at the top, type a Name for your Project. Notice how the text at the bottom changes to match your project name (in the text box to the right of Create Main Class):firstproject.MainIf we leave it like that, the Class will have the name Main. Change it toFirstProject:

Now, the Class created will be called FirstProject, with a capital "F", capital "P". The package is also called firstproject, but with a lowercase "f" and lowercase "j".The default location to save your projects appears in the Project Location text box. You can change this, if you prefer. NetBeans will also create a folder with your project name, in the same location. Click the Finish button and NetBeans will go to work creating all the necessary files for you.When NetBeans returns you to the IDE, have a look at the Projects area in the top left of the screen (if you can't see this, clickWindow > Projectsfrom the menu bar at the top of the software):

Click the plus symbol to expand your project, and you'll see the following:

Now expand Source Packages to see your project name again. Expand this and you'll see the Java file that is your source code.

This same source code should be displayed to the right, in the large text area. It will be If you can't see a code window, simply double click in your Projects window above. The code will appear, ready for you to start work.The coding window that appears should look like this (we've changed the author's name):

One thing to note here is that the class is called FirstProject:public classFirstProject {This is the same name as the java source file in the project window: When you run your programmes, the compiler demands that the source file and the class name match. So if your .java file is called firstProject but the class is called FirstProject then you'll get an error on compile. And all because the first one is lowercase "f" and the second one uppercase.