Problem Solving and Software Engineering Chapter 1.

Slides:



Advertisements
Similar presentations
What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions.
Advertisements

Designing a Program & the Java Programming Language
Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets Running Java applets. Security.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
The Web Warrior Guide to Web Design Technologies
 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 1: Introduction
Static Methods Chapter 4. Chapter Contents Objectives 4.1 Introductory Example: Old MacDonald Had a Farm … 4.2 Getting Started with Methods 4.3 Example:
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Computers: Tools for an Information Age
Java Programming, 3e Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Mgt 240 Lecture Website Construction: Software and Language Alternatives March 29, 2005.
CS102 Introduction to Computer Programming
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
Introduction 01_intro.ppt
Java Programming, 2E Introductory Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
A First Program Using C#
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Problem Solving and Software Engineering Chapter 1.
CS413: Java Programming language Applications Applets
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
COMPUTER SOFTWARE Section 2 “System Software: Computer System Management ” CHAPTER 4 Lecture-6/ T. Nouf Almujally 1.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
UNIVERSITI TENAGA NASIONAL “Generates Professionals” CHAPTER 4 : Part 2 INTRODUCTION TO SOFTWARE DEVELOPMENT: PROGRAMMING & LANGUAGES.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
The Java Programming Language
1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Computer Concepts 2014 Chapter 12 Computer Programming.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Visual C++ Programming: Concepts and Projects
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Introduction to Java. 2 A Brief History of OOP and Java Early high level languages –_________________________ More recent languages –BASIC, Pascal, C,
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
APPLET. 2 Introduction to Java Applet Programs Applications are stand alone programs ◦ executed with Java interpreter Applet is a small program ◦ can.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Chapter 131 Applets and HTML Chapter Objectives learn how to write applets learn to write a simple HTML document learn how to embed an applet in.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Creating a Java Application and Applet
Introduction to OOP CPS235: Introduction.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
ITP 109 Week 2 Trina Gregory Introduction to Java.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
PROGRAMMING (1) LECTURE # 1 Programming and Languages: Telling the Computer What to Do.
Introduction to Java. 2 A Brief History of OOP and Java Early high level languages –FORTRAN, COBOL, LISP More recent languages –BASIC, Pascal, C, Ada,
System is a set of interacting or interdependent components forming an integrated whole.
Your Interactive Guide to the Digital World Discovering Computers 2012 Chapter 13 Computer Programs and Programming Languages.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Applications Active Web Documents Active Web Documents.
CSCI-235 Micro-Computer Applications
Key Ideas from day 1 slides
Lecture 1: Introduction to JAVA
Java programming lecture one
UNIT-5.
Java Applets.
Introduction CSC 111.
Computer Programming-1 CSC 111
Presentation transcript:

Problem Solving and Software 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 Source program Compiler for UNIX platform Compiler for Windows Platform Compiler for Mac OS Platform Executable code for UNIX platform Executable code for Windows platform Executable code for Mac OS platform We need 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 –Interpreter translates one command at a time 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 This is the platform independence for which we seek

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 Object oriented programs: –A collection of object interactions that solve a problem Note the similarity of this definition to the definition for a program

Java Application to Display a Greeting Figure 1.2 import ann.easyio.*; import java.util.*; class Greeter1 extends Object { public static void main (String [] args) { Date currentDate = new Date(); String today = currentDate.toString(); Screen theScreen = new Screen(); theScreen.println ("Welcome! today, " + today + ", you begin to study Java!"); }

Program Components Comments –Anything between /* and */ or following // on a single line –Documentation for humans to read –Compiler ignores Objects for this program –The screen –Current time and date –A string to store the time and date information

Classes and Packages Objects are constructed from classes Classes used for our objects Classes accessed by use of import statements Class Name Package Name Screenann.easyio Datejava.util Stringjava.lang import java.util.*

Class Declaration Syntax: class ClassName extends Object { Declarations of class members } Note the extends clause –specifies that the ClassName inherits attributes and behaviors of Object –also it will add new attributes and behaviors –ClassName is the subclass or derived class –Object is the superclass or base class

Class Members Specified between outermost set of curly braces { … } Members can be –variables that store values –methods which perform operations on the variables The main method’s declaration public static void main (String [ ] args) { a list of Java statements }  First statement of the program executed is first of these statements  Program terminates at last of these statements  First statement of the program executed is first of these statements  Program terminates at last of these statements

Declarations Example Date currentDate = new Date() Actually creates the Date object Class specification variable name for a Date object

Calling an Object Method Example theScreen.println(“Welcome ! Today” + today + “you begin your study of Java”) Object name Parameters Method name

Introduction to Java Applet Programs Applications are stand alone programs –executed with Java interpreter Applet is a small program –can be placed on a web page –will be executed by the web browser –give web pages “dynamic content”

Java Applet to Display a Greeting Figure 1.3 import javax.swint.*; import java.util.*; public class Greeter2 extends JApplet { public void init() { Date currentDate = new Date(); String today = currentDate.toString(); JLabel greeting = new JLabel ("Welcome ! today, " + today + ", you begin your study of Java!"); }

Java Applets Built using one of general definitions of applets –Applet class –JAapplet class Java applets are usually graphical –Draw graphics in a defined screen area –Enable user interaction with GUI elements

Java Applet Classes Abstract Windowing Toolkit AWT –Earlier versions of Java –Applet class is one of the AWT components Java Foundation Classes JFC –Extension to Java in 1997 –Has a collection of Swing components for enhanced GUIs –Swing component classes begin with J –Note the import javax.swing.*; line in figure 1.3

Applet Declaration Syntax (note difference from application declaration) public class ClassName extends JAappletapplication 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 –H yper T ext M ark-up L anguage Syntax... Turns format onTurns the format off

Applets and Web Pages – HTML Embedding Java applets –Insert applet tags Call the specific applet by its file name Where nnn and mmm are specific pixel sizes

Applets and Web Pages – HTML Create the web page code using a text editor Save it with an.html suffix Open this file with appletviewer or with a web browser that supports Java

Applets and Web Pages – HTML Client Web browser anywhere can access this web page from its host server Embedded Java applet runs on client browser (of any type platform) This means a client anywhere on any type of platform can run a piece of software developed on any other type of platform 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 Object TypeKindName Program?? screenScreenvariable theScreen prompt for distStringConstant distancedoublevariable meters keyboardKeyboardvariable theKeyboard prompt for timeStringconstant timedoublevariable seconds speeddoublevariable kilometersPerHour

Operations Display on theScreen prompt for distance Read a value from theKeyboard Store it in meters Display on theScreen prompt for time Read a value from theKeyboard Store it in seconds Compute kilometersPerHour Display kilometersPerHour on theScreen

Algorithm 1.Construct theKeyboard and theScreen 2.Ask theScreen to display prompt for dist 3.Ask theKeyboard to read a double value, store in meters 4.Ask theScreen to display prompt for time 5.Ask theKeyboard to read a double value, store it in seconds 6.Compute the conversion of mps to kph 7.Ask theKeyboard to display kilometersPerHour along with descriptive text

Coding and Testing Translate algorithm into syntax of Java –Note Figure 1.4 Compile the program – compiler checks for syntax errors Run the program with sample values –observe whether the results are reasonable –Calculate results by hand to see if there is agreement –try a variety of times Run-time errors can be tracked down with a debugger –executes the program one line at a time

Maintenance Requirements of program may change –Client wants different kind of output –Client sees ways of expanding program to do more –Some other entity (government) requires a different format or additional results

Part of the Picture : Computer Ethics Computers permeate every aspect of our lives They perform life-critical tasks Yet computer science is not regulated to the extent of medicine, air travel, or construction zoning Much thought should be given to issues of ethics

Computer Crime & Security Some crimes are high tech versions of low tech problems (theft, fraud, child porno) Viruses and “trojan horses” Hackers try to get into restricted systems 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 Illegal software copying (pirating) Infringement copyright by copying of pictures or text from web pages Plagiarism by copying text from other sources when original work is expected

“Netiquette” and Hoaxes Inflammatory interchange of messages via internet ( , chat rooms, etc.) Chain mail Virus warning hoaxes “Spam” – unsolicited, bulk

Internet Content & Free Speech Information on internet includes hate, violence, harmful information for children How much of this should be regulated Do filters solve problems or create more How reliable are web sites used for course work and research

Privacy U.S. Constitution, Amendments, and laws specify certain levels of privacy Databases containing personal information are easily stored, transmitted, and often available Does an employer have a right to monitor messages Procedures and policies should be put in place and used by computer professionals

Quality Control & Risk Reduction Good software is difficult to produce It must be carefully designed, developed, tested Mistakes generated by computers can be far reaching Commenting and documenting software is required for effective maintenance throughout the life of the program Y2K issues highlighted the need for thinking ahead

The Future Telecommuting Distance learning E-commerce Information availability Also … hazards