Lab 1_Intro to NetbeansBasic_Programming, Lab Reports of Object Oriented Programming

This would be the first lab od CS-212 in NUST.

Typology: Lab Reports

2019/2020

Uploaded on 05/13/2020

ahmad2246
ahmad2246 🇵🇰

5

(4)

7 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Department of Computing
CS 212: Object Oriented Programming
Class: BESE-10(AB)
Lab01: Familiarity with NetBeans IDE & Basic Programming in
Java
Date: 22nd January, 2020
Time: 9:00am- 12:00pm & 2:00pm-5:00 pm
Instructor:
Ms. Hania Aslam
CS 212: Object Oriented Programming Page 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Lab 1_Intro to NetbeansBasic_Programming and more Lab Reports Object Oriented Programming in PDF only on Docsity!

Department of Computing

CS 212: Object Oriented Programming

Class: BESE-10(AB)

Lab01: Familiarity with NetBeans IDE & Basic Programming in

Java

Date: 22

nd

January, 2020

Time: 9:00am- 12:00pm & 2:00pm-5:00 pm

Instructor:

Ms. Hania Aslam

Learning Objectives

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!

Lab Activity Outcomes:

 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.

Basic Lab Instructions!

 Talk to your classmates for help.  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.

Using an IDE – A Smarter Way To Code:

An IDE is more than just a text editor: it’s a set of integrated tools that assist you with the typical development workflow of coding, testing and debugging, profiling, compiling, running, and deploying applications. With NetBeans IDE, it is easy to effectively write your code, manage and build large software projects, and maintain control of multiple file revisions in a team environment.

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.

2. Select Next.

3. Take the defaults. Make sure JDK is listed, and then select Next

4. Leave Check for Updates option as checked. Then click Install to proceed with the

installation process.

  1. From the File menu, select New Project option.
  2. From the Categories menu select Java. From the Projects menu select Java Application. Then press Next.
  1. The Project Name typed was HelloWorld. The NetBeans generated the rest of the values (including the Create Main Class). Click on Finish when done. It will take a few seconds as the project is created. Here is a new blank project.
  2. We will now fill in some code to make the program do something. Replace line 18(inside main function) with the following:

1. From the Run menu, select Run Project. You can press the keyboard shortcut F6, if you prefer.

Additionally, you may press the green arrow to Run your project. As shown above, the program output appears inside the Output panel in NetBeans

A popup window about Usage Statistics may appear when you start NetBeans. If you would like to participate in anonymous information being sent to NetBeans to help them improve the program, click on I Agree. Otherwise, you may wish to say No, Thank You. Debugging Your Programs

  1. Let’s make a more complicated program. We will make a New Java Application. The Project Name will be called Counter. Click on Finish when done.

int i=0; i++; i++; i++; System.out.printf(“%d\n”,i); The file should look like the one shown below:

  1. If we Run the program (Press F6), we see the following output: 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.
  2. Select the location the source code that you would like the program to stop at.

In this case we selected in the source code at line 21.

  1. 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.

It shows that indeed, i has the value of 3, when it will be displayed to the console.

  1. If you want to stop the debugger, you can select the Red Stop button. Formatting Your Source Code You can have NetBeans automatically format the source code for you.
  2. From the Source menu, select Format.

It will automatically indent, put spaces in between variables and assignments, and fix other formatting issues. Consider the code sample, before formatting is applied to it: After selecting Format option from the source menu, code takes the following form i.e. indentation and spacing is fixed: Printing Your Source Code

1. From the File menu, select Print.

3. Select Line Numbers and Wrap Lines. Then press OK.

4. Now the preview shows the line numbers and the text wrapped on the page. Press Print to Print your file. Exporting / Importing If you want to move your project to another machine, you can Export it.

  1. From the File menu, select Export Project , To ZIP.