java programming, 3e concepts and techniques chapter 1 an introduction to java and program design

51
Java Programming, 3e Concepts and Techniques Chapter 1 An Introduction to Java and Program Design

Post on 21-Dec-2015

224 views

Category:

Documents


3 download

TRANSCRIPT

Java Programming, 3eConcepts and Techniques

Chapter 1An Introduction to

Java and Program Design

2Chapter 1: An Introduction to Java and Program Design

Chapter Objectives

• Describe characteristics of Java

• Explain the uses of Java and identify types of Java programs

• Identify the phases in the program development life cycle

• Define programs, programming, and applications

• Read, explain, and create a class diagram

3Chapter 1: An Introduction to Java and Program Design

Chapter Objectives

• Read, explain, and create an event diagram

• Explain object-oriented programming (OOP) and object-oriented design (OOD)

• Define the terms objects, attributes, methods, and events

• Define and explain encapsulation, inheritance, and polymorphism

4Chapter 1: An Introduction to Java and Program Design

Chapter Objectives

• Describe rapid application development (RAD)

• Identify key components of the Java Software Development Kit (SDK)

5Chapter 1: An Introduction to Java and Program Design

Introduction

• A program is a step-by-step series of instructions for a computer

• Computer programming is the process of writing these instructions

• Programmers, or developers, design and write programs using a programming language or development tool

• Java is a programming language that provides the structure for efficient and economical programs

6Chapter 1: An Introduction to Java and Program Design

What Is Java?

• High-level language

• Object-oriented– Data and operations are packaged into a

single unit called an object

• Basic syntax derived from C, C++, and Smalltalk– Designed by a team from Sun Microsystems

led by James Gosling in the early 1990’s

7Chapter 1: An Introduction to Java and Program Design

What Is Java?

• Parsimonious– Compatible with older versions

• Robust– Strongly typed and incorruptible data

• Secure– Protection against misuse of code

• Portable– Platform-independent

8Chapter 1: An Introduction to Java and Program Design

Java Program Types

• Console and Windowed applications

• Applets

• Servlets

• Web Services

• JavaBeans

9Chapter 1: An Introduction to Java and Program Design

Console Applications

• Stand-alone programs using a command-line interface

10Chapter 1: An Introduction to Java and Program Design

Windowed Applications

• Stand-alone programs using a graphical user interface (GUI)

11Chapter 1: An Introduction to Java and Program Design

Applets

• Client-side programs executed as part of a displayed Web page

12Chapter 1: An Introduction to Java and Program Design

Servlets

• Server-side programs hosted and run on a Web server

• Used in conjunction with Java Server Pages (JSP) to provide sophisticated server-side logic

• Enable connections to server databases through Java Database Connectivity (JDBC)

13Chapter 1: An Introduction to Java and Program Design

Servlets

14Chapter 1: An Introduction to Java and Program Design

Web Services

• Services receive information requests over the Web and return the requested data

15Chapter 1: An Introduction to Java and Program Design

JavaBeans• Reusable software components

16Chapter 1: An Introduction to Java and Program Design

Programming a Computer

• Companies need developers to build general application software packages

• Custom applications are built for specific needs

• Existing programs need maintenance, monitoring, and upgrades

• New applications will be needed due to emerging technologies

17Chapter 1: An Introduction to Java and Program Design

18Chapter 1: An Introduction to Java and Program Design

Program Development Cycle

19Chapter 1: An Introduction to Java and Program Design

Phase 1 – Analyze the Requirements• Verify that the requirements are clear and

complete

• Evaluate the problem to determine that it is solvable using a program

• List the required input and output data

• Determine whether the input data is available for testing

20Chapter 1: An Introduction to Java and Program Design

Phase 1 – Analyze the Requirements• Ensure that a solution, or algorithm, can

be developed with the information provided in the requirements

• Verify the user interface specifications

21Chapter 1: An Introduction to Java and Program Design

22Chapter 1: An Introduction to Java and Program Design

Phase 2 – Design the Solution

• Develop a logical model that illustrates the sequence of steps you will take to solve the problem

• Use design tools such as storyboards, class diagrams, flowcharts, and pseudocode to outline the logic of the program

23Chapter 1: An Introduction to Java and Program Design

Phase 2 – Design the Solution

• Storyboards are sketches of the user interface

24Chapter 1: An Introduction to Java and Program Design

Phase 2 – Design the Solution

• Class Diagrams illustrate the attributes and methods of a class of objects– Attributes define the characteristics of a class– Methods are instructions a class uses to

manipulate values, generate outputs, or perform actions

25Chapter 1: An Introduction to Java and Program Design

Phase 2 – Design the Solution

26Chapter 1: An Introduction to Java and Program Design

Phase 2 – Design the Solution

• Flowcharts graphically represent the logic used to develop an algorithm

• Control structures allow the programmer to specify the code that will execute only if a condition is met

• Flowcharts use pseudocode, English, or mathematical notation inside symbols to represent the steps of a solution

27Chapter 1: An Introduction to Java and Program Design

28Chapter 1: An Introduction to Java and Program Design

29Chapter 1: An Introduction to Java and Program Design

Phase 2 – Design the Solution

• Pseudocode is an English representation of how the program code should be written

30Chapter 1: An Introduction to Java and Program Design

Phase 3 – Validate the Design

• The programmer steps through the solution with test data

• The user agrees that the program design solves the problem put forth in the requirements

• The user verifies that the initial requirements document contains all necessary requirements

31Chapter 1: An Introduction to Java and Program Design

Phase 4 – Implement the Design

• Write the code that translates the design into a program

• Create the user interface

• Create comments within the code that explains the purpose of the code

• Unit testing– Test the code as it is written

• Test related code

32Chapter 1: An Introduction to Java and Program Design

Phase 4 – Implement the Design

33Chapter 1: An Introduction to Java and Program Design

Phase 5 – Test the Solution

• Create a test plan with test cases of sample input data and expected output

• Perform integration testing to ensure that components interact correctly

• Test boundary values

• Document any problems– If results are unsatisfactory, a new iteration of

the development cycle begins

34Chapter 1: An Introduction to Java and Program Design

Phase 6 – Document the Solution

• Requirements documents, program design documents, user interface documents, and documentation of the code

• Test cases and proof of successful completion of testing

• Program code should be archived electronically

35Chapter 1: An Introduction to Java and Program Design

Object-Oriented Programming and Design• Object-oriented programming

– Data and the code that operates on the data are packaged into a single unit called an object

• Object-oriented design– Identifies how objects interact with each other

to solve a problem

36Chapter 1: An Introduction to Java and Program Design

Object-Speak

• Aggregation– The concept of an object composed of

another object

• Generalization hierarchy– A tool displaying a hierarchy of classes,

including superclasses and subclasses

• Instance– A specific use of a class

37Chapter 1: An Introduction to Java and Program Design

Object-Speak

• Operation– Activity that reads or manipulates the data of an

object

• Message– Activates the code to perform one of the operations

• Trigger– Causes the message to be sent

• Event– The process of a trigger sending a message that

results in an operation

38Chapter 1: An Introduction to Java and Program Design

Object-Speak

• An event diagram graphically represents relationships among event and operations

• Useful for designing event-driven programs• Part of the Unified Modeling Language (UML)

– The UML provides a standardized model to describe object-oriented designs graphically

– The UML is a system of symbols to represent object behavior and program behavior

39Chapter 1: An Introduction to Java and Program Design

40Chapter 1: An Introduction to Java and Program Design

Encapsulation

• The process of hiding the implementation details of an object from its user

• The user is shielded from the system’s complexity

• Information hiding provides access to an object only through its messages

• Objects can be modified without requiring application modification

41Chapter 1: An Introduction to Java and Program Design

Inheritance

• An efficient way to reuse code by defining a subclass as an extension of another class

• The subclass inherits all the data and functions of the superclass

• The subclass has at least one attribute or method that differs from its superclass

42Chapter 1: An Introduction to Java and Program Design

Polymorphism

• Allows an instruction to be given to an object using a generalized command

• The same command will obtain different results depending on the object receiving the command

• The specific actions internal to the object are encapsulated from the user

43Chapter 1: An Introduction to Java and Program Design

44Chapter 1: An Introduction to Java and Program Design

Rapid Application Development

• Pre-built objects speed up program development

45Chapter 1: An Introduction to Java and Program Design

What Is the Java SDK?

• The Java Software Development Kit (SDK) is a programming package to develop Java applications

• The Java Runtime Environment (JRE) provides the tools to deploy Java applications

46Chapter 1: An Introduction to Java and Program Design

Features of the J2SE

• The Java Compiler– Converts code into bytecode

• The Java Virtual Machine – Contains an interpreter to execute the bytecode

• The Java API– The standard set of packages available in Java

• The Java Applet Viewer– Mini browser to display Java applets

47Chapter 1: An Introduction to Java and Program Design

Other Java Development Tools

• VATE (value-added text editor)– Color codes elements and numbers lines– Examples: TextPad, JCreator, JGrasp

• IDE (integrated development environment)– Builder tool to aid coding and debugging – Examples: Sun ONE Studio, JBuilder, Visual Age,

Simplicity

• Web server– Deploys servlets– Example: Tomcat

48Chapter 1: An Introduction to Java and Program Design

Chapter Summary

• Describe characteristics of Java

• Explain the uses of Java and identify types of Java programs

• Identify the phases in the program development life cycle

• Define programs, programming, and applications

• Read, explain, and create a class diagram

49Chapter 1: An Introduction to Java and Program Design

Chapter Summary

• Read, explain, and create an event diagram

• Explain object-oriented programming (OOP) and object-oriented design (OOD)

• Define the terms objects, attributes, methods, and events

• Define and explain encapsulation, inheritance, and polymorphism

50Chapter 1: An Introduction to Java and Program Design

Chapter Summary

• Describe rapid application development (RAD)

• Identify key components of the Java Software Development Kit (SDK)

Java Programming, 3eConcepts and Techniques

Chapter 1 Complete