Programming Fundamentals Lab Manual 03

Programming Fundamentals Lab Manual 03

Statement Purpose:

This lab covers the following topics:
                      • Install Net Beans
                      • Getting Started with Net Beans
                      • Creating a Project
                      • Creating a Class
                      • Compiling a Class
                      • Running a Java Application
                      • Forcing a Program to Terminate
This tutorial applies to Net Beans 6, 7, or a higher version.

Activity Outcomes:

This lab teaches you the following topics:
                      • Installing java
                      • Create first java program

1)       Stage J(Journey)

Introduction

This tutorial is for students who are currently taking a Java course using Net Beans with Introduction to Java Programming.
You can use the JDK command line utility to write Java programs. The JDK command line utility consists of a set of separate programs, such as compiler and interpreter, each of which is invoked from a command line. Besides the JDK command line utility, there are more than a dozen Java development tools on the market today, including Net Beans, J Builder, and Eclipse. These tools support an integrated development environment (IDE) for rapidly developing Java programs. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface. Using these tools effectively will greatly increase your programming productivity.
This brief tutorial will help you to become familiar with Net Beans. Specifically, you will learn how to create projects, create programs, compile, run, and debug programs.

2)       Stage a1 (apply)

Lab Activities:

Activity 1:Install Net Beans

Download and install JDK 1.8 and Net Beans 8.0 from one bundle at http://www.oracle.com/technetwork/java/javase/downloads/jdknetbeansjsp142931.html

Activity 2 Getting Started with Net Beans

Assume that you have successfully installed Net Beans on your machine. Start Net Beans from Windows, Linux, Mac OS X, or Solaris. The Net Beans main window appears, as shown in Figure 1.

Figure 1

The Net Beans main window is the command center for the IDE.
The Net Beans main window contains menus, toolbars, project pane, files pane, run time pane, navigator pane, and other panes.
1.1 The Main Menu
The main menu is similar to that of other Windows applications and provides most of the commands you need to use Net Beans, including those for creating, editing, compiling, running, and debugging programs. The menu items are enabled and The toolbar provides buttons for several frequently used commands on the menu bar. The toolbars are enabled and disabled in response to the current context. Clicking a toolbar is faster than using the menu bar. For many commands, you also can use function keys or keyboard shortcuts. For example, you can save a file in three ways:
disabled in response to the current context.
1.2 The Toolbar 
  • Select File, Save from the menu bar.
  • Click the “save” toolbar button ().
  • Use the keyboard shortcut Ctrl+S.
TIP: You can display a label known as Tool Tip for a toolbar button by pointing the mouse to the button without clicking.
1.3 Work spaces 
A work space is a collection of windows that are pertinent to performing certain types of operations, such as editing, execution, output, or debugging. The work-space windows can be displayed from the Window menu.

Activity 3 Creating a Project

A project contains information about programs and their dependent files, and it also stores and maintains the properties of the IDE. To create and run a program, you have to first create a project.
Here are the steps to create a demo project:
  1. Choose FileNew Project to display the New Project dialog box, as shown in Figure 2.
  2. Select General in the Categories section and Java Application in the Projects section and click Next to display the New Java Application dialog box, as shown in Figure 3.
  3. Type demo in the Project Name field and c:\michael in Project Location field.
  4. (Optional) You can create classes after a project is created. Optionally you may also create the first class when creating a new project. To do so, check the Create Main Class box and type a class name, say First, as the Main Class name.
  5. Click Finish to create the project. The new project is displayed, as shown in Figure 4.
Figure 2
The New Project dialog box enables you to specify a project type.
Figure 3
The New Java Application prompts you to enter a project name, location, and a main class name.
Figure 4
A new demo project is created.

Activity 4 Creating a Class

You can create any number of classes in a project. Here are the steps to create Welcome.java.
  1. Right-click the top demo node in the project pane to display a context menu, as shown in Figure 5. Choose NewJava Class to display the New Java Class dialog box, as shown in Figure 6.
  2. Type Welcome in the Class Name field and select the Source Packages in the Location field. Leave the Package field blank. This will create a class in the default package. (Note that it is not recommended to use the default package, but it is fine to use the default package to match the code in the book. Using default package is appropriate for new Java students. Section 10, “Using Packages,” will introduce how to create a class in a non default package.)
  3. Click Finish to create the Welcome class, as shown in Figure 7. The source code file Welcome.java is placed under the <default package> node, because you did not specify a package name for the class in Figure 6.
  4. Modify the code in the Welcome class to match Listing 1.1, as shown in Figure 8.
Figure 5
You can create a new class in a project. 
Figure 6
The New Java Class dialog box enables you to specify a class name, location, and package name to create a new class.
Figure 7
A new Java class is created in the project.
Figure 8
The source code for Welcome.java is entered.
TIP 
You can show line numbers in the Source Editor by choosing ViewShow Line Numbers from the main menu.
NOTE
The source file Welcome.java is stored in c:\michael\demo\src.

Activity 5 Compiling a Class

To compile Welcome.java, right-click Welcome.java to display a context menu and choose Compile File, or simply press F9, as shown in Figure 9.
The compilation status is displayed in the Output pane, as shown in Figure 10. If there are no syntax errors, the compiler generates a file named Welcome.class, which is stored in c:\michael\demo\build\classes.
Figure 9
The Compile File command in the context menu compiles a source file.
Figure 10

The compilation status is shown in the output pane.
NOTE: When you compile the file, it will be automatically saved.

Activity 6 Running a Java Application

To run Welcome.java, right-click Welcome.java to display a context menu and choose Run File, or simply press Shift + F6, as shown in Figure 12. The output is displayed in the Output pane, as shown in Figure 13.

Figure 11
The Run File command in the context menu runs a Java program.
Figure 12
The execution result is shown in the Output pane. 
NOTE: The Run File command invokes the Compile File command if the program is not compiled or was modified after the last compilation.  

Activity 7 Forcing a Program to Terminate

If a program does not terminate due to a logic error, you can force it to terminate by clicking the Stop icon, as shown in Figure 15.

You can force a program to terminate from the run time pane.

3) Stage v(verify)

Home Activities:

Every student is required to make installation on his / her personal computer before next lab.

4) Stage a2(assess)

Lab Assignment and Viva voce

Comments

Popular posts from this blog

Programming Fundamentals Lab Manual 13

Programming Fundamentals Lab Manual 04

Programming Fundamentals Lab Manual 12