Problem Solving and Software Engineering
Problem Solving and Software Engineering
Engineering
Chapter 1
Chapter Contents
Chapter Objectives
1.1 A Brief History of OOP and Java
1.2 Introduction to Java Application Programs
1.3 Introduction to Java Applet Programs
1.4 Problem Solving through Software
Engineering
Part of the Picture: Computer Ethics
Chapter Objectives
• Indicate variety of uses for computers
• Cover historical development of Java
• Note the platform-independent scheme of Java
• Take first looks at Java applications and
applets, comparing and contrasting
• Illustrate software development life cycle
• Note ethical issues and principles for
computing professionals
Importance of Computers in our
World
• Areas of human endeavor where computers are
used:
– Business and Finance
– Industry
– Government
– Medicine
– Entertainment
– Science
– Information Technology
A Brief History of OOP and Java
• Early high level languages
– FORTRAN, COBOL, LISP
• More recent languages
– BASIC, Pascal, C, Ada, Smalltalk, C++, Java
• UNIX operating system upgrades prompted the
development of the C language
• Powerful language … but not the best intro to
programming
– Difficult for beginning programmers
– Does not fit modern programming strategies
A Brief History of OOP and Java
• Simula-67 was a language which facilitated
the modeling of real-world objects
– New language feature called the “class”
– A class was extendable through “inheritance”
• This was the foundation needed for Object
Oriented Programming, OOP
• Smalltalk-80 used this concept
– This is the first truly object-oriented language
A Brief History of OOP and Java
• The C language was extended to include “classes”
and in 1983 became C++
• The Java language originally conceived to control
household devices using the OOP concept
– Thus, was meant to be platform (or device) independent
• Soon this was seen as well suited for running
small programs (applets) on Internet web pages
– By 1995, Netscape browsers began supporting Java
applets
– This did much to establish Java as a major language
A Brief History of OOP and Java
• Note typical implementation of a program
on different platforms Executable
code for
Compiler for
UNIX
UNIX platform
platform
Source
program Executable
Compiler for
Windows Platform
code for
Windows
platform
Compiler for Mac
OS Platform
We need Executable
Platform code for Mac
OS platform
Independence
A Brief History of OOP and Java
• Contrast compiler with interpreter
– Compiler runs once, translates to machine code for
commands of whole program This is the platform
– Interpreter translates one command
independence
at a time for which
we seek
• Java combines these two
– Java compiler generates intermediate “bytecode”
– An interpreter is developed for each platform to
interpret the bytecode
– Interpreter called the Java Virtual Machine or JVM
Introduction to Java Application
Programs
• What is a program?
– A collection of statements
– Written in a programming language
– Specify the steps taken to solve a problem
• Programs have grammar rules
– Specify how the statements are formed
– How the statements are combined
Introduction to Java Application
Programs
• Java is an object oriented programming
language
– Uses objects to carry out the tasks
– Sends messages to the objects to perform the
tasks
– Objects interact with each other to do the tasks
– An actual object is called an instance of a class
• The class is the declaration of or blueprint for the
object
Introduction to Java Application
Programs
variable
name for a
Date object
Calling an Object Method
• Example
theScreen.println(“Welcome ! Today” +
today + “you begin your study of Java”)
Method name
Object name
Parameters
Introduction to Java Applet
Programs
• Applications are stand alone programs
– executed with Java interpreter
ClassName is an
object that is a
subclass of JApplet
Body of an Applet
• Note there is no main() method in an applet
– JApplet class provides other methods instead
of a main method
• First method executed is the init() method
Applet Statements
• Declaration statements for Date are same as in
previous example
• Labels declared
JLlabel greeting = new JLabel ( … )
– freestanding strings of text
– not part of a button or menu
• Content pane
– portion of window where label is added
getContentPane().add(greeting)
// add() method called
// greeting is the parameter
Applets and Web Pages – HTML
• Applets embedded in a web page
– Executed when web page loaded by browser
• Web pages structured with HTML codes
– HyperText Mark-up Language
• Syntax Turns format on
<command>
. . .
</command>
Turns the format off
Applets and Web Pages – HTML
• Embedding Java applets
– Insert applet tags
<APPLET>
</APPLET>
• Call the specific applet by its file name
<APPLET CODE = "Whatever.class"
WIDTH = nnn HEIGHT = mmmm>
<\APPLET>
Where nnn and mmm are specific pixel sizes
Applets and Web Pages – HTML
• Create the web page
code using a text <HTML>
editor <HEAD>
Platform Independence
Problem Solving through
Software Engineering
• Common steps or phases in software development
– Design
• create an algorithm to solve the problem
– Coding
• use the high-level language according to its syntax rules
– Testing – Execution – Debugging
• try out variety of possibilities, correct problems
– Maintenance
• update, modify for changing needs
Object Centered Design
1. Behavior: state precisely what program should
do
2. Objects: identify real-world objects
- some will be primitive types
- some will need a new class to represent
3. Operations: what actions do the objects do or
have done to them
4. Algorithm: arrange the objects and operations in
an order that solves the problem
Sample Problem
• Write a program to compute a sprinter’s
average speed in kilometers per hour, given
distance (meters) and time elapsed (seconds)
Behaviors
• Display prompt for distance in meters
• Receive input from keyboard
• Display prompt for time in seconds
• Receive input from keyboard
• Compute kph
• Display titled results
Objects
• Program
• Prompt for distance
• Distance
• Keyboard
• Screen
• Prompt for seconds
• Time
• Calculated speed
Types of Objects
Description of
Type Kind Name
Object
Program ?? ?? ??
screen Screen variable theScreen
• Some solutions
– effective use of passwords
– antiviral software
– firewalls
– physical security
Health Concerns & the
Environment
• People who spend too long at a computer
and get too little exercise
• Ergonomic issues
– radiation, eye strain,
repetitive motion
damage
• Internet addiction
• Disposal of old computer parts
Information Ownership
• Also … hazards