0% found this document useful (0 votes)
106 views9 pages

Study Guide: Object Oriented Programming (OOP)

This document provides a study guide for an Object Oriented Programming lesson about the NetBeans IDE software. It covers how to load and use NetBeans, create projects, understand Java code structure and comments, run and share Java programs. The lesson includes activities for students to create Java classes that output text to the screen.

Uploaded by

Aj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views9 pages

Study Guide: Object Oriented Programming (OOP)

This document provides a study guide for an Object Oriented Programming lesson about the NetBeans IDE software. It covers how to load and use NetBeans, create projects, understand Java code structure and comments, run and share Java programs. The lesson includes activities for students to create Java classes that output text to the screen.

Uploaded by

Aj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

BICOL UNIVERSITY POLANGUI CAMPUS

Polangui, Albay

STUDY GUIDE

OBJECT ORIENTED PROGRAMMING


(OOP)

Study Guide #2
Lesson 2: The NetBeans IDE 8.0.2 Software
Topics covered:
 Loading NetBeans IDE 8.0.2 for the first time
 Creating a New Project
 Java Comments
 The Structure of Java Code
 Running a Java Program
 Sharing a Java Program

Objectives:

At the end of the lesson, the student must be able to:

1. Learn how to load NetBeans IDE.


2. Create a New Project in Java
3. Learn Java Comments
4. Know the structure of Java Code
5. Execute a Java program
6. Share a Java program

Lesson 2.1: Loading NetBeans IDE 8.0.2 for the first time
To load NetBeans IDE for the first time, there are several ways to consider, using Desktop, Start
Menu, and etc…

 Using the Desktop: Double Click the icon Apache NetBeans IDE 11.3 or right click then click
Open to load NetBeans IDE.

 Using the Start Menu: Click the Start Menu button, then look for the Apache NetBeans IDE
11.3 program from the list and then Click it.

Desktop:
Double Click

Desktop:
Right Click
The NetBeans IDE 2.0.8 (When you first run NetBeans)

Lesson 2.2: Creating a New Project


1. To start a New project, Click on File>New Project. You can also Press Ctrl+shift+N or Click
the New Project Button.

File

New Project

2. The New Project window appears, select Java from the Categories: box, select Java Application
from the Projects: box, then click Next button.

Java

Java Application

Next
3. The New Java Application window appears, in the Project Name area, type the name of your
project. Project Location area is the default location to save your projects, you can change this if
you prefer. Project Folder area is also created by NetBeans with your project name. Click the
Finish button.

Project Location

Project Folder
Project Name

Finish Button

4. The NetBeans IDE 8.0.2 appears, which is compose of the Project Area and Coding Window.
You are now ready to work.

The Project Area Coding Window

Lesson 2.3: Java Comments


Some text is grayed out, grayed-out areas are comments with lots of slashes and asterisk.
Comments are ignored when program runs, you can type whatever you want inside of your comments.
Comments also explain what is you’re trying to do.

Types of Java Comments

1. Single Line Comment (double slashes - //)

Example 1: single line

//this is a single line comment


Example 2: more than one line

//this is a comment spreading


//over two lines or more

2. Multi-line Comment (/*………..*/)

Example 1:

/*
This is a comment spreading
Over two lines or more
*/

3. Javadoc Comments (/**….*…*/)

Example 1:

/**
*this is a Javadoc comment
*/

NOTE: You can delete the comments that NetBeans generates for you.

Lesson 2.4: The Structure of Java Code


1. After deleting the comments, here is what your coding window should look like now:

Coding window with deleted comments

2. The Package name is coded first, and notice the semicolon (;) at the end of the line, program will
not run if you miss semicolon:

package Program1;

3. The Class name, you can think of a class as a code segment, you should begin and end with a left
and right curly brackets. Anything inside the left and right curly brackets belong to that code
segment:

public class Program1 {

4. The Main Method, it is here the action begins, it is the main entry point for your program, it will
execute any codes within the curly brackets. You will get error messages if your do not have a
main method on your Java code:
public static void main(String[] args) {

 public – method can be seen outside this class


 static – means that you don’t have to create a new object
 void – it doesn’t return a value
 String[] args – command line arguments

Lesson 2.5: Running a Java Programs


In your previous lessons you have a Main method, but it has no code inside of it. Let’s add a line
of code and then execute it. We will learn how to display text on your screen.

1. Add the following line to your Main method:

public static void main(String[] args) {

System.out.println("My First project in Java");

 When you type the full stop after “System”, NetBeans will try to help you by displaying a list
of available options:

2. Double click out to add it to your code, then type another full stop. Again a list of options
appears. Select println, this time.
3. Type your text ("My First project in Java"); and end it with semicolon, each complete line of code
in Java needs a semicolon at the end, miss out and the program will not compile.
4. Save your code, click File>Save or File>Save All or click the Save button in the toolbar.
5. There are a lot of ways to run a Java program, you can use any of the following:

 Press F6 from the keyboard Function keys.


 Locate Run menu and then click Run Project (Program1)

Run

Run Project

 Using the Green arrow on the NetBeans toolbar.

Green Arrow Button

 Right Click Java source file in the Project window, then select Run File.

Source File

Run File
 Lastly, is to Right Click inside the Code Area or Code Window, then Select Run File.

Code Area/Window
Run File
6. Using one of the above methods, execute or run your program. The possible output is shown in
the Output Window below:

The Output Window

Lesson 2.6: Sharing your Java Programs


You can send your programs to other people so that they can run them. To do that, you need to
create a JAR File (Java Archive).

1. Click Run menu at the top, select Clean and Build Project or press Shift+F11 from the keyboard.
The Run
menu

Clean and Build


Project/Shift+11

2. NetBeans save your work and then creates all the necessary files.
3. It will create a folder called dist and places all the file in there.
4. Look for the dist folder in your computers Documents Folder>NetBeansProjects>Program1
NetBeans project.
5. Double click the dist folder to display files inside the folder.

Location of
the dist
Files folder

6. You should see a JAR file and README text file.


7. The text file contains instructions on how to run the program from a terminal/console window.

Activity No. 1: Using NetBeans, create a class named: [YourName]. The program should output on the
screen:

Welcome to Java Programming [YourName]!!!

Activity No. 2: Using NetBeans, create a class named: TheTree. The program should output the
following lines on the screen:

I think that I shall never see,


a poem as lovely as a tree.
A tree whose hungry mouth is pressed
Against the Earth’s sweet flowing breast.

Things to do: Submit a screenshot of your codes and output in our Google drive under activity folder.

References:

1. https://www.homeandlearn.co.uk/java/getting_started_with_java.html
2. NetBeans IDE 8.0.2

You might also like