Kami menangani hak cipta konten dengan serius. Jika Anda merasa konten ini milik Anda, ajukan klaim di sini.
Format Tersedia
Unduh sebagai DOCX, PDF, TXT atau baca online di Scribd
Anda di halaman 1/ 15
Membuat Program Aplikasi HelloWorld di Java
dengan NetBeans IDE
D I P O S K A N O L E H M A D I A N D I D I 0 0 . 0 0 0 K O M E N T A R B A S I C Halo, Selamat datang diblog saya ini, Pada artikel sebelumnya telah dibahas mengenai Syntak 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 silahkan Klik Disini untuk 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 HelloWorld.java 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 J ava menggunakan ; (titik koma). Untuk pembuatan aplikasi yang selanjutnya silahkan baca artikel selanjutnya.
Running NetBeans NetBeans is available on the Ubuntu Linux workstations in the School of Computer Science & Informatics. Press the left mouse button over theApplications menu and select theProgramming category from the menu.
From the sub-menu choose NetBeans.
NetBeans begins and shows a splash screen while 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 for Netbeans, choose Online Docs and Support from theHelp pull- 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 the NetBeans IDE Quick Start Guide to 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, choose New Project... from the File menu.
In the New Project dialogue, you may choose appropriate project type. For the simple Java program, choose Java from the categories list and Java Applicationfrom the projects list. Click on the Nextbutton to continue.
A New Java Application dialog panel appears.
In the dialogue, put a project name (for example Hello) in Project Name. The Project Folder will be updated accordingly.
By default, Create Main Class is selected (ticked) and hello.Main will be automatically created.
With Set as Main Project selected, 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 the Finish button to complete the project creation.
A template Main.java (under the package hello) 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. Choose Save All from the File menu to save all the modified files.
The Projects panel shows the file structures of all the projects. For this example, project hello contains a single package hello which then contains a single Java source file Main.java.
The Navigator panel shows the classes and members within the current item. Here the Main.java contains a single classMain which 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 Program By 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 choosing Run Main Project from the Run menu will run the program (after building if necessary).
The program output will appear in the Output panel.
The NetBeans Software When 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 on File > New Project from the NetBeans menu at the top. You'll see the following dialogue box appear:
We're going to be create a Java Application, so select Java under Categories, and then Java Application under 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.Main If we leave it like that, the Class will have the name Main. Change it to FirstProject:
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, click Window > Projects from 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 calledFirstProject.java. If you can't see a code window, simply double click FirstProject.java 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 class FirstProject { This is the same name as the java source file in the project window: FirstProject.java. 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.