Lab Manual
(Object-oriented)
1432/1433H
Lab - 1
Learning Procedure
1) Stage
J
(Journey inside-out the concept) 2) Stagea
1 (apply the learned)3) Stage
v
(verify the accuracy) 4) Stagea
2 (assess your work)Laboratory 1:
Statement Purpose:
This lab will give you an introduction to Java programming environment.
Activity Outcomes:
This lab teaches you the following topics:
To understand the activity of programming
To learn about machine code and high-level programming languages
To learn the environment you will be using for programming in Java.
Introduce the basics of NetBeans IDE.
To become familiar with your computing environment and your compiler
To compile and run your first Java program
Instructor Note:
As pre-lab activity, read Chapter 1 from the book (An Introduction to Object- Oriented Programming with Java, 4th Edition by C. THOMAS WU (Book’s website www.mhhe.com/wu), and also as given by your theory instructor.
Names I.D.
1. .………..………. ………
2. ..……….. ………
1) Stage J (Journey)
Introduction
The purpose of this Lab. is to familiarize you with the environment you will be using throughout this course. It reviews the architecture of a computer and discusses the difference between machine code and high-level programming languages. Finally, you will see how to compile and run your first Java program, and how to diagnose errors that may occur when a program is compiled or executed.
What Is Program?
Programs are sequences of instructions and decisions that the computer carries out to achieve a task. A computer must be programmed to perform tasks. Different tasks require different programs.
The Anatomy of a Computer
Computer Understand Only Machine Level language.
The CPU reads machine instructions from memory.
In High Level Language is a language which is very nearer to English language in which the programmer expresses the idea behind the task that needs to be performed in an English type language some of the high level languages are Java, C++, etc.
Compiler translates the high-level description into machine instructions for a particular processor.
Java programming specification
Java Byte Code: Intermediate representation for Java programs
Java Compiler: Transform Java programs into Java byte code
Java Interpreter: Read programs written in Java byte code and execute them
Java Virtual Machine (JVM): Runtime system that provides various services to runni
ng programs
Java Programming Environment: Set of libraries that provide services such as GUI (Eclipse, NetBeans), data structures, etc.
Java is case sensitive. You must be careful about distinguishing between upper- and lowercase letters.
2) Stage a
1(apply)
NetBeans IDE 6.X (Java Quick Start Tutorial)
Welcome to NetBeans IDE!
This tutorial provides a very simple and quick introduction to the NetBeans IDE workflow by walking you through the creation of a simple "Hello World" Java console application. Once you are done with this tutorial, you will have a general knowledge of how to create, build, and run applications in the IDE.
This tutorial takes less than 10 minutes to complete.
After you finish this tutorial, you can move on to the NetBeans IDE learning trails. The learning trails provide comprehensive tutorials that highlight a wider range of IDE features and programming techniques for a variety of application types. If you do not want to do a "Hello World" application, you can skip this tutorial and jump straight to the learning trails.
Before You Begin
To write your first program, you'll need to have the following software installed on your system:
The J2SE(TM) Development Kit (JDK), version 5.0 or compatible.
NetBeans IDE 6.0.
To download go to the link below and choose "JDK 6 Update 4 with NetBeans 6.0.1"
http://java.sun.com/javase/downloads/index.jsp
Setting Up the Project
To create an IDE project:
1. Start NetBeans IDE.
2. In the IDE, choose File > New Project, as shown in the figure below.
3. In the New Project wizard, expand the Java category and select Java Application as shown in the figure below. Then click Next.
In the Project Name field, type Hello.
In the Create Main Class field, type Hello.
Leave the Set as Main Project checkbox selected.
5. Click Finish.
The project is created and opened in the IDE. You should see the following components:
The Projects window, which contains a tree view of the components of the project, including source files, libraries that your code depends on, and so on.
The Source Editor window with a file called Hello open.
The Navigator window, which you can use to quickly navigate between elements within the selected class.
3) Stage v (verify)
Adding Code to the Generated Source File
Because you have left the Create Main Class checkbox selected in the New Project wizard, the IDE has created a skeleton class for you. You can add the "Hello World!" message to the
skeleton code by replacing the line:
// TODO code application logic here
with the line:
System.out.println("Hello World!");
Save the change by choosing File > Save.
The file should look something like the following:
/*
* Hello.java *
* Created on Sep 7, 2007, 6:44:16 PM *
* To change this template, choose Tools | Templates
/**
*
* @author Sonya Bannister */
public class Hello { /**
* @param args the command line arguments */
public static void main(String[] args) { System.out.println("Hello World!");
} }
Compiling the Source File
If the build output concludes with the statement BUILD SUCCESSFUL, congratulations! You have successfully compiled your program!
If the build output concludes with the statement BUILD FAILED, you probably have a syntax error in your code. Errors are reported in the Output window as hyper-linked text. Click such a hyper-link to navigate to the source of an error.
You can then fix the error and once again choose Build > Build Main Project.
When you build the project, the bytecode file Hello.class is generated. You can see where the new file is generated by opening the Files window and expanding the
Hello World App/build/classes/Hello node as shown in the following figure.
Now that you have built the project, you can run your program.
Running the Program
Congratulations! Your program works!
You now know how to accomplish some of the most common programming tasks in the IDE.
4) Stage a
2(assess) Homework 1:
For this lab you are requested to solve Lab homework and to submit it before the deadline.
Lab Homework:
The laboratory homework of this lab (and also all the following labs in this manual) should include the following items/sections:
A cover page with your name, course information, lab number and title, and date of submission.
Programming: a brief description of the process you followed in conducting the coding of the homework solution.
Results obtained throughout the written code followed with brief analysis of these results.
A zip file including both the Java project folder and the work file contains all items/sections above.
Note: only a softcopy is required, please do not print or submit a hard copy.