A1_HelloWorldExample.doc - Wikispaces

searchcoilΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 4 χρόνια και 8 μήνες)

218 εμφανίσεις

Kelvin High School

A1: Hello World

IB Computer Science

Mr. Nguyen

Hello World: Your First Java Program

Using NetBeans, set up a new project:


New Project


Java Application

Set the Project Name to HelloWorld

Set the Project as MainProject

Do NOT create a Main class

Ensure you ar
e saving to your U drive and click Finish

Kelvin High School

A1: Hello World

IB Computer Science

Mr. Nguyen

You should get something resembling the following:

Since we did not create a main class yet, we need to do it manually. Right click on the project and
header and select:



Set the Class Name to HelloWorld and click Finish (this will create a HelloWorld.java file)

Every Java program needs a main class so that it knows where to begin. Since we do not have
one yet, we will change the name of the HelloWorld c
onstructor to be:

Public static void main(String args[])

This will be the first line of code executed when the program runs.

Kelvin High School

A1: Hello World

IB Computer Science

Mr. Nguyen

We will now add the following line of code
in the main class to output to the screen

llo, World!”);

When you are ready to compile your project, go to:


Main Project

Once your source code is compiled, a Bytecode file is created
(.class extension). This Bytecode file must be executed by the
Java Runtime Environment
in order for your program to run.

You issue this command by going to:


Run Main Project

If everything is compiled and executed properly, you should see the following in the Output

Congratulations! You have just:


d your first Java project in NetBeans


Entered Java source code into a Main class


Compiled this source code into Java bytecode


Told the Java Runtime Environment to run this bytecode file


Viewed the results in the NetBeans output window

You are now ready to

tackle more challenging problems!