A1_HelloWorldExample.doc - Wikispaces

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

15 Αυγ 2012 (πριν από 5 χρόνια και 1 μήνα)

242 εμφανίσεις

Kelvin High School


A1: Hello World

IB Computer Science


Mr. Nguyen


Hello World: Your First Java Program


Using NetBeans, set up a new project:


File


New Project

General


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:


New


JavaClass


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


System.out.println(“He
llo, World!”);


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


Build


Build
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


Run Main Project








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















Congratulations! You have just:


0.

Create
d your first Java project in NetBeans

1.

Entered Java source code into a Main class

2.

Compiled this source code into Java bytecode

3.

Told the Java Runtime Environment to run this bytecode file

4.

Viewed the results in the NetBeans output window


You are now ready to

tackle more challenging problems!