OOP Lab 1
OOP Lab 1
OOP Lab 1
Class: BESE-10(AB)
Lab01: Familiarity with NetBeans IDE & Basic Programming in
Java
Instructor:
Ms. Hania Aslam
The purpose of this Lab is to familiarize students with the programming environment that they will be
using throughout this course for software development purposes. This lab introduces the basics of
NetBeans IDE and demonstrates how IDE software facilitates the process of programming.
After completing this lab you will be able to use different features of Netbeans IDE. Your first activity
will be creating a simple "Hello World" program using Java. As you carry out the steps in this lab, it is
important to think about what you are seeing and to understand what's going on. The more attentive you
are here the fewer headaches you'll have later!
The students will know how to download, install and use NetBeans IDE.
Further they will learn how IDE software facilitates the process of programming.
The students will write their first java program and do further simple exercises.
You may want to bring your textbook to future labs to look up syntax and examples.
Stuck? Confused? Have a question? Ask a TA/Lab Engineer for help, or look at the book or past
lecture slides.
Before you leave today, make sure to check in with one of the Lab Engineers/TAs in the lab to
get credit for your work.
Introduction to Netbeans
NetBeans IDE is a free, open source, popular, integrated development environment used by many
developers. Out of the box, it provides built-in support for developing in Java, C, C++, XML, and HTML
applications. NetBeans IDE is available for Windows, Mac, Linux and Oracle Solaris. The NetBeans
platform and IDE are free for commercial and non-commercial use, and they are supported by Sun
Microsystems.
Windows OS:
4. Leave Check for Updates option as checked. Then click Install to proceed with the
installation process.
2. From the Categories menu select Java. From the Projects menu select Java Application.
Then press Next.
4. We will now fill in some code to make the program do something. Replace line 18(inside main
function) with the following:
As shown above, the program output appears inside the Output panel in NetBeans
i++;
i++;
i++;
System.out.printf(“%d\n”,i);
The value of variable i is displayed on the screen. But how did it become the value of 3?
Let us debug the program to see what happens to the variables at each stage as the program runs.
5. Select the location the source code that you would like the program to stop at.
6. From the Debug menu, select Run to Cursor (or Press the keyboard shortcut F4).
The debugger stopped the program. We can inspect the variables. Make sure the Variables tab in the
lower right part of the window is selected.
7. From the Debug menu, select Step Over (easier to press F8). The debugger will step over this
instruction to the next instruction.
As you write more complex programs, you may need to use Step Into (to see inside of a method) option.
9. If we select line 25 of the program, and select from the debug menu to Run to Cusor (F4).
10. If you want to stop the debugger, you can select the Red Stop button.
You can have NetBeans automatically format the source code for you.
After selecting Format option from the source menu, code takes the following form i.e. indentation and
spacing is fixed:
Exporting / Importing
If you want to move your project to another machine, you can Export it.
4. To import the project back on a new machine (or if you used the export as a backup and wish
to restore back the original), from the File menu, select Import Project, From ZIP.
If the project already exists it will replace it(overwrite it). Do this only if you are restoring to replace
the current project files with the files contained in the ZIP file. Otherwise you can Change Import
Folder to place the files in a new folder. Otherwise press Cancel to avoid the import sequence.
Lab Exercises:
1. Create a new project Lab1 in Netbeans IDE as follows.
1. Select line#19
2. Select Debug > Run to Cursor(or F4). It will debug the code at line#19.
3. Select Debug > Step over(or press F8). It will debug the code at next line(line#20).
4. Select Debug > Step over(or press F8). It will debug the code at next line(line#21).
5. Select Debug > Step over(or press F8). It will debug the code at next line(line#22).
6. Select Debug > Step over(or press F8). It will debug the code at next line(line#23).
7. Select Debug > Step over(or press F8). It will debug the code at next line(line#24).
package activity1;
/**
*
* @author seecs
*/
public class Activity1
{
public static void main(String[] args)
{
System.out.println("BESE-9");
System.out.println("Section-A");
System.out.println("Course-OOP");
Once you have pasted the entire code inside Activity1.java file, format the above given code and
paste a screenshot of your formatted code below: