0% found this document useful (0 votes)
1 views

A Webbased Introduction To Programming Essential Algorithms Syntax And Control Structures Using Php Html And Mariadbmysql 4th Mike Okane download

The document is a comprehensive guide titled 'A Web-Based Introduction to Programming' by Mike O'Kane, covering essential algorithms, syntax, and control structures using PHP, HTML, and MariaDB/MySQL. It includes detailed chapters on various programming concepts, client/server applications, program design, and practical coding exercises. The fourth edition aims to provide instructional value for learners in web-based programming environments.

Uploaded by

miskaaxiefa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

A Webbased Introduction To Programming Essential Algorithms Syntax And Control Structures Using Php Html And Mariadbmysql 4th Mike Okane download

The document is a comprehensive guide titled 'A Web-Based Introduction to Programming' by Mike O'Kane, covering essential algorithms, syntax, and control structures using PHP, HTML, and MariaDB/MySQL. It includes detailed chapters on various programming concepts, client/server applications, program design, and practical coding exercises. The fourth edition aims to provide instructional value for learners in web-based programming environments.

Uploaded by

miskaaxiefa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 88

A Webbased Introduction To Programming Essential

Algorithms Syntax And Control Structures Using


Php Html And Mariadbmysql 4th Mike Okane
download
https://ebookbell.com/product/a-webbased-introduction-to-
programming-essential-algorithms-syntax-and-control-structures-
using-php-html-and-mariadbmysql-4th-mike-okane-10011484

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Crystal Programming A Projectbased Introduction To Building Efficient


Safe And Readable Web And Cli Applications George Dietrich

https://ebookbell.com/product/crystal-programming-a-projectbased-
introduction-to-building-efficient-safe-and-readable-web-and-cli-
applications-george-dietrich-47661790

Crystal Programming A Projectbased Introduction To Building Efficient


Safe And Readable Web And Cli Applications 1st Edition George Dietrich

https://ebookbell.com/product/crystal-programming-a-projectbased-
introduction-to-building-efficient-safe-and-readable-web-and-cli-
applications-1st-edition-george-dietrich-48199106

A Webbased Approach To Measure Skill Mismatches And Skills Profiles


For A Developing Country The Case Of Colombia Jeisson Arley Crdenas
Rubio

https://ebookbell.com/product/a-webbased-approach-to-measure-skill-
mismatches-and-skills-profiles-for-a-developing-country-the-case-of-
colombia-jeisson-arley-crdenas-rubio-54746500

Satveg A Webbased Tool For Visualization Of Modis Vegetation Indices


In T South America Jlio Csar Dalla Mora Esquerdoa

https://ebookbell.com/product/satveg-a-webbased-tool-for-
visualization-of-modis-vegetation-indices-in-t-south-america-jlio-
csar-dalla-mora-esquerdoa-23506924
Unemployed But Moving On Smart Job Searching In A Webbased World And A
Sucky Economy Cheryl Butler Long

https://ebookbell.com/product/unemployed-but-moving-on-smart-job-
searching-in-a-webbased-world-and-a-sucky-economy-cheryl-butler-
long-46411648

Theplete Emerce Booksign Build And Maintain A Successful Web Based


Business 2nd Edition Janice Reynolds

https://ebookbell.com/product/theplete-emerce-booksign-build-and-
maintain-a-successful-web-based-business-2nd-edition-janice-
reynolds-1304934

How To Open Operate A Financially Successful Webbased Business 1st


Edition Beth Williams

https://ebookbell.com/product/how-to-open-operate-a-financially-
successful-webbased-business-1st-edition-beth-williams-48777848

A Web Of New Words A Corpusbased Study Of The Conventionalization


Process Of English Neologisms 1st Edition Daphn Kerremans

https://ebookbell.com/product/a-web-of-new-words-a-corpusbased-study-
of-the-conventionalization-process-of-english-neologisms-1st-edition-
daphn-kerremans-5220028

Advances In Webbased Learning Icwl 2019 18th International Conference


Magdeburg Germany September 2325 2019 Proceedings 1st Ed 2019 Michael
A Herzog

https://ebookbell.com/product/advances-in-webbased-learning-
icwl-2019-18th-international-conference-magdeburg-germany-
september-2325-2019-proceedings-1st-ed-2019-michael-a-herzog-10801642
A Web-Based Introduction
to Programming

2
A Web-Based Introduction
to Programming

3
Essential Algorithms, Syntax,
and Control Structures Using PHP, HTML,
and MariaDB/MySQL

Fourth Edition

Mike O'Kane

4
Copyright © 2017
Mike O'Kane
All Rights Reserved.

Library of Congress Cataloging-in-Publication Data

Names: O'Kane, Mike, 1953- author.


Title: A web-based introduction to programming : essential algorithms,
syntax, and control structures using PHP, HTML, and MariaDB/MySQL / Mike
O'Kane.
Description: Durham, North Carolina : Carolina Academic Press, [2017] |
Includes bibliographical references and index.
Identifiers: LCCN 2017017694 | ISBN 9781531002749 (alk. paper)
Subjects: LCSH: Computer software--Development. | Internet programming. |
Computer programming--Web-based instruction. | PHP (Computer program
language) | XHTML (Document markup language)
Classification: LCC QA76.76.D47 O43 2017 | DDC 005.3--dc23
LC record available at https://lccn.loc.gov/2017017694

eISBN 978-1-53100-707-2

Carolina Academic Press, LLC


700 Kent Street
Durham, North Carolina 27701
Telephone (919) 489-7486
Fax (919) 493-5668

www.cap-press.com

Printed in the United States of America.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any
means, electronic, mechanical, recording or otherwise, without the prior written permission of the author.

Please note: The information in this book is provided for instructional value and distributed on an “as is” basis,
without warranty. While every precaution has been taken in the preparation of the book, neither the author nor
Carolina Academic Press shall have any liability to any person or entity with respect to any loss or damage caused
by or alleged to be caused, directly or indirectly, by the instructions contained in this book or by the programs or
applications that are listed in, or provided as supplements to, this book.

Macintosh®, Mac OS®, Safari, and iOS® are registered trademarks of Apple, Inc. in the United States and other
countries. Windows® and Windows Mobile® are registered trademarks of Microsoft Corporation in the United
States and other countries. Linux® is the registered trademark of Linus Torvalds in the United States and other
countries. MySQL® is a registered trademark of Oracle Corporation and/or its affiliates. MariaDB® is a registered
trademark of MariaDB Corporation Ab. Mozilla® and Firefox® are registered trademarks of the Mozilla
Foundation. Joomla!® is trademarked by Open Source Matters. Apache® is a trademark of the Apache Software
Foundation. XAMPP and Apache Friends are registered trademarks of BitRock. The WordPress® trademark is
owned by the WordPress Foundation. Android® and Google Chrome® are trademarks of Google Inc. The Drupal®
trademark is owned and controlled by Dries Buytaert. BlackBerry® is a trademark of Blackberry. All product
names identified in this book are trademarks or registered trademarks, and are the properties of their respective
companies. We have used these names in an editorial fashion only, and to the benefit of the owner, with no

5
intention of infringing the trademark.

6
To my dear mother and father,
thank you for the love and light that you bestowed on us.

7
Contents

Preface
Acknowledgments
About the Author

Chapter 1 · Introducing Computer Programming


Introduction
What Is a Computer Program?
What Do Programmers Do?
The Software Development Life Cycle
The Importance of Writing and Communicating
What Are Programming Languages?
Compilers and Interpreters
So Many Languages!
Standalone and Network Applications
Markup Languages
Combining Markup and Programming Languages
Summary
Chapter 1 Review Questions

Chapter 2 · Client/Server Applications—Getting Started


Introduction
Client/Server Design in Web Applications
Working with Files and Folders
Locating Files and Folders on Computers Running a Windows Operating System
Locating Files and Folders on the Internet
Internet Naming Conventions for Files and Folders
Working with a Local Web Server
What Languages Will I Use?
What Software Will I Need?
Installing a Text Editor
Installing One or More Web Browsers
Installing Your Web Server
Using Your Web Server
Using URLs with Your Web Server
Always Use URLs to Run Your Web Applications!
Where to Save Your Work Files
The Importance of Frequent Backups
Creating an HTML Document
Creating a PHP program

8
Creating an Interactive HTML and PHP Program
Summary
Chapter 2 Review Questions
Chapter 2 Code Exercises

Chapter 3 · Program Design—From Requirements to Algorithms


Introduction
What Are Instructions?
Common Characteristics of Instructions
Sequence, Selection and Repetition Structures
A Programming Example
Creating an Input, Processing, Output (IPO) chart
Designing the User Interface
Developing an Algorithm
A Smoking Calculator
Coding the Application
Summary
Chapter 3 Review Questions
Chapter 3 Code Exercises

Chapter 4 · Basics of Markup—Creating a User Interface with HTML


Introduction
A Short History of HTML
Introducing HTML Tags
Ignoring White Space
More HTML Tags
Introducing HTML Tables
Using HTML Tables to Layout Web Pages
Other HTML Tags
Deprecated HTML Tags
Introducing Style Sheets
Multiple Styles for a Single Tag
Selecting Colors for Fonts and Backgrounds
Referencing a Style Sheet in Your HTML Document
Applying a Style Sheet to Multiple Pages
Interactive User Interfaces
Creating HTML Forms
Using HTML Forms to Obtain User Input
Using HTML Tables to Line Up Prompt and Input Boxes
Problems with Form Submission
Drop Down Lists
Combining Textboxes and Drop Down Lists
Other Types of Input
Stylesheets and Forms

9
Summary
Chapter 4 Review Questions
Chapter 4 Code Exercises

Chapter 5 · Creating a Working Program—Basics of PHP


Introduction
Why PHP?
Working with HTML and PHP
Important Features of Client/Server Programs
Receiving Input from a Form — wage2.php
Processing the Smoking Survey — smoking.php
PHP — General Guidelines and Syntax
Arithmetic Expressions
Using Arithmetic Functions
White Space in PHP Files
Generating Character Strings from PHP
Including Double Quotes in Character Strings
Using Multiple PHP Sections
Using the number_format() Function to Display Numbers to a Specific Number of Places
Including Calls to PHP Functions inside PHP Print Statements
String Concatenation and the Concatenation Operator
The PHP Echo Statement
Finding Syntax Errors
Finding Logical Errors
Summary
Chapter 5 Review Questions
Chapter 5 Code Exercises

Chapter 6 · Persistence — Saving and Retrieving Data


Introduction
The Difference Between Persistent and Transient Data
Files and Databases
Working with a Text File
Closing a Text File
Reading Data from a Text File
PHP Functions to Read Data from a Text File
Writing Data to a Text File
PHP Functions to Write Data to a Text File
Be Careful to Avoid Security Holes!
Using Escape Characters
Escape Characters and HTML Tags
Using PHP to Append Data to Files
PHP Functions to Append Data to a Text File
Processing Files that Contain Complete Records on Each Line

10
PHP Functions to Parse a Delimited Character String
Processing a File with Multiple Records
Appending Records to a File
Working with Multiple Files
Summary
Chapter 6 Review Questions
Chapter 6 Code Exercises

Chapter 7 · Programs that Choose — Introducing Selection Structures


Introduction
Introducing IF and IF..ELSE Structures
Introducing Flow Charts
Boolean Expressions and Relational Operators
Selection Using the IF Structure
Testing Threshold Values
Selection Using the IF..ELSE Structure
When to Use Braces in IF..ELSE Statements
Creating a Program with Multiple but Independent Selection Structures
Comparing Strings — Testing for a Correct Password
Ignoring the Case of a Character String
Providing a Selective Response
Using Selection to Construct a Line of Output
Summary
Chapter 7 Review Questions
Chapter 7 Code Exercises

Chapter 8 · Multiple Selection, Nesting, ANDs and ORs


Introduction
Introducing the Logical Operators AND and OR
Introducing the NOT Operator
Validating User Input
Using A Nested Selection Structure to Validate Input
Designing Applications with Nested Selection Structures
Use of Braces in Nested Selection Structures
Chaining Related Selection Structures
Additional Input Validation Using Chained Selection Structures
More about Input Validation: Using the trim() Function
When to Use AND or OR? Be Careful with Your Logic!
The Challenge of Software Testing
A Special Case: The Switch Statement
More Examples in the Samples Folder
Some Words of Encouragement
Summary
Chapter 8 Review Questions

11
Chapter 8 Code Exercises

Chapter 9 · Programs that Count — Harnessing the Power of Repetition


Introduction
Controlling a Loop by Counting
Coding a FOR Loop in PHP
General Syntax of a FOR Loop
Including the Counting Variable in Your Loop Statements
Using a Variable to Control the Loop Condition
Converting from Celsius to Fahrenheit
Changing the Increment Value
Using Loops with HTML Tables
Allowing the User to Control the Loop
Improving Processing Efficiency
Using Loops to “Crunch Numbers”
Using a Loop to Accumulate a Total
Finding the Total and Average from a File of Numbers
Finding the Highest and Lowest Values in a Series
Performing Multiple Operations on a File of Numbers
Nesting IF..ELSE Structures to Customize Output from a Loop
Loops within Loops — Creating a Bar Chart
Selecting from a List of Data Files
Summary
Chapter 9 Review Questions
Chapter 9 Code Exercises

Chapter 10 · “While NOT End-Of-File”—Introducing Event-Controlled Loops


Introduction
Characteristics of WHILE Loops
The Structure of WHILE Loops
An Algorithm to Process Files of Unknown Length
Using a WHILE Loop to Process a File of Scores
Including Selection Structures Inside a WHILE Loop
Using a WHILE Loop to Count, Sum and Average Data
Using a WHILE Loop to Process a File of Records
Processing Weekly Wages from a File of Timesheet Records
Processing Selected Records from a File of Timesheet Records
Processing Selected Fields from a File of Records
Processing a File of Survey Data
Using DO..WHILE or REPEAT..UNTIL Loops
Summary
Chapter 10 Review Questions
Chapter 10 Code Exercises

12
Chapter 11 · Structured Data — Working with Arrays
Introduction
What Is an Array?
Working with Array Elements
Extending an Array
Displaying Array Values
Receiving Scores into an Array from an HTML Form
Arrays of Strings
How Large Is the Array?
Why Do Array Indices Begin with 0 and Not 1?
Using FOR Loops with Arrays
Using the sizeof() Function to Control a FOR Loop
Summing and Averaging the Values in an Array
Counting Selected Values in an Array
Multiple Operations on an Array
Reading Data from a File into an Array
Reading Data into an Array from a File of Unknown Length
Using [] with no Index Value
Reading Selected Data from a File into an Array
Reading Data from a File into Multiple Arrays
Reading Selected Data from a File of Records into an Array
More About the explode() and list() Functions
A Special Loop for Processing Arrays — FOREACH
Multi-Dimensional Arrays
Summary
Chapter 11 Review Questions
Chapter 11 Code Exercises

Chapter 12 · Associative Arrays


Introduction
Using a Variable to Reference the Key of an Associative Array
Using Associative Arrays as Lookups
Using the array() Function to Create Associative Arrays
Associative Arrays and the FOREACH Loop
More about the $_POST Array
Using the isset() Function to Combine a Web Form with the Form Processing Code in a Single Page
Web Sessions and the $_SESSION Array
Adding Code to Manage a Web Session
Creating, Initializing and Modifying Session Variables
Validating $_SESSION and $_POST Arrays
Revisiting the Same Page in a Web Session
Summary
Chapter 12 Review Questions

13
Chapter 12 Code Exercises

Chapter 13 · Program Modularity — Working with Functions


Introduction
Using Functions
Understanding Function Arguments
Receiving Values from a Function
Researching Available Functions
Reasons to Use Pre-Defined Functions
Using die() or exit() to Terminate an Application
Creating Your Own Functions
Where Do I Put My Functions?
Creating a Library of Functions
Including Functions from External Files
Using the Same Functions in Different Programs
Functions Calling Functions
Learning to Think Beyond Specific Applications
More about Include Files
Summary
Chapter 13 Review Questions
Chapter 13 Code Exercises

Chapter 14 · Connecting to a Database — Working with MySQL


Introduction
What Is a Relational Database?
The Relational Database Management System (RDBMS)
Structured Query Language — MySQL
Starting Your MySQL Server
Configuring MySQL for Use with This Textbook
Three Ways to Work with MySQL
Working with PHP and MySQL
Using PHP to Open and Close a Connection to a MySQL Server
Using the MySQL SELECT Query
Selecting Specific Records
Relational Operators in MySQL
The Logical Operators AND and OR
Ordering Your Query Results
Viewing Your Query Results
Using an HTML Table to Display the Query Results
Putting It All Together
Using Input from an HTML Form to Construct a Query
Processing Queries with a Single Result
Performing Calculations with the Result Set
Performing Aggregate Operations on MySQL Queries

14
Performing JOIN Operations on Multiple Tables
Using INSERT to Add Records to a Table
Using UPDATE to Modify a Record
Removing a Record
Storing MySQL Connection Data in an Include File
Creating, Dropping, and Altering Databases and Tables
Summary
Chapter 14 Review Questions
Chapter 14 Code Exercises

Chapter 15 · Introduction to Object-Oriented Programming


Introduction
What is an Object?
Creating and Using Instances of a Class
Using Employee Objects in an Application
Defining an Object
Coding the Object Class
Creating and Using Instances of an Object Class
The Class Constructor Method
Method Overloading
Why do Objects Matter?
Object Design and Inheritance
Abstract Classes and Methods
Method Over-riding
Polymorphism
OOP and Databases
OOP Development
OOP Languages
Summary
Chapter 15 Review Questions
Chapter 15 Code Exercises

Chapter 16 · Where to Go from Here . . .


Introduction
Moving Forward with PHP and HTML
More about PHP
PHP and Other Languages
XHTML and XML
Client Side Processing with Javascript and Ajax
The Importance of OOP
IDE's, Modeling Languages and Frameworks
Client/Server and Server/Server Programming
Mobile Applications
Digital Media

15
Graphical User Interfaces and Interface Design
Web Design and Content Management
Database Programming and SQL
In Summary: Follow Your Heart!

Appendix A · Data Representation and Formats


Introduction
Storing Data in Bits and Bytes
How Multimedia Data Is Represented in Binary
How Numeric Values Are Represented in Binary
How Plain Text Is Represented in Binary
How Source Code and Markup Code Is Represented in Binary
How Program Instructions Are Represented in Binary
How Memory Addresses Are Represented in Binary
What Else Can Be Represented in Binary?

Appendix B · Files, Folders, Addressing Schemes, and Command Line Arguments


File Types and File Extensions
Disk and Disk Drives
Files and File Folders (Directories)
Naming Files and Folders
File Addresses in Windows and on the Web
Relative Addresses in Windows
Relative Addresses on the Internet
Using Relative Web Addresses in HTML Code
Managing Files at the Command Line
Introduction to MS DOS Commands
Recalling Previous Commands
Use Double Quotes when Paths Include Spaces
Printing the Contents of the Console Window
Creating Batch Files
Unix Commands

Appendix C · Installing and Running Your Standalone Web Server


Using an Active Web Server
Problems Using Your Web Server
Advanced Users

Appendix D · Debugging Your Code


Problems Viewing Your HTML or PHP Programs
Problems with HTML Layout
Locating PHP Syntax Errors
Common PHP Syntax Errors
Common Logical Errors

16
Appendix E · More about HTML and CSS
Useful HTML References
Useful CSS References
Inline Styles and Internal Style Sheets
Deprecated HTML Tags
Frequently Asked Questions Regarding HTML Tags

Appendix F · More about PHP Functions and Data Types


Useful PHP References
More about PHP Functions and Data Types
Standard PHP Array Functions
Standard PHP File Functions
Standard PHP Math Functions
Standard PHP String Functions
PHP Data Types

Appendix G · Additional PHP Operators and Control Structures


Shortcut Operators
Switch Structure
Another Loop Structure: DO..WHILE
Multi-Dimensional Arrays
Ragged Arrays
Multi-Dimensional Associative Arrays

Index

17
Preface

The problem I have tried to solve with this textbook is, quite simply, how to effectively introduce general
programming concepts to students who have never programmed before. Perhaps like me, you have found yourself
frustrated by textbooks that try to cover too much too fast, make inappropriate assumptions about what a student
already knows, or take sudden leaps in complexity when providing examples and exercises.
I believe that the purpose of an introductory programming course is to help students gain confidence and
develop their understanding of basic logic, syntax, and problem-solving. They do not need to learn all aspects of a
language or even learn best practices—these are topics for the next course level. The question is: how to provide
the kind of hands-on experience that supports active learning without overwhelming the beginning student with
too much syntactical and programmatic detail?
I have tried many approaches over the years before settling on a Web-based approach, using PHP, CSS, and
HTML code to develop small, interactive Web applications. This approach has proved very successful. Many
students report how much they enjoy the course, how much they have learned, and how well the material has
served them in subsequent courses and in their professional life. I also hear from many students who tell me that
the course positively changed their opinion of programming as a career or subject of interest, which is most
gratifying.
Some instructors may have concerns that my coverage of the PHP and HTML is insufficient. The book uses a
small number of HTML tags, CSS rules, and PHP functions, and employs some arbitrary conventions to simplify
the code and keep the focus on basic concepts common to most languages. For example, PHP print statements
are used rather than echo statements, and these statements always include parentheses and double quotes so that
the syntax is more consistent with the output statements of most other languages. The last chapter (“Where to Go
From Here”) clarifies which practices are standard and which are particular to the textbook.

18
Intended Audience
The book is designed to serve:

Instructors teaching introductory programming, programming logic and design, or Web programming
courses, who want a textbook that engages students and provides a solid preparation for subsequent courses,
but avoids overwhelming beginners with too much syntactical detail or program complexity.
Traditional and online students taking a first course in programming, programming logic and design, or
Web programming.
Web designers, graphic artists, technical communicators, and others who find that their work increasingly
requires some degree of programming expertise, and need an effective, hands-on introduction.
Others who wish to learn the basics of programming, either for personal interest, or to explore the
possibility of a career in this field.

Note that solutions to quizzes and exercises are only available to verified course instructors.

19
Approach
The book takes a fairly novel approach, allowing students to learn program logic and design by developing a large
number of small Web-based applications. Students love working with the Web, and this approach has other
important benefits:

Important concepts such as client/server design, server-side processing, and interface-driven code modules
can be introduced in the form of working applications, and then applied in hands-on exercises.
Students not only learn the essential control structures and syntax of a programming language, but also learn
to use a markup language (and associated style sheets), and a database query language to access and query a
database. This makes sense in today's programming environment where these languages are routinely used
in combination to develop a networked application.
The material is relevant to students across a range of disciplines: Computer Science, Information Systems,
Technical Communications, Network Systems, Digital Media, Web Technologies, Mobile Applications,
Database Programming, and other technology-related fields.
The focus on hands-on problem-solving and fundamental structures prepare students for next-level,
language-specific courses such as PHP, Python, Java or C++, as well as Web design and database courses,
without replicating a great deal of material, while the syntax covered here is generally consistent with these
and other languages.

The book makes use of a programming language (PHP), a scripting language (HTML), a style sheet language
(CSS), and a database query language (MariaDB or MySQL), but does not attempt to provide a complete
overview of these languages. Instead, students learn sufficient syntax to convert requirements into working
applications using basic programming structures, arithmetic and logical expressions, user interfaces, functions,
data files, and SQL queries. The focus remains on basic concepts, logic and design, algorithm development, and
common programming procedures. The book provides context throughout, explaining why each topic is
important, and referring students to related career paths.
Although the book focuses on Web-based applications, there is NO requirement for a network-based
programming environment. The book uses a fully functional but standalone Apache Web server (the open source
xampp distribution provided by the Apache Friends group) that students can install on a USB drive or home
computer simply by unzipping a file. Students can begin programming in HTML, PHP and MariaDB or
MySQL in literally minutes.

20
Features
Each chapter begins with clearly stated learning outcomes. Each topic is introduced using examples of simple
program requirements that are first developed as algorithms and interfaces and then realized in working code.
Code statements and control structures are explained step by step.
Different programming topics are treated in separate chapters. Even topics that are commonly combined, such
as counting loops and event-controlled loops, have their own chapters so that students have the chance to develop
and apply their understanding of each separately.
Each chapter includes quizzes that have been carefully developed to test the student's understanding of the
chapter's learning outcomes. The questions have been tested extensively in the classroom.
Three different types of coding exercise are provided at the end of each chapter:

Fixit exercises provide small programs that include a single error of some kind. These exercises help students
improve their problem-solving ability, test their understanding of key concepts, and develop tracing and
debugging skills.
Modify exercises provide working programs that must be modified to perform a somewhat different or
additional function. These exercises help students determine how and where to add new code, and test their
ability to read and understand existing code.
Code completion exercises allow students to apply concepts and tools covered in the chapter by developing
new applications. These exercises test the student's ability to: understand requirements, develop algorithms,
and produce working code. The code completion exercises follow consistent themes that are developed
throughout the book, so that students can more readily appreciate the value of new functionalities that they
learn in each chapter.

Templates for each exercise contain partially completed code so students don't waste time typing (and debugging)
code that is not relevant to the problem at hand. The templates also help instructors to streamline the grading
process.
The textbook comes with a standalone Web server that can be installed on a fixed or portable drive simply by
unzipping a file (so students can bring the software with them to work on computers at any location).
The server installation includes textbook folders that contain all code samples and exercise templates. Students
can complete the exercises simply by opening, editing, and saving the appropriate files. Assignments can be turned
in simply by zipping and submitting the appropriate chapter folder.
The textbook appendices provide additional learning resources designed to: (a) help individual students with
particular needs or interests (for example file/folder management, additional references, and help debugging
code); and (b) deliver useful topics not included in the chapters (for example data representation, additional
control structures, and multi-dimensional arrays).

21
Textbook Web Site
The textbook Web site ensures that both students and instructors have access to the most current resources
associated with this textbook. The Web site includes: everything you need to install and use the Web server; slide
presentations; and hints and help for students working through each chapter. The Web site also provides support
for verified instructors, including additional exercises, test banks, slide presentations, quiz solutions, code
solutions, and other instructional resources. The Web site can be found at:
http://www.mikeokane.com/textbooks/WebTech/

22
Changes to the Fourth Edition
In addition to minor corrections and improvements, this fourth edition of the book includes: a new install of the
xampp Apache Web server distribution with installation instructions for Windows, Mac OS, and Linux; revised
file naming conventions that are more standard for current web development; a hopefully improved redesign of
Chapters 7 and 8; additional materials and improvements to Chapter 13 (functions); references to both MySQL
and MariaDB in Chapter 14 (the actual code and descriptions are identical); a new Chapter 15 that introduces
Object-Oriented Programming.

23
Chapter Overview
Chapter 1: Introducing Computer Programming. Students learn the relationship between machine language
and high-level languages, and review common tasks that computer programs typically perform. The work of a
programmer is described, and the software development cycle is explained. The chapter highlights and briefly
summarizes design approaches such as algorithm development, interface design, client/server design and object-
oriented programming. Different programming languages are identified, and the distinction is made between
interpreted and compiled languages, and between markup and programming languages. Standalone and network
applications are also contrasted.
Chapter 2: Client/Server Applications—Getting Started. This chapter prepares students for the hands-on
work they will perform in subsequent chapters. File types and local and Internet addressing schemes are explained.
Instructions are provided to install, run, and test the required software. Students are shown how to create, store,
and run a number of sample applications in order to become familiar with the process of using a text editor,
saving files, running the Web server, and viewing the results in a Web browser.
Chapter 3: Program Design—from Requirements to Algorithms. The general characteristics and
requirements of effective instructions are explored, using human and program examples. Students walk through
the process of reviewing simple requirements, creating input, processing, and output (IPO) charts, designing the
interface, and developing solution algorithms. The chapter introduces sequence, selection and control structures,
variables and assignment operations, and arithmetic and logical expressions.
Chapter 4: Basics of Markup—Creating a User Interface with HTML. This chapter explains the significance
of data rendering, and provides a brief overview and history of Hypertext Markup Language (HTML).
Commonly used HTML tags are explained, and the student is shown how to apply these to create and organize
simple Web pages. Cascading style sheets are introduced. Students are shown how to create HTML forms to
obtain user input as a first step in developing interactive Web applications. HTML Tables are used to perform
simple form layout.
Chapter 5: Creating a Working Program—Basics of PHP. This chapter teaches sufficient PHP language
syntax to process user input received from HTML forms, perform simple arithmetic, and produce formatted
output. In the process, students learn to code arithmetic expressions, use standard operators and functions, create
and work with variables, and identify and fix both syntax and logical errors.
Chapter 6: Persistence—Saving and Retrieving Data. This chapter explains the difference between persistent
and transient data, and introduces text file processing as well as basic database concepts. Students learn to: open,
read, write, and close text files; work with multiple files; parse lines of data that contain multiple values separated
by some kind of delimiter.
Chapter 7: Programs that Choose—Introducing Selection Structures. This chapter introduces selection
control structures and demonstrates the use of algorithms to solve problems requiring simple selection. Students
learn to use IF and IF..ELSE structures, Boolean expressions, relational operators, truth tables, simple string
comparisons, and testing procedures.
Chapter 8: Multiple Selection, Nesting, ANDs and ORs. This chapter develops examples from Chapter 7 to
handle problems associated with input validation and more complex requirements. Students explore the use of
compound Boolean expressions, nested selection structures, chained IF..ELSEIF..ELSE selection structures, and
multiple but independent selection structures.
Chapter 9: Programs that Count—Harnessing the Power of Repetition. This chapter introduces loop
structures with a focus on count-controlled FOR loops. Students learn how to refer to the counting variable
within the loop, and how to use loops to generate tables, crunch numbers, accumulate totals, find highest and
lowest values in a series, select values from a file of records, and display bar charts.
Chapter 10: “While NOT End-Of-File”—Introducing Event-Controlled Loops. This chapter introduces
WHILE loops and demonstrates the use of the priming read and the standard algorithm to process files of
unknown length. The student is shown how WHILE loops can be used to perform various operations on a list of

24
data values, and how a file of records can be processed and searched for specific records or field values.
Chapter 11: Structured Data—Working with Arrays. This chapter introduces numerically-indexed arrays,
and shows how arrays can be used to store, access, and update multiple-related values. The use of the FOR loop
to process arrays is explained, and various array-processing algorithms are demonstrated.
Chapter 12: Associative Arrays. This chapter introduces associative arrays. Students learn how to use
associative arrays as lookups, and gain a better understanding of the $_POST array and the way that data is
received from HTML forms. Web sessions are introduced, and students learn how to use the $_SESSION array
to maintain session data between applications.
Chapter 13: Program Modularity—Working with Functions. This chapter demonstrates the importance of
program modularity and introduces functions, include files and objects. Students learn to write their own
functions, to build libraries of related functions, and to call functions from different applications as needed.
Chapter 14: Connecting to a Database—Working with MySQL. This chapter introduces databases queries
as an important application tool. The relationship between relational databases and SQL is explained, along with
the purpose and syntax of common queries (SELECT, INSERT, UPDATE and DELETE). Students learn to
write code to open and close database connections, submit queries, handle errors, perform simple joins, and
process results.
Chapter 15: Introduction to Object-Oriented Programming. This chapter introduces Object-Oriented
Programming. Examples show how simple object classes are designed, how class variables are encapsulated and
accessed by class methods, how objects are instantiated and used in applications, and how classes can be inherited
by other classes. An overview of basic OO terminology is provided.
Chapter 16: Where to Go From Here. This last chapter provides a short overview of key concepts and
technologies that the students may want to explore after completing this textbook, along with clarification of
some of the conventions followed in the book.
The textbook also includes a number of useful appendices as follows:
Appendix A introduces data representation, and shows how binary values can store data for a wide range of
purposes.
Appendix B provides an introduction to overview of file and folder management, file addressing schemes
(including relative and absolute addresses), and the use of the command line with a list of common DOS and
Unix command equivalents.
Appendix C provides help for students wishing to use different Web server installations.
Appendix D provides debugging help for students having trouble identifying and resolving PHP code errors.
Appendix E provides additional material and references for students wishing to learn more about HTML and
style sheets.
Appendix F provides additional information regarding PHP data types, and provides a list of common PHP
functions not covered in the book.
Appendix G provides additional coverage of common PHP operators and structures that were omitted from
the chapters to avoid overwhelming the beginning student (for example, shortcut operators, the SWITCH
statement, DO..WHILE loops, and multi-dimensional arrays).

25
Acknowledgments

This textbook could not have been created without the generous help and support of many others. In particular I
want to thank my dear wife Constance Humphries for her invaluable technical advice, proof-reading,
development of video tutorials, and daily encouragement and patience! My sincere thanks to Scott Sipe, Beth
Hall, Sara Hjelt, and all at Carolina Academic Press for their supportive style, professionalism and experience.
Thanks to all my fellow instructors at A-B Tech (Asheville-Buncombe Technical Community College), especially
to Charlie Wallin and Fred Smartt who field-tested the first edition, and provided invaluable suggestions and
corrections. And thanks to all of those students who have learned with me and sometimes in spite of me as this
book evolved in the classroom. A particular thank you to A-B Tech students Uma Benson, Jean-Jacques Maury,
and Kenneth Stanley, who all voluntarily provided me with carefully compiled lists of corrections that were
incorporated into the fourth edition. Their engagement with the material and concern for future students is
greatly appreciated. Any remaining errors or inconsistencies are of course my own.
Lastly, a huge thank you to Kai ‘Oswald’ Seidler, Kay Vogelgesang, and all those who have contributed to the
Apache Friends Project, and who continue to deliver and support the XAMPP distribution. So many of us owe
you our great appreciation for your generosity of spirit!

26
About the Author

Mike O'Kane holds a master's degree in Systems Science (specializing in Advanced Technology) from
Binghamton University. He has over eighteen years' experience teaching computer science courses, most recently
at Asheville-Buncombe Technical Community College in North Carolina. He also has extensive practical
experience in the use of technology for learning, having worked at IBM as a short-course developer, NC State
University as an Instructional Coordinator, and the University of North Carolina system as the first Executive
Director of the UNC Teaching and Learning with Technology Collaborative. He has a passion for developing
effective instructional content, and learning environments that promote rather than hinder student learning.

27
Chapter 1

Introducing Computer Programming

Intended Learning Outcomes


After completing this chapter, you should be able to:

Explain the difference between computers and other machines.


escribe the purpose of the microprocessor's instruction set.
Explain the relationship between the instruction set and machine language.
List some common tasks that computer programs perform.
escribe what programmers do.
Summarize the stages of the software development cycle.
Explain the importance of writing and communications for programmers.
Explain the relationship between high-level programming languages and machine language.
istinguish between the purpose of a compiler and an interpreter.
Explain the difference between standalone and network applications.
Explain the difference between programming languages and markup languages.

28
Introduction
Welcome! If you have never programmed before, this book is for you. By the time you complete the chapters and
exercises, you will have a good grasp of the basic logic and design of computer programs. The book is designed to
teach common programming syntax and control structures in a manner that will prepare you for further study in
this field, and provide you with sufficient expertise to develop small, interactive Web applications, using a
combination of the HTML markup language and PHP programming language. You will also be introduced to
the CSS stylesheet language, and the MariaDB and MySQL database languages.
To get started, in this first chapter we will explore the general process of programming and define some
important term and practices. For a book that is supposed to be hands-on this chapter is mostly descriptive! Don't
be too concerned if some of the topics don't make complete sense yet. Your understanding will deepen as you
work through the chapters and develop your own applications.

29
What Is a Computer Program?
A computer is a programmable machine. Computers can perform any number of tasks by reading and executing
computer programs, or software. Each computer program contains instructions to direct the computer's
operating system and hardware for a specific purpose. The ability to read and execute programs is achievable
because each computer contains a microprocessor which includes the computer's instruction set. The instruction
set defines all of the basic commands that the computer can execute. These basic commands are very low-level
activities such as adding numbers, moving a piece of data from one location to another, or comparing values. The
commands that make up the instruction set constitute the computer's machine language. Your programs work
with the computer's operating system to issue commands to the microprocessor, so a computer program is
essentially a set of instructions that tell the microprocessor to execute machine language commands in a particular
sequence in order to provide a game, a Web browser, a business application, an email program, or some other
useful service. If you've ever wondered why some programs run on one computer but not another, it is because
different computers have different microprocessors and different operating systems.
Although different computer programs serve quite different purposes, all programs share some important
characteristics. Here are some common tasks that any computer program might typically perform:
Provide interactive environments for users: programs may use text-based input/output or Graphical
User Interfaces (GUI's) to interact with users. Interfaces may include graphics, animations, audio,
video, and other multimedia features.
Read and write data: programs may access, create, modify or delete data that is stored in files and
databases.
Perform numerical calculations: programs can add, subtract, multiply, divide, and compare numbers,
and can combine these operations to perform much more complex calculations.
Perform text-processing operations: programs can validate, convert, search, sort, compare, and replace
text, and can construct reports, messages or documents such as this textbook.
Communicate with other programs and devices: programs may exchange data with other programs,
cameras, scanners, Web browsers, satellites, cell phones, ATM machines, etc.
Control hardware: programs can control robots, satellites, aircraft, automobiles, printers, and other
computers.
A single computer program may perform any combination of these operations. For example a computer game
may look up player and game information in a file or database, provide an interactive multimedia environment
for the player to play the game, perform numerical calculations, and communicate with programs running on
other computers to allow multi-user play over the Internet. Similarly a payroll program may perform text-
processing operations (such as validation and conversion), query and modify a database, perform numerical
calculations, and send checks to a printer. What this means is that, as a programmer, you will want to know how
to write programs that might include any or all of these operations.

30
What Do Programmers Do?
Programmers write program code, right? Well, actually programmers do a lot more than write code, and many
programmers actually write very little code. One of the things that makes programming an attractive career for
many men and women is that this work requires an appealing combination of right-brain (creative, problem-
solving, brain-storming) and left-brain (logical, linear, sequential) activities. Another appeal is that there are a
variety of career paths within the field, so if you have a general aptitude you have a good chance of finding work
suited to your personal interests. For example if you like to work with people you may find yourself drawn to
software design, interface development, usability, or training. If you prefer to work with data, you may prefer
server-side application development, object design, or database administration.
Let's walk through the major stages in software development. This will clearly demonstrate the range of skills
that programmers need in order to be successful in their work. Here we will simply summarize these steps so
don't be concerned if this appears a little abstract right now. We will learn how to apply these steps to develop a
working application in Chapter 3.

1. Evaluation of Requirements
In order to develop an effective software application we first need to determine the program's requirements. This
usually requires careful reading and listening, asking questions, and careful documentation. Understanding and
documenting requirements takes time and skill. A common mistake that beginning (and not just beginning)
programmers make is to rush this important step in order to begin coding. Rushing the requirements phase can
actually be very costly in terms of time, money and even professional relationships. So learn to go slowly and
carefully when you are presented with a requirements document or when you first meet with a client. The more
time you spend analyzing your program requirements (and asking questions if you are unsure about anything),
the more easily the solution will appear. Remember: the most important skills a programmer needs at this phase
are to listen, read, ask questions, document carefully, and communicate effectively with clients, managers, and
other programmers.

2. Software Design
Once you have a good idea of the software requirements, it's time to develop the design of your application. This
may be a one-person job in the case of a small application or may involve a design team. Software design can
actually become a career path and some (often the most experienced) programmers spend most of their time
evaluating requirements and designing applications that other programmers will then code.
Unless your requirements are quite simple, your application design will most likely consist of multiple code
segments or modules, each of which can be developed separately. There are many advantages to a modular
approach to software. Each module can be developed and tested separately, often by different programmers or
programming teams. The modules can be developed concurrently which speeds up development time. This
approach also allows each module to be developed by different programmers with the most suitable skills. And a
modular approach promotes reusability: once they have been developed, some of the more useful modules can be
shared by many different applications. Modular design includes the development of testing procedures to test that
each module will perform as expected when it is coded.
Client/server design is an essential feature of Web-based application development. A client application, such as
a Web browser, provides an interface to the user and waits for the user to request a service, for example by
clicking on a link, submitting a URL, or typing a URL. The client application then calls a server application to
process the request and send back a response. When the client application receives the response this is presented
to the user and the process repeats. You participate in a client/server interaction every time you use your Web
browser.
For example, Figure 1-1 shows the screens for a very simple client/server application to calculate an employee's
pay based on their hours worked and hourly wage. This example provides the user with two Web pages. When

31
you type the URL to request the first page, the Web browser sends a request to the appropriate Web server, which
sends back the data to display the page. The first page contains a form. When the user clicks the “Get Your Wage
Report Now” button, the Web browser sends a second request to the Web server that includes the data that the
user has entered into the form. The server executes a program that has been developed especially to process this
data. This program generates the content for the second page, which the server sends back to the browser for
display to the user.

Figure 1-1: A simple client/server interaction

In this book you will develop many small client/server applications similar to the example described above.
Object-Oriented Programming (OOP) provides another modular design approach that is extremely
important for modern application development. OOP allows programmers to share and reuse code very
effectively and to design applications in a very structured and logical fashion, reducing costs and simplifying long
term maintenance. Chapter 15 provides an introduction to this important topic.
Whether your programs are simple or complex, it helps greatly to stay away from a computer in the early
phases of application design! Explore your design ideas using a pen and paper, sticky notes, a white board, even
the backs of napkins! If you go to work as a programmer, you will find that this is how software design teams
usually work. The reason is simple: using disposable materials prevents you from becoming too invested in any
particular approach too quickly and encourages brainstorming and creativity. You will find that sketching out
ideas on paper before you start coding will help you think things through and save you time in the long run.
Once you have a clear idea of what to do you will be ready to develop your algorithms and application structure.
Important skills for software designers are creative thinking, organization, familiarity with data structures, a
background in object-oriented programming, writing documentation, and experience with client-server
programming and interface design.

3. Algorithm Development
Once you have a general design for your application, it is time to develop algorithms for each code module that
the application will need. An algorithm is simply a set of clearly written, unambiguous instructions that have been
developed to perform a task of any kind. Algorithms are a critical component of software design, often written in
pseudocode, a mix of English and programming language syntax that programmers can easily understand. You
will learn to develop algorithms using pseudocode in Chapter 3. The actual work of coding an application is
ideally a fairly straightforward process of converting a carefully developed algorithm into a specific programming
language.
The skills required for these activities include careful attention to detail, logical thinking, documentation
(writing), and general programming experience.

4. Application Coding
This is the activity that is usually associated with programming! The algorithm for each program module is coded
into a programming language. Each module is then carefully tested before the modules are assembled to produce
the complete application. The most important skill required for coding is knowledge of the appropriate

32
programming language, but programmers are expected to also have the experience to develop code efficiently, test
thoroughly, find and fix errors (debugging) and document the code so that other programmers can refer to the
documentation as needed.
Coding, testing, debugging and documenting require patience, thoroughness, and careful attention to detail.

5. Application Testing
Once the application has been assembled, it is time for thorough testing. While the development team may
perform many tests for correctness, it is also important to test for usability. A development team may produce a
terrific application that has been thoroughly tested and debugged but turns out to be a disaster when provided to
end users. Why? Because the end users find the interface confusing and cannot easily perform the tasks that are
most important for their purposes. Usability testing brings the users into the development process and ensures
that the needs and concerns of the user are taken into account before the product is distributed. In the case of
larger applications, usability testing is often undertaken by usability experts who may observe users working with
the product to determine where improvements can be made. In smaller applications, the programmer may simply
work with the client to find problems and get feedback.
Testing takes a great deal of patience, attention to detail, and thoroughness. Usability testing requires good
listening skills, careful observation, and (if you are the programmer) humility! It's very easy for any programmer
to be so focused on his or her own design that the needs of the user become secondary. If you notice yourself
getting impatient with a user who cannot figure out how to use your product, or who wants the software to
perform differently, then it's probably time to step back, pay attention to the user's concerns, and reconsider your
own design assumptions.

6. User Support, Training, Software Maintenance


So now you have a complete and well-tested application. The development process does not end there! You will
also need to develop online or printed manuals and other documentation for use by your end users. You may also
need to deliver some form of training. And the software must be maintained. Users will find problems that must
be corrected, and suggest additions and improvements that will need continued programming support. User
support and training is a career path for those who like to work with non-technical people and who can also
communicate effectively with programmers and software designers.
Important skills are the ability to communicate with both technical and non-technical people, the ability to
listen and to explain (verbally and in writing) procedures clearly and carefully, patience, and often a sense of
humor and willingness to accept constructive criticism!

33
The Software Development Life Cycle
Taken together these activities constitute the software development life cycle:

Evaluation of requirements
Application design
Algorithm development
Application coding
Application testing
User support, training, software maintenance

This is not a precise list—in reality these various stages may not be so neat and sequential, and you will see
somewhat different versions of this process in every programming textbook and in every workplace. Development
teams may implement these various stages differently. But no matter how these stages are defined, no part of the
development cycle should be treated carelessly. As you gain experience as a programmer you will more fully
appreciate the special characteristics and importance of every step. And perhaps you can already see how the field
of software design attracts people who are both creative and logical, who enjoy using both the left and right sides
of their brain equally.

34
The Importance of Writing and Communicating
Documentation and writing are frequently mentioned as important skills for programmers. Documentation is
critical to software development and wherever your own career path takes you in the field of software design and
development, you will need to be able to write carefully and communicate effectively. Clients, designers and
managers must refer to well-written documents that clearly define requirements, design and code specifications.
Everyone involved in the development process must listen carefully and communicate effectively. Programmers
must document their working code so that other programmers can easily read and modify it (often the
programmer who develops a piece of code will not be the programmer who is asked to make changes for the next
version). Programmers must often give presentations to clients or to their team. The testing phase also requires
extensive documentation that indicates what tests were applied, the results of these tests, and how problems were
resolved. Software users will need course manuals and training materials. Lastly all maintenance procedures must
be documented so that a complete record is always available regarding the current state and history of the
software.

35
What Are Programming Languages?
Earlier we explored what a computer program is, and what programmers do, but what about programming
languages? What is a programming language and why are there so many different languages?
As we have seen, a computer program is a sequence of instructions that direct the computer's microprocessor to
execute commands that are available in the microprocessor's instruction set. These low level commands are
expressed in machine language and are very basic, for example to add numbers, or copy a value from one
memory location to another. It would be extremely time-consuming to write instructions in the 0s and 1s of
machine language, and this code would be very error-prone and difficult to debug, maintain, or modify.
Instead of using machine language directly, we develop programs using high-level programming languages.
Examples of current high-level languages are C++, C#, Java, PHP, Python, and Ruby. Examples of older high-
level languages are C, Ada, BASIC, COBOL, Fortran, Pascal, and perl (older does not necessarily mean no longer
used—many applications written in older languages are still in widespread use, and programmers are still needed
to maintain and even update these programs).
A high-level programming language consists of a set of special words, symbols and operators that a programmer
uses to write program instructions. These instructions are often referred to as the program's source code and the
process of writing source code is often simply called coding. High-level languages are quite easy for programmers
to learn, and applications written in these languages can be developed very quickly and efficiently. However the
computer can only understand machine language, so once a program has been written in a high-level language,
the code must then be translated into machine language instructions. There are actually two approaches to
translating high-level code to machine language, either by compiling the code or by interpreting the code. The
approach depends on the programming language that you are using.

36
Compilers and Interpreters
Some programming languages are compiling languages. This means that the entire source code for a program is
converted (or compiled) into an executable file by special software known as a compiler. The executable file that is
produced by the compiler contains the necessary machine language instructions to perform the required task.
Once a program has been compiled into an executable file, the source code is no longer required to run the
program. End users of the program simply receive the executable file. Of course, the programmers keep the source
code in order to perform updates and produce new versions. Usually when you purchase standalone software from
a store you are buying an executable program that has been compiled. Two advantages of compiled programs are:

Compiled programs tend to run faster.


The end user does not have access to the source code (and so cannot change the program).

Since a compiler generates an executable file containing the machine language instructions for a specific
microprocessor and operating system, the source code must be compiled separately for different platforms
(Windows, Macintosh, Linux, etc). Also, each time the source code is modified, the new version must be
compiled again to produce a new executable file. The new executable file must then be distributed to the end
users.
Other programming languages are interpreted languages. Execution of programs written in interpreted
languages is dependent on a special program known as an interpreter. An interpreter reads through the source
code, converting the instructions into machine language and executing them as it does so. Because of this, both
the interpreter and the source code are needed every time that the program is executed since no executable file is
created for later use. One advantage of this approach is that the same source code can be used on any computer:
computers running Windows, Macintosh or Linux operating systems can each use their own language interpreter
to translate the source code into their own specific machine language.
A disadvantage of using an interpreter is that in most cases we do not want to deliver the actual source code to
the end user of the software. But this approach works very well for network-based programs, such as Web
applications, since these programs are not distributed to end users. In these cases, the source code is located on a
Web server and executed each time a request is submitted by a client application, such as a Web browser. The
source code can be modified quickly and easily on the Web server with no need to recompile and redistribute the
software every time a change is made. PHP is an example of an interpreted programming language that is widely
used to develop server-based Web applications.
Some languages provide both compiling and interpreting options, and some languages actually combine
compiling with interpreting stages to achieve greater efficiency and platform independence. A notable example is
the Java language. Java applications are compiled “up to a point” to produce an “almost executable” version in the
form of byte code that incorporates many of the efficiencies of the compilation process, and then Java interpreters
are provided for different platforms so that the same byte code can be distributed for execution on any machine
(Windows, Macintosh, Linux, etc.) in order to achieve platform independence.

37
So Many Languages!
As computer technology evolves, new programming languages are continually developed to take advantage of the
latest hardware and software design strategies. For example new languages were developed to implement the
functionality of object-oriented programming, while others have been developed to facilitate client/server
application development. There are literally thousands of different programming languages and often a computer
programmer is expert in only a few of these. While each programming language has its own special syntax and
characteristics, most languages are very similar in their overall characteristics and functionality, and use the same
basic logical structures to write instructions. We will learn about these common characteristics as we work
through this book. A programmer who is familiar with the general logic of programming, and who has experience
coding in one or two languages can usually learn new languages quite quickly.

38
Standalone and Network Applications
Computer programs can be designed for use on individual machines (as standalone applications), or across
networks (as network applications).
A standalone application is designed to provide a complete service on the local computer, usually the
computer sitting on the user's desk. Standalone applications do not require any network connectivity, interacting
only with the computer's operating system and other utility software on the local machine. If a new version of
the application becomes available, or if updates are required, these must be also installed on every user's computer.
Examples of standalone software are traditional word-processing and spreadsheet applications, image-processing
software, many games, etc. At this time, most of the programs that you install on your local computer are
standalone applications.
Network applications are programs that run partly or entirely on remote computers, linked to the user across a
network of some kind. The more traditional network application was simply installed on a single host computer
and then accessed by many users remotely. Each user that signs on to the host computer is provided a user
interface to work with the application. An increasingly important type of network application is a client/server
application which consists of any number of component programs that work together across a network. Some
components of a client/server application can be installed on a local computer, and perform as client programs.
Other components of a network application are installed on network servers and perform as server programs. The
server-based components respond to requests from client components of the application as needed. At the
minimum the client component usually provides the user interface that allows the user to submit information and
view the results, while the server component does most of the processing.
You are using a client/server application whenever you use your Web browser. The Web browser performs as a
local client component, providing your user interface and allowing you to send requests to server programs all
over the world. So you are using a client/server application whenever you use your Web browser to obtain
information, shop online, or play an online game. Other common examples of client/server applications are
ATM's and e-mail programs.
Client/server applications are becoming more and more common because they allow us to obtain services and
perform tasks without need for special software on our local computer. We can expect to make increasing use of
Web-based client/server applications as bandwidth increases since these require only a local Web browser and an
Internet connection, rather than software that must be installed locally and continually updated. For example we
are now seeing networked versions of word-processing and spreadsheet applications.

39
Markup Languages
So far we have discussed the purpose of programming languages. As you now know, the purpose of a
programming language is to allow a programmer to write instructions that process data. In other words,
programming languages are used to perform operations that read or modify existing data or generate new data for
some purpose (for example to calculate wages, convert temperatures, or keep track of a game player's score).
Another type of language is a markup language. Markup languages are often used in conjunction with
programming languages, but have a very distinct purpose. The purpose of a markup language is to provide
markup instructions (usually in the form of tags) that simply describe data or indicate how data is to be
formatted, or rendered (for example to define how data should be displayed on a Web page, or printed in a
document). Markup languages are defined for a wide range of purposes. For example, your word-processing
program uses a markup language to save formatting instructions with your document as you type a report or
letter.
The markup language that is used to render data for display in Web browsers is Hypertext Markup Language
(HTML). We will learn the basics of HTML in order to format our Web-based applications.

40
Combining Markup and Programming Languages
In this course, you will learn the basics of programming by developing small, Web-based client/server applications
using a programming language known as PHP, one of the most widely used programming languages for this type
of application. Since you will use a Web browser to display your program output, you will also learn the basics of
the HTML markup language to format your application input and output for display in your browser window.

41
Summary
A computer is a programmable machine. The computer's microprocessor includes the computer's instruction set
which defines all of the basic commands that the computer can execute.
Commands to the microprocessor must be issued using the computer's machine language. A computer
program is a set of machine language instructions that execute a sequence of commands to perform a useful task.
Different programs combine common components to achieve their purpose: interactive environments;
read/write operations; numerical operations; text-processing, communication with other programs; control of
hardware.
A software designer/developer requires a range of skills that combine creative problem-solving and logical
processing. Documentation is an important part of the software process so writing and communication are
important skills that are often not associated with this field.
Software development includes a number of stages: evaluation of requirements; application design; algorithm
development; application coding; application testing; user support, training, software maintenance.
Programs are written in programming languages which may be compiled or interpreted. The code containing
the program instructions written in a specific language is known as source code. If the language is a compiler-
based language the source code must be converted into an executable version which is then distributed for use. If
the language is an interpreted language, the source code itself is distributed and this is then executed one line at a
time by a language interpreter.
Some programs are designed to function as standalone applications, which means that they are installed locally
and do not need access to other networks. A copy of a standalone application is required for every user. Network
applications run over networks. A single network application can be installed on one computer and accessed
across a network by many users.
An increasingly important type of network application is a client/server application, where client programs on
local computers send requests to server programs on remote computers. These requests are processed and results
returned to the client. A common example is a Web-based client/server application where a user's Web browser
performs as a client to request services from server applications throughout the world.
Markup languages are not the same as programming languages. Programming languages provide instructions to
process data. Markup languages provide tags to describe or format (render) data.
In this course you will learn to develop simple Web applications using the PHP programming language and
HTML markup language.

42
Chapter 1 Review Questions
1. A web application is an example of:
a. Object-Oriented Programming
b. Client/server design
c. A microprocessor
d. A standalone application
2. A program that requires the source code each time that it executes is using which method to convert the
source code to machine language?
a. A compiler
b. An interpreter
3. Which approach is better when evaluating software requirements?
a. Determine the requirements as quickly as possible in order to move on to the design and coding
phases.
b. Take time to analyze and clarify the application requirements.
4. What kind of thinking activities are most associated with the work of a programmer?
a. Left brain activities
b. Right brain activities
c. Both left AND right brain activities
d. Neither left NOR right brain activities
5. What language is often used to write algorithms?
a. Markup language
b. Pseudocode
c. High-level programming language
d. Machine language
6. Which language does the computer actually understand when it executes instructions for a program?
a. Markup language
b. High-level programming language
c. Pseudocode
d. Machine language
7. What is the computer's instruction set?
a. The set of all programming languages that a computer can understand
b. The set of all software that is currently available on the computer
c. The basic set of commands that a computer can execute
d. The rules for using a high-level programming language
8. What is source code?
a. Programming instructions written in a programming language
b. Program instructions that have been compiled into machine language
c. The code used to identify text characters from languages all over the world
d. The code used to identify memory addresses
9. What does an executable file contain?
a. Programming instructions written in a programming language
b. Program instructions that have been compiled into machine language.
c. Formatted text
d. An audio image
10. Which term applies to an application model where one program calls another program in order to have
some task performed?
a. Client/server
b. Standalone program
c. Instruction set
d. An algorithm

43
11. What does an interpreter do?
a. Reads and executes source code, one line at a time
b. Converts source code into an executable file.
c. Sends data from one program to another
d. Converts and displays text that has been marked up
12. What does a compiler do?
a. Reads and executes source code, one line at a time
b. Converts source code into an executable file
c. Sends data from one program to another
d. Converts and displays text that has been marked up
13. When you use your Web browser to access information you are working with
a. A client/server application
b. A standalone application
14. What is an algorithm?
a. A set of instructions to meet a requirement of some kind
b. An executable file
c. Program instructions that have been compiled into machine language
d. Programming instructions written in a programming language
15. Which of the following is not a feature of modular application design?
a. Concurrent development of each module
b. Reusable code
c. Separate testing of each module
d. Less time needed to evaluate requirements
16. What category of language is used to describe or format data?
a. Markup language
b. High-level programming language
c. Pseudocode
d. Machine language
17. What languages will you learn in this course?
a. C++ and HTML
b. XML and Java
c. PHP and FORTRAN
d. PHP and HTML
18. Which is the correct order for these stages in the software development life cycle?
a. Application coding, application design, algorithm development
b. Application design, algorithm development, application coding
c. Algorithm development, application design, application coding
d. Algorithm development, application coding, application design
19. Is a Web browser a client application or a server application?
a. Client
b. Server
20. What type of application runs entirely on your own computer?
a. Client/server
b. Networked
c. Web-based
d. Standalone

44
Chapter 2

Client/Server
Applications—Getting
Started

Intended Learning Outcomes


After completing this chapter, you should be able to:

Explain how Web programs function as client/server applications.


Identify the content of a file by referring to the file extension.
Locate files using the Windows addressing scheme.
Locate files using the Internet (IP) addressing scheme.
Use the localhost domain to access a standalone Web server.
Identify the languages we will use in this course.
Identify the software you will need to complete the hands-on work.
Install the required software.
Create, save and open an HTML document that is stored on a local Web server.
Create, save and run a PHP file that is stored on a local Web server.
Create, save and run an interactive Web application consisting of an HTML document that includes a form, and a PHP application
that processes the form.

45
Introduction
This chapter will prepare you for the hands-on activities that you will perform as you work through the
subsequent chapters of this book. First we will review client/server design with a focus on Web-based
applications. Next we will look at how files and folders are organized and located, using local addresses based on
disk drives, and Internet addresses based on domain names. This is important since you will need to be careful
to save files to the correct locations on your disk drive, and then open these files in your Web browser using the
correct Internet address.
You will also install the server software that you need to work through the textbook and complete the exercises.
This is a very straightforward procedure and you will be able to test that your server is running correctly by
running some sample programs.
Once the server has been installed you will have the option to install a text editor, then you will be asked to
type in a few small programs, save them, and run them using your Web browser. The code for these programs is
provided. The idea is not to learn to develop programs (that comes later), but to simply learn the general process
of using an editor to create code, saving your files to the correct location under your Web server, running the
server, and then testing that your programs work correctly.

46
Client/Server Design in Web Applications
In a client/server design, client programs send requests to server programs to perform a task of some kind, just as
you might ask someone else to do something for you. The server receives the request from the client and responds
appropriately. The server program resides on a networked computer and can respond to hundreds, thousands, or
millions of client requests; consider an online shopping site that receives requests from customers all over the
world every minute. An important advantage of client/server design is that software updates are applied on the
servers without requiring any changes on the client computers.
Client/server applications are delivered world-wide across the Internet, and are also used to provide services to
users of private networks (known as intranets) within an organization or company.
A Web application is a familiar example of an Internet-based client/server design. In the case of Web
applications, the client program is a Web browser. The Web browser runs on a user's personal or office computer.
Each time the user enters a URL, or clicks on a link on a Web page, or clicks a Submit button after entering data
into a Web form, the browser sends the user's request. The request is transmitted across the Internet to the
appropriate Web server. The Web server receives and processes the request, then sends back a response for the
browser to display to the user. Web servers may be located anywhere on the Internet and can accept requests from
any client that has Internet access (Figure 2-1). In order to process each request, the server program may
communicate with other programs or access databases or files. This is a very efficient design since it allows the
user to obtain all kinds of useful services without installing special software on their local computer. Instead the
user uses their Web browser to execute programs that are located on remote servers.
In order to develop Web-based applications we must create files that contain the necessary instructions for our
Web pages and programs, and store these files on a Web server. The server can then process the files as needed in
response to requests.

Figure 2-1: Example of client/server design

In this course you will run a Web server on your local computer so that you can develop applications without
having to connect to a server located on the Internet. In other words, your Web server will actually be located on
the same computer as your Web browser, but it will behave exactly like a Web server running on the Internet.
This approach allows you to keep all your work on your local computer or USB drive, and saves you the expense
of setting up an account with an Internet Service Provider (ISP). Note that, if you prefer, you can also do all the
work in this book using an Internet-based Web server; in that case you will need to transfer your files to and from
the server in order to edit them.
Even though your Web server will run on your local computer, it will still function as though it were running
on the Internet. You will need to be careful to save your files to the correct folder locations so that your Web
server can find them, and you will also need to provide the correct Web addresses (URLs) for these files when you
wish to view them in your Web browser. Web addresses are quite different from the addresses used in Windows
so let's review how files and folders are organized on disks, and then learn how files can be located using the

47
Windows and Internet addressing schemes.

48
Working with Files and Folders
Files are used to store data, all kinds of data. A file may contain text, images, videos, word-processing documents,
programs, etc., but each file may only contain one type of data. The file extension usually indicates the format of
the data that is stored in the file. This is very useful since the format indicates what type of program is needed to
process the file. For example, a file with a .jpg extension contains image data stored using the jpeg image format,
and can be opened by any image-viewing or image-processing program that can read this format. A file with an
.mp3 extension contains an MP3 audio file that can be handled by any MP3 player. A file with a .zip extension
contains data that has been compressed using the ZIP compression scheme. To create zip files, or extract data
from these files, you will need zip utility software.
Text files contain plain text (characters that can be typed on your keyboard). Text files can be viewed and
edited using any text editing software. Files that contain plain text are often saved with a .txt extension. Often
however, text files are given special extensions to indicate the specific purpose of the text that is stored in the file.
In this course you will use a number of different extensions for your text files, as follows:

Plain text files, using a .txt or .dat extension, will be used to store simple data for use by your programs. For
example you might create a file named scores.txt that contains a list of student scores.
HTML files, using an .html extension, will be used to store the markup instructions for Web pages. Our
Web pages will include forms to allow the user to enter information that will be submitted for processing by
our programs. For example you might create a file named wages.html that contains a Web page with a form
for the user to submit their hours worked and hourly wage.
CSS files, using a .css extension, will be used to store style sheet specifications that define how our HTML
code is to be rendered on the Web page.
PHP files, using a .php extension, will be used to store the source code for PHP programs. Our PHP
programs will usually receive information from the user or look up data in files in order to perform useful
processing operations and generate output. For example you might create a file named wages.php that
contains the source code to receive wage information from a Web page, then calculate and display the pay.

Since these are all text files we can create and modify the content using any text editor. However since these files
contain text to serve different purposes, the file extension indicates what software is required to process the
content of each file. A file with an .html extension is usually opened by a Web browser, since Web browsers are
designed to interpret .html files and display the contents as Web pages. A file with a .php extension can only be
executed as a set of PHP instructions if it is opened by a PHP code processor. A PHP code processor is included
with the Web server that you will install as you work through this chapter.
Files are usually organized into folders for ease of management, and files and folders are stored on portable or
fixed disks that are accessed through disk drives connected to computers. You can access files on disks located in
local drives that are attached to your personal computer. You can also access files on disks in remote disk drives,
attached to computers that are connected to your computer through a network such as the Internet. No matter
where the drive is located, in order to locate a specific file on a disk, you need to be able to refer to it using some
kind of file addressing scheme.

49
Locating Files and Folders on Computers
Running a Windows Operating System
Most often when we want to locate a file or folder using a Windows operating system, we open File Explorer and
point and click our way to the file that we wish to work with. As a programmer, it is important to know that we
can also reference a file by providing its unique file path or address. Every file and folder on a computer has a
unique address that is based on its folder location and disk drive specification. Take a look at Figure 2-2, which
displays a screen containing a list of four folders.

Figure 2-2: Examples of folders on a disk

Note that the address box shows the root address of these folders. They are located on the D:\ drive of the local
computer. The address of the folder named CourseMaterial is therefore D:\CourseMaterial.
Folders can contain any combination of other folders and data files. Let's look inside CourseMaterial by double-
clicking this folder (Figure 2-3).

Figure 2-3: Inside the CourseMaterial folder

Notice the address in the address box is now D:\CourseMaterial, indicating that we have shifted our location to
the CourseMaterial folder. This folder contains three folders (CourseWork, ReferenceMaterials and Samples)
and two data files (notes.txt and myImage.bmp). The file extensions indicate the type of data stored in these two
files: notes.txt contains plain text, while myImage.bmp contains a bitmap image. The complete address of the
file named notes.txt is D:\CourseMaterial\notes.txt and the address of the folder named Coursework is
D:\CourseMaterial\Coursework.

50
Exploring the Variety of Random
Documents with Different Content
detail all the proofs and arguments adduced by our able writers, at
least in English, in support of the papal supremacy and the
eucharistic sacrifice. Unless they do this, they will not be entitled to
any notice at our hands.
So far as Dr. Harwood merely describes the doctrine we hold
respecting the papal supremacy, he is almost entirely correct, and so
eloquent that the effect produced in his mind by its grandeur, in
spite of his inward reluctance, is visible. Of argument against it there
is hardly the semblance, a point we note not to the author's
disadvantage, but merely as a reason for not arguing in its favor.
One passing objection he does throw, as he goes by, at the title
supreme pontiff or pontifex maximus. This word appears to alarm
him, and no doubt alarmed all the excellent ladies and other worthy
persons in his audience, who are easily alarmed by words. "He is
regarded as the pontifex maximus of the whole church of Christ.
Pontifex maximus! The very word brings up memories of the
imperial city before it became Christian. Julius Cæsar was pontifex
maximus—the office was held by all the Cæsars—it was held while
the disciples of Jesus Christ, worshipping their Lord in the
catacombs, or dying in the amphitheatre 'to make a Roman holiday,'
associated the office with all cruelty and impiety." If this passage is
any thing more than a rhetorical flourish, it means that the name
and office of supreme pontiff are bad, unchristian things, because
the heathen had them. We ought, then, to carry this principle out to
its fullest extent. The heathen had an order of men specially devoted
to religion, public prayers, holy days, temples, religious hymns, etc.,
therefore we should have none of these. The surplice which Dr.
Harwood wears is derived through the Jews, from the ancient
Egyptian priests; his prayer-book is full of observances derived from
the Roman Church. He preaches sermons and observes a fast of
forty days, like the Mohammedans, all of which is very wrong, and
reminds us painfully of Pharaoh, and the fires of Smithfield, and the
cruel persecutions of the Turks against the Christians. The Jews had
a high priest appointed by Almighty God. Our Lord is a high-priest,
pontifex maximus. Heathen perversions or travesties of divine things
make no argument against the things themselves. Neither is there
any reason why names, forms, observances, used by heathen, if
they are good and suitable, should not be adopted by Christians, just
as we appropriate heathen architecture, take possession of heathen
temples, and employ heathen philosophy in the service of religion.
We have no doubt that Moses imitated the civil and religious
customs of the Egyptians to a very great extent in the prescriptions
of his law. Parallelisms between the Catholic religion and various
false religions may easily enough be pointed out. We laugh at such
an argument as not worthy of being seriously refuted. The greater
the number of analogies that can be pointed out, the stronger is the
proof that the principles of our religion are derived from the origin of
the race, universal, and in accordance with human nature. Rome
was not all bad before it was converted. Whatever in it was good did
not need to be abolished, but only sanctified. Our Lord drove out
Jupiter, the angels and saints supplanted the imaginary divinities of
Olympus, the successor of Peter took the place of the successor of
Cæsar. The glorious temples of the gods became Christian churches,
and Roman polity became an organizing power over all Christendom.
In this was only fulfilled the prophecy of St. Paul, "The God of peace
shall bruise Satan under your feet shortly."[60] This kind of play
upon words with pontifex maximus will, therefore, help Dr. Harwood
very little unless he can disprove the existence of the thing they
represent—a human priesthood with a supreme head over it,
possessing power delegated by Jesus Christ.
The lecturer is not precisely accurate in what he says of the
definition of the immaculate conception. The judgment of the
Catholic bishops and doctors had been for ages manifested, and was
taken anew in the most formal manner, before Pius IX. proclaimed
his definition. Those few persons among the prelates and
theologians who were opposed to the definition, did not merely
submit outwardly by keeping silence, but inwardly by an interior
submission of the mind, precisely as a good Christian would have
submitted to St. Peter himself in a similar case. If Dr. Harwood
admits the doctrinal infallibility of the New Testament, he can easily
understand that, if the meaning of any passage in it about which he
had previously doubted should be made clear to him, he would have
to give his interior assent to it, even though he must change an
opinion he had held all his life long. Precisely so with us. An infallible
judgment makes known to us with the certainty of faith the true
sense of the divine revelation, which we receive accordingly as
equally certain and obligatory on the conscience with every other
revealed truth. Whoever does not give this inward assent becomes a
heretic, and therefore Pius IX., in his Bull Ineffabilis, pronounces that
every one who does not believe the immaculate conception as a
revealed truth has suffered shipwreck of the faith.
In his account of the Catholic doctrine of the sacrifice of the mass
the author of the lecture is less successful, and misrepresents it
seriously; not intentionally, or through wilful carelessness, but
through a misunderstanding of Catholic phraseology. Because the
church calls it the same sacrifice with the sacrifice of the cross, he
appears to think that our Lord is believed to have redeemed the
world by the oblation of himself at the institution of the eucharist,
and to be continually repeating this act of redemption in the sacrifice
offered daily on our altars. Dr. Seabury, the first Protestant bishop of
Connecticut, did actually teach that our Lord offered himself in the
eucharist as a sacrifice, and not on the cross. This strange notion of
the founder of his own diocese, Dr. Harwood incorrectly ascribes to
the Catholic Church.

"The sacrifice was made or instituted in the night in which he


was betrayed; and, in the system of Romanism, this sacrifice is
every thing. I do not see that the cross is necessary; for the
stress falls upon the sacrifice of the altar, and the worshipper is
directed to that sacrifice as vested with objective propitiatory
virtue."

The church teaches that our Lord redeemed the world by his death
and the shedding of his blood upon the cross. He did not redeem it
by the oblation of himself in the Last Supper, nor does he do so by
the sacrifice of the altar; the sacrifice of redemption having been
offered once for all upon the cross, and not needing to be repeated.
The church does not mean by "same sacrifice" that the oblation in
the eucharist is a similar act of redemption, propitiatory in the
divided sense, or merely as containing the body and blood of Christ,
and presenting them before God. The sacrifice is the same, because
the victim is the same, the priest is the same, and all the value or
merit contained and applied in the sacrifice of the altar is derived
from the bloody sacrifice of the cross. There is thus a moral unity
binding together the innumerable acts of consecration and oblation
which take place on the Christian altars with each other and with the
sacrifice of the cross, in one whole, just as the innumerable acts of
obedience performed by our Lord during his earthly life make one
integral act of obedience with the final and consummating act of his
oblation on Mount Calvary. No doubt the intrinsic excellence of the
sacrifice of the eucharist is infinite, and therefore sufficient for the
redemption of this world or a thousand others, if there were others
needing redemption. The merit of the circumcision, the fasting, the
prayer, the preaching, the poverty and humiliation, the labors and
tears of our Blessed Lord was infinite, and fully adequate to the
redemption of mankind, without the sacrifice of the cross. Every act
of love to God the Father proceeding from the sacred heart of Jesus
Christ in heaven is simply infinite in its intrinsic value. Yet no Catholic
theologian maintains that the meritorious acts of our Lord performed
while he was a wayfarer on the earth redeemed mankind apart from
his death, or that he has merited any additional grace for men since
his sacrifice was completed. The sacrifice which our Lord offered in
the Last Supper did not, therefore, constitute that act of expiation to
which, in the divine decree, the remission of original and actual sin
was annexed; and much less is there any such distinct, expiatory
merit in the sacrifice which he perpetually makes of himself in the
eucharist, since his meritorious work has been consummated. He
offered himself once for all as a bloody sacrifice upon the cross,
meriting thereby an eternal redemption. At the Last Supper he
offered up himself to the Father as the Lamb who was to be slain
the next day, presenting by anticipation the merit which he would
gain by his cruel and ignominious death, as an act of adoration,
thanksgiving, expiation, and impetration in behalf of all those who
were included either generally or specially in his intention.
Doubtless, he frequently in prayer had presented these same merits
to his Father; and from the time of Adam's sin these same merits
had constituted the only ground on which pardon or grace had been
conferred, thus verifying the appellation applied to our Lord in the
Scripture of "the Lamb slain from the foundation of the world." In
the sacrifice now offered by the priests of the new law, Christ is
presented before the Eternal Father as the Lamb who has been
slain. And although, as a sacrifice, the eucharist is equally an
oblation of the body and blood of the Lamb of God with the sacrifice
of the cross, differing only in the manner of offering, yet as this
manner of offering upon the cross by pain, blood-shedding, and
death constituted the precise act which expiated sin and redeemed
the world, the sacrificial nature of the eucharistic action which it has
in common with the crucifixion does not derogate from the exclusive
attribute belonging to the latter as the redemptive expiation or the
sacrifice of ransom, blotting out the curse of the fall, and reopening
the gates of heaven to our lost race. A sacrifice of expiation
including all ages, all men, and all sins having been once offered,
there is no need and no place for another, which is precisely what St.
Paul proves in the Epistle to the Hebrews. Dr. Harwood fancies that
we have a dread of that epistle. It is not long since we went through
that epistle carefully with a theological class without being aware of
any sentiments of repugnance to its doctrine arising in our minds. It
is very true that the unlearned and unstable may wrest this, as they
do the other epistles of St. Paul and the Scriptures generally, to a
sense in contradiction to the Catholic faith. To one, however, who is
sufficiently learned to understand the real scope and intent of the
apostle, or sufficiently docile to receive the instruction of competent
interpreters, it presents no difficulty. St. Paul is not speaking of the
eucharist or of the Christian priesthood at all, but is confronting the
priesthood and sacrifices of Jesus Christ in the work of redemption
with the priesthood and sacrifices of the old law, as these were
understood by unbelieving or heterodox Jews. The point to be
established was, that Jesus Christ would never give up his
priesthood to a successor, or offer up another sacrifice similar to the
one offered on the cross. It needs no reasoning to show that
Catholic priests do not pretend to be in the place of Jesus Christ, but
simply his instruments. The perpetuity of his priesthood is therefore
not in the slightest degree incompatible with ours, which is in a
different line, but rather requires it. Neither is it necessary to prove
that we do not pretend to offer a sacrifice which expiates sins or
atones for persons not included in the sacrifice of the cross. The
doctor misunderstands the phrase "propitiatory sacrifice." The
church does not mean that a new sacrifice is offered for persons
whose sins were unatoned for on the cross, or who have fallen a
second time under the curse and need a new ransom. The word
"propitiatory" merely denotes that in the sacrifice of the altar an
application is made of the merits of Christ's death to individuals for
the remission of temporal penalties due to the justice of God. The
redemption was made on the cross; the application of the grace of
remission is made in the sacrament of penance; the remission of
temporal penalties, both for the living and the dead, is obtained
through the sacrifice of the altar. All the efficacy of the divine
eucharist, whether as a sacrifice or a sacrament, is derived from the
merits of Jesus Christ, which were consummated in his death. It is,
therefore, by the application of the merit of the sacrifice of the cross
that the sacrifice of the mass becomes efficacious to salvation. The
Lamb of God is presented before the Father with the merit acquired
by his death upon Mount Calvary, and this presentation is an act of
supreme adoration, of thanksgiving, of impetration, and of
satisfaction for the debt due to the divine justice, made in a sensible,
visible manner, with mystic rites and ceremonies; which is enough to
constitute a sacrifice in the strict and proper sense, whatever
difference of opinion there may be concerning the essence of the
sacrificial act in the eucharist. Although, therefore, there are many
priests and many sacrifices numerically, it is one act performed by
one person which is exhibited and applied in all, so that there is truly
but one sacrifice and one priest. The reverend doctor might have
seen this for himself if he had reflected more carefully on the words
of the Council of Trent which he has himself quoted, Cujus quidem
oblationis cruentæ, inquam, fructus per hanc uberrime percipiuntur
—"The fruits of which bloody oblation, indeed, are by this most
abundantly partaken of."
The words of the lecturer following his exposition of the doctrine are
not at first sight intelligible. "We may be pardoned, then, if we ask
what then is our Lord to us personally?" It is very difficult to see how
the hidden presence of our Lord under the sacramental veils is any
obstruction to our personal relation to him as our Saviour. How does
this presence derogate from the fact that he died for each of us on
the cross, and is ever living in heaven to make intercession for us?
Our adoration of his sacred body and precious blood under the forms
of bread and wine does not hinder our meditating upon his passion
and death upon the cross, or raising our mental eye to his glorious
form at the right hand of God. The author appears to imagine that
his sacramental presence must destroy his natural mode of existence
and reduce him to a passive, helpless state of being in the host. But
this is only because he fails to conceive the Catholic doctrine that
our Lord is present both in heaven and also in the host at the same
time, though in two different modes. He says, "He is present with
us, we adore that presence, but he is passive and lifeless in the
hands of a priesthood. No sign or word comes from the pix. When
the church is in travail over a new doctrine, recluse and learned men
busy themselves in vast libraries in order to catch the consensus of
Catholic tradition. A believer may be excused, if, like Mary, he cries
out, 'They have taken away the Lord, and I know not where they
have laid him!'" Strange language this from a member of the
communion of Andrewes, Hooker, Taylor, Pusey, and Hobart! Has the
author ever read their glowing words respecting this same theme? Is
he familiar with the doctrinal books of his own church? Taken away
the Lord, when he remains perpetually in our tabernacles awaiting
the visits of those true believers who pass hours in sweet
communion at the foot of the altar, conversing with him as with the
friend and spouse of their souls? When he is given to them in
communion and his sacred body rests in their bosoms, kindling there
the flames of a sacred love often equal to that which glows in the
seraphim? Let the reverend doctor read the lives of the saints, and
ask them if the Lord is silent when they converse with him in the
blessed sacrament, or let him even ask the ordinary pious Catholic
that question. He does not indeed break the silence of his hidden
state by words audible to the bodily ear, but he speaks far more
efficaciously to the heart in a way which is unintelligible to cold
rationalism, but perfectly well known to faith inflamed by love. The
divine eucharist was not instituted as a medium for communicating
light to the church concerning revealed truths. Christ teaches and
rules the church by the Holy Spirit, and not by his human voice. It is
his will that study, meditation, and counsel should be the means by
which the prelates and doctors of the church obtain the light and
assistance of this divine Spirit. Dr. Harwood is not pleased with this
arrangement; but as the Lord appears to have determined definitely
that it must be so, we are afraid that his suggestions will not be
attended to. At all events, he may console himself with the reflection
that he has discovered an entirely new objection to the Catholic
doctrine.
We have unwittingly passed over one other objection, namely, that
the doctrine of the eucharistic sacrifice destroys the idea of
communion. The eucharist does not cease to be a sacrament by
being a sacrifice. If there is communion among Episcopalians
through a reception of bread and wine, it would seem that there
might be also communion among Catholics in receiving the true
body and blood of Christ. If the Protestant Episcopal liturgy is a
common prayer, certainly the Catholic liturgy is equally one, though
it is also a sacrifice. Moreover, there is, in the strictest sense,
communion in the very act of offering the sacrifice. The priest,
though consecrated by a heavenly grace and commissioned by the
divine authority of our Lord, is consecrated to minister for the
people, in their name and as their representative. He offers up the
sacrifice for the people, and they offer sacrifice to God through him,
which is signified in the mass by the action of the deacon, who, as
the representative of the laity, holds the pixis in his hand at the
offertory, and placing his right hand on the foot of the chalice,
recites with the priest the prayer, Offerimus tibi, Domine, calicem,
etc. We will not attempt to prove the truth of the Catholic doctrine of
the mass, since the author does not directly attempt to disprove it,
but will drop the subject here, and proceed to notice what method
he proposes to follow in refuting the two grand Catholic doctrines of
the papacy and the mass.
The reverend doctor takes a review of the condition of Protestantism
as in contrast with that of the Catholic Church, in which we are
happy to be able to concur with him as well as to commend the
graphic power of his description. He then briefly indicates three ways
of proceeding: one by tradition, one by tradition and Scripture
together, and one by Scripture alone, which he selects, reserving the
right to appeal to tradition when it is convenient. We will let his
language speak for itself:

"As searchers after truth, we must acknowledge some standard


and appeal to some recognized authority. Without this we must
follow either our own mental bias, or else become the prey of
every man who shall be bold enough to declare that he has and
holds the truth of God. I fear very much we have lost sight of
this need of appeal to a recognized standard of truth and duty.
We are, in this new age, building apparently on the sand; or it
would seem that what we had supposed to be rock, on which
many were building, has become pulverized, and as the sands
shift under the power of the stream, multitudes believe to-day
what they did not believe yesterday, and to-morrow they may
believe nothing at all.
"I touch here a serious evil which is doing more harm to our
Protestantism than any direct assaults of Romanism. We seem
to be under some spell. Our spiritual ideas are resolving
themselves into a series of dissolving views; and all because the
mind has not the proper nutriment to impart health and vigor to
our religious feelings and convictions. Upon every account it
becomes us to recognize the fact that in religion we must have
an actual, definite standard of appeal. This we must find either
in sacred Scripture or in tradition, or in both combined. If we
accept the tradition of the church as law, we might as well
abandon the contest with Rome, because the traditions
gradually, as they gather force and headway in time, revolve
around the papacy. The traditions in the long run have made
the papacy; they are its chief support to-day. To accept them
bodily, in mass, is to appeal to actual Christendom—to the
historic church—as to a standard and law, and not as to a
witness of truth. It is to acknowledge the identity of Christian
truth and the Christian Church visible. This brings us again to
Romanism, or this is the postulate of the Roman Catholic
apologist.
"If to-day I ask what is truth? and if I allow every church or sect
to answer, I am stunned by a confused and unintelligible noise.
If I allow one church to answer, and only one, in the midst of
the crowd of churches, by my procedure I submit myself, in
advance, to that one church. But if I allow none to answer for
me, and I recognize, nevertheless, a divine historic revelation, I
am compelled to go to sacred Scripture in order to learn what
God requires me to believe. Shall we take the sacred Scripture
fashioned by Italian workmen? or by Greek, or by Anglican, or
by German, or by American workmen? No; but the text in its
purity and simplicity. Here we must take our stand whensoever
we come to the question of what it is necessary to believe in
order to be a Christian; whensoever, in a word, loyalty and the
obedience of faith are required or even considered.
"I do not mean, however, to deny and repudiate utterly the
traditional principle. Christianity is historic. As a social interest,
as an organized spiritual fact, it comes to us from the past. We
cannot dismiss this past of Christian life and history, any more
than we can dismiss the past of our civil life and institutions.
The new generation, as it succeeds the old, does not build again
from the foundations. A. U. C. represented a fact to the Roman
citizen which he never could forget. We measure time in the
world's history by the letters A. D. We date our public
documents in the United States from the declaration of our
independence. We do not create the state anew; we administer
it as an existing fact. So in religion. Many things, many words,
institutions, and the like have come to us from the past, which
we accept and use as a matter of course. We baptize infants,
we observe the first day of the week, we use the imposition of
hands in ordination and confirmation, we employ the words
sacrament, trinity, incarnation, etc., in theology. This is an
illustration of the recognition of a traditional principle which is
inevitable. We do not, therefore, maintain that we must have a
sure and certain warrant of Scripture for all that we may
observe and do as Christians, because it is impossible to be
confined to the written word under all circumstances, and
during all ages. Much is left the conscience and judgment of
individuals and of particular churches; but when we come to
faith, to what it is necessary to believe as Christians, we must
adhere firmly to the Bible, and never for a moment allow any
one to impose upon the conscience any thing, as requisite to a
true reception of the Gospel, which is not contained therein, nor
may be proved thereby.
"This, then, is our standard of appeal. Logically and morally it is
the right and only standard of appeal in the discussion,
especially of the claims and teachings of any and of every
church whatsoever. If this be not the tribunal to which we must
go, then we must have recourse to the dictum of a church, and
then, as we have seen, we allow a church to be its own
standard of appeal. Consequently, when Rome proclaims her
infallibility, we must allow her claim. When the Church of
England disowns infallibility, we may or may not accept her
disclaimer. If we do not accept it, then we prove her to be
fallible, to be mistaken articulately in respect of her own quality
and prerogative. We are reduced to absurdity.
"We are forced back to sacred Scripture, and in the interests of
Christian truth we are compelled to take our stand here. And I
declare in all completeness of conviction, that with the Bible in
our hands we are triumphant against the doctrine of the
supremacy of the pope, and of the sacrifice of the mass. This is
to be triumphant against Romanism."

Dr. Harwood is sagacious enough not to follow the example of the


generality of his Episcopalian associates, which the Presbyterians
have been lately seduced by their evil genius into following, that is,
to appeal to the first six councils. He probably agrees with the
author of Liber Librorum and Dr. Stanley, that in A.D. 200 we find
the thing he is opposing and anxious to escape from, existing. "How,
then, came such an institution into existence? For nothing can be
plainer than that about a hundred years after the death of John it
appears, although in any thing but apostolic garb. All is altered." "No
other change," says Dean Stanley, "equally momentous has ever
since affected its fortunes; yet none has ever been so silent and
secret. The church has now become history, the history not of an
isolated community or of isolated individuals, but of an organized
society, incorporated with the political systems of the world."...
"Hard is it to see in such a church any thing but a profound mystery
of God, a mystery of spiritual evil, a mystery of iniquity."[61] Dr.
Harwood feels it to be necessary to take refuge in the obscure
period between the year 100 and the year 200 as in a chasm
separating historical from scriptural Christianity. It is very easy to
make a theory concerning the silent, sudden change which took
place during this century, and then, clearing history by a bound, to
land in the New Testament. Once there, with full liberty of private
interpretation, which means freedom to interpret it by the light of
any philosophical theory or preconceived opinions one may choose
to adopt, Dr. Harwood thinks he is safe, and able to defend himself
to the end against Romanism. He imagines that we are unwilling and
unable to follow him there, and meet him—or rather the champions
of his cause—on their own chosen ground. "In conclusion, we will
ask you to remember that the Roman Catholics have never liked our
appeal to Scripture. They do not like it to-day any better than they
liked it three hundred years ago." If the doctor thinks we are afraid
of the Scriptures, or in any way distrustful of our ability to prove our
doctrines from it, he is extremely mistaken. We have always been
ready to enter into that part of the argument, and we maintain
specifically respecting the two grand doctrines of the papacy and the
mass that they can be fully and satisfactorily proved from Scripture,
as in point of fact they have been proved, to mention no others, by
Mr. Allies and Cardinal Wiseman. We object to the demand that
Scripture should be the only source of appeal, not because we are
afraid that we shall be defeated by scriptural arguments; but
because the demand is unjust, and the assumption on which it is
founded is baseless. We demand that the subject shall be discussed
in all its bearings, on all its grounds, by the light of all the
knowledge that is attained from every source. We deny the ability of
our adversaries to establish the authority of Scripture without first
assuming Catholic principles, and we deny their logical and moral
right after using these principles in establishing Scripture, to throw
away or burn their ladder by denying or ignoring these same
principles when it is a question of establishing the sense of the
Scripture, explaining or integrating its statements. If we are to shut
out of our minds all the ideas of Christianity which are extraneous to
the literal statements of the New Testament, to take the attitude of
learners searching after truth, and to get from the naked text
without other interpreter than itself the sense that is in it, we have a
difficult task of doubtful issue before us. John Locke, who was
probably as capable of doing this impartially as any Englishman can
be, tried it, and proclaimed as the result of his studies that only one
idea is demonstrably revealed in the New Testament, namely, that
Jesus Christ is the prophet of God to whose teaching and precepts
obedience is due. As to his actual teaching and precepts, he could
only find probability, concluding, therefore, very justly, that there is
no system of doctrine or code of precepts clearly binding upon all
alike, each one being left to the guidance of a probable conscience
only.
It is very difficult, if not impossible, to read the New Testament
without spectacles. For our own part, we are quite sure that the New
Testament contains more or less explicitly all the principal and many
of the minor Catholic doctrines, and that the sense given by the
church is the one given by true exegesis and criticism. Yet we will
not venture to say how far we should be able to see this without
Catholic spectacles. We are quite sure that Dr. Harwood also has a
pair of spectacles, and cannot lay them aside if he would. We find in
point of fact, that ordinarily persons who believe in the Bible and
read it all their lives, whether Episcopalians, Presbyterians, or even
Unitarians, are seldom startled out of the belief they have been
taught, and convinced of some different interpretation, merely by
reading it. It is evident, therefore, that any one exposition made of
Christianity from the simple text will never be a demonstration in the
view of all candid, sincere persons. There will always be various
interpretations having more or less probability, and unity will never
be reached. Besides this, the degree and extent of inspiration will
never be settled, or the limits between the human, transitory
element and the divine, unchangeable element become fixed. The
result will be that we must fall back on philosophy and a system of
rationalism. Let it be conceded that the ideas in the mind of each
sacred writer when he wrote are clearly apprehended, it will be
impossible to secure perfect submission even to the teachings of
inspired men, when the principle of church authority has been cast
to the winds. This is the reason why, even at the outset of an
argument, and before we are entitled to cite the authority of
tradition as divine to one who denies it, we refuse to permit the case
to be argued on the scriptural ground alone, even though both
parties admit the divine authority of Scripture. We desire to do
something more than to make a good case, and to establish our
interpretation as even the more probable or the most probable. We
desire to prove it to a demonstration which does not leave even a
slight probability on the other side, through which an adversary may
creep. We wish to have the question adjudicated and decided, so
that it may be clear and indisputable that God has revealed and
commands all men to believe and obey the Gospel of his Son as a
distinct and positive law of faith and practice, and not as a mere
theory. We are not afraid, however, that we cannot get the best of it,
in a discussion of the text of the New Testament, conducted on the
same principles that we should apply to an ancient manuscript about
whose contents we have no extrinsic light whatever. Those who
come nearest to this cold, critical impartiality are men who possess
the intellectual keenness necessary to see into ideas as they are,
without having any motive to misrepresent them. One who is
indifferent as to the question what the sacred writers thought and
intended to say, because he considers their teaching as equivalent
only to that of Socrates or Confucius, and who is qualified to
examine critically the New Testament, will at least attempt to state
impartially what impression it has made on his mind. And that
statement will throw some light on the question, What does the text
clearly and unmistakably signify by itself, apart from ideas on the
same subject-matter which are derived from Christian tradition? One
person of this kind, Mr. Samuel Johnson, of Lynn, Massachusetts,
who is a leader among the Bostonian free-thinkers, in an article
which appeared in The Radical gave his opinion that the doctrine of
the papacy is clearly contained in St. Matthew's Gospel. The infidel
Jew Salvador, in a work whose name we do not now remember, but
which we have attentively read, declares that the Roman Catholic
religion is the genuine religion of the New Testament, and that
Protestantism is a total misconception of Christianity; an opinion we
have ourselves personally heard expressed by a well-informed and
zealous Israelite of our acquaintance. We do not care to press these
testimonies too far; but at all events they indicate, in connection
with the fact that so many learned students of the Bible, both
Protestant and Catholic, interpret it in a manner quite different from
that of Dr. Harwood's school, that it does not on the face of it clearly
and unmistakably pronounce in his favor or against us.
We insist then, further, that even conceding Dr. Harwood for a
moment in possession of the ground on which his belief of the divine
authority of the Scripture stands, he is bound to admit all the light
that ecclesiastical history throws back on its text, as he himself
partially but inconsistently admits, and as all Protestants have ever
done so far as it suited their purposes to do so. We may illustrate
this by a parallel case. A Christian discusses the text of the Old
Testament with a Jew. If the Jew should insist on sticking to the
text, and interpreting the prophecies exclusively by biblical criticism,
the Christian could justly insist that the facts of the life of Jesus
Christ and the history of Christianity must be considered. The Jew
himself would not fail to cite all kinds of historical facts not
prejudicial to himself against an infidel, as manifesting the sense and
fulfilment of the prophecies. Let the Jew shut his eyes to the
miracles proving the divine mission and miraculous conception of
Jesus, and he can very plausibly explain the famous prediction,
"Behold the Virgin (ha almah) shall conceive," etc., as signifying.
"Behold this young woman"—that is, one standing by and pointed
out by Isaias—shall conceive and bear a son. So, with all the
Messianic passages of the Old Testament, as one may see by
consulting Rabbi Leeser's English translation, with notes, published
at Philadelphia. Now, it is a perfectly fair and conclusive argument
against a Jew to show that the history of Jesus, established on
merely human faith, presents such a correspondence to the
prophecies of the Old Testament that it must be regarded as their
fulfilment. Although the Old Testament alone might not reveal Jesus
to his individual reason, yet in the light of his life it is shown that
these ancient Scriptures testify of him. It is not competent for him to
allege his Scripture as a complete and finished revelation, rejecting
every thing which is not clearly visible on its face; for we can show
him that his Scriptures point out the glorious son of David's royal
daughter as the one who will carry out the dispensation of Moses to
its consummation.
It is precisely the same case between us and Protestants. We point
to the church as presenting historical facts and verities
corresponding to the somewhat obscure predictions or other
declarations of the Scripture, and manifesting their significance. We
show how all that can be learned from the New Testament by itself
is in harmony with what the church proclaims herself to be, and
declares true Christianity to consist in; and we show the Scripture
presupposes, provides for, and points toward the church. If we take
all those passages which relate to the divine eucharist, and place
beside them the traditional teaching and practice of the church, we
see them at once lit up with meaning and irradiating our minds with
the true and Catholic doctrine. One is the explanation of the other,
and the historical existence of the sacrifice of the mass confronted
with the language of the Scripture demonstrates that it must be the
thing which the sacred writers meant. We take the prediction of our
Lord to St. Peter, "Thou art Peter, and on this rock I will build my
church." One who knows nothing about the Catholic Church might
easily be persuaded that our Lord meant no more than this: "Thou
art firm like a rock in thy faith, and upon such a firm faith I will
establish all the elect who are an invisible society known to me, and
these Satan shall never be able to overcome." But when that
stupendous, world-subduing might of Peter's see which overawes
even Dr. Harwood is contemplated in history as it emerges from the
obscure dawn of the Christian era, and goes forward through all time
conquering and to conquer, its plain correspondence to and
fulfilment of the literal significance of our Lord's words proves
conclusively that he meant this, and nothing else. We do not intend,
however, to go into this argument any further, as Dr. Harwood does
not profess to argue the point himself. All we aim at is, to show that
the argument must be conducted on the ground of history as well as
that of Scripture. And here we desire to call attention to an
admirable article by President Woolsey in the same number of the
New-Englander, in which Dr. Harwood's lecture was first published,
on the Church of the Future, which exhibits with rare ability the very
idea we are insisting upon, that the true Christianity is the genuine
historical Christianity.
The only true issue which can be made is respecting the genuine,
historical development of the Christian idea. Dr. Harwood and his
school cannot escape from this. If, therefore, the champions whom
he summons to the controversy respond to his call, they will be
bound to demonstrate historically that the papal supremacy was a
purely human invention substituted for the authentic constitution
which the apostles gave to the Christian church. This Dr. Harwood
thinks can be done. "If the pope be that rock, we can find by the
lights of history the strata and the law of its structure. We observe it
acquired shape and size—and there is a hammer which can break it
in pieces." If there is such a hammer, we wonder that it has not yet
been found and wielded. In our opinion, the enemies of the papacy
have already said every thing which can be said on their side of the
question. We are at a loss to know how history can be made to give
up any thing new on the subject, any thing which has not been
already thoroughly sifted and discussed. We are perfectly willing that
our adversaries should try again to look up or manufacture a
hammer with which to try the effect of their blows upon the Rock of
Peter. We think they will find that they are undertaking a herculean
task. One thing only we must be permitted to observe, that any one
who undertakes this controversy ought not to ignore and pass by
what has already been written by Catholic controversialists. It is not
fair that the discussion should be always beginning de novo, and
Catholic writers be required to repeat all the labor of their
predecessors. If Dr. Harwood, or any one else, is disposed to
attempt our demolition, let him first master all the arguments and
evidences which have been already adduced on our side, give a
distinct answer to them, and rebut the answers which we have
already made to anti-papal arguments. Whoever does this with
competent learning and ability, will no doubt receive due attention;
but until this is done, it will be quite sufficient for us to challenge a
refutation of the works of our champions which hitherto have
remained unanswered, and which we confidently affirm to be
unanswerable.
HAYDN'S STRUGGLE AND TRIUMPH.
I.
"Seventeen kreutzers for a morning's work!" exclaimed a pretty but
slovenly-dressed young woman, standing at the door of an
apartment in a mean-looking house in one of the narrow streets of
Vienna, addressing a man of low stature and sallow complexion,
who had just come in. "And the printers running after you ever since
you went out! Profitless doings for you to spend your time! At eight,
the singing-desk of the brothers De la Merci; at ten, Count de
Haugwitz's chapel; grand mass at eleven; and all this toil for a few
kreutzers!"
"What can I do?" said the weary, desponding man.
"Do! Give up this foolish business of music, and take to something
that will enable you to live. Did not my father, a hair-dresser, give
you shelter when you had only your garret and skylight, and had to
lie in bed and write for want of coals? Had he not a right to expect
you would dress his daughter as well as she had been used at home,
and that she should have servants to wait on her, as in her father's
house?"
"You should not reproach me, Nanny. Have I not worked till my
health has given way? If fortune is inexorable—"
"Fortune! As if fortune did not always wait upon industry in a proper
calling. Your patrons admire and applaud, but they will not pay; yet
you will drudge away your life in this ungrateful occupation. I tell
you, Joseph Haydn, music is not the thing!"
Here a knock was heard at the door; and the wife, with exclamations
of impatience, flounced away. The unfortunate artist threw himself
on a seat, and leaned his head on a table covered with notes of
music. So entirely had he yielded himself to despondency that he did
not move, even when the door opened, till the sound of a well-
known voice close at his side startled him from his melancholy
reverie.
"How now, Haydn! what is the matter, my boy?"
The speaker was an old man, shabbily dressed, but with something
striking and even commanding in his noble features. His large, dark,
flashing eyes, his olive complexion, and the contour of his face
bespoke him a native of a sunnier clime than that of Germany.
Haydn sprang up and welcomed him with a cordial embrace.
"And when, my dear Porpora, did you return to Vienna?" he asked.
"This morning only; and my first care was to find you out. But how is
this? I find you thin, and pale, and gloomy. Where are your spirits?"
"Gone," murmured the composer, and dropped his eyes on the floor.
His visitor regarded him with a look of affectionate interest.
In answer to Porpora's inquiries, Haydn told him of the struggles and
failures by which he had been led to doubt his own genius, till he
had succumbed under the crushing hand of poverty. "I am chained,"
he concluded bitterly; and, giving way to the anguish of his heart, he
burst into tears.
Porpora shook his head, and was silent for a few moments. At length
he said:
"I must, I see, give you a little of my experience. I was, you know, a
pupil of Scarlatti more fortunate than you; for my works procured
me almost at once a wide-spread fame. I was called for not only in
Venice, but in Vienna and London."
"Ah! yours was a brilliant lot," cried the young composer, looking up
with kindling eyes.
"The Saxon court," continued Porpora, "offered me the direction of
the chapel and of the theatre at Dresden. Even the princesses
received my lessons; in short, my success was so great that I
awakened the jealousy of Hasse himself. All this you know, and how
I returned to London upon the invitation of amateurs in Italian
music."
"Where you rivalled Handel!" said Haydn enthusiastically. "Handel,
with all his greatness, had no versatility. Your sacred music, Porpora,
will live when your theatrical compositions have ceased to enjoy
unrivalled popularity."
"My sacred compositions may survive and carry my name to
posterity; for taste in such things is less mutable than in the opera.
You see now, dear Haydn, for what I have lived and labored. I was
once renowned and wealthy. What did prosperity bring me? Envy,
discontent, rivalship, disappointment! Would you know to what
period I can look back with self-approbation, with thankfulness? To
the toil of early years; to the struggle after an ideal of greatness,
goodness, and beauty; to the self-forgetfulness that saw only the
glorious goal far, far before me; to the undismayed resolve that
sought only its attainment. Or to a time still later, when the visions
of manhood's impure and selfish ambition had faded away, when the
soul had shaken off some of her fetters, and roused herself to a
perception of the eternal, the perfect, the divine; when I became
conscious of the delusive vanity of earthly hopes and earthly
excellence, but at the same time awakened to the revelation of that
which cannot die!
"You see me now, seventy-three years old, and too poor to
command even a shelter for the few days that yet remain to me in
this world. I have lost the splendid fame I once possessed; I have
lost the riches that were mine; I have lost the power to win even a
competence by my own labors; but I have not lost my passion for
our glorious music, nor enjoyment of the reward she bestows on her
votaries; nor my confidence in Heaven. And you, at twenty-seven,
you—more greatly endowed, to whom the world is open—you
despair! Are you worthy to succeed, O man of little faith?"
"My friend, my benefactor!" cried the young artist, clasping his hand
with deep emotion.
"Cast away your bonds; cut and rend, if your very flesh is torn in the
effort; and the ground once spurned, you are free. What have you
been doing?" And he turned over rapidly the musical notes that lay
on the table. "Here, what is this—a symphony? Play it for me, if you
please."
So saying, with a gentle force he led his young friend to the piano,
and Haydn played from the piece he had nearly completed.
"This is excellent, admirable!" cried Porpora, when he rose from the
instrument. "When can you finish this? for I must have it at once."
"To-morrow, if you like," answered the composer more cheerfully.
"To-morrow then; and you must work to-night. I will go and order
you a physician; he will come to-morrow morning—how madly your
pulse throbs!—and when your work is done, you may rest. Adieu for
the present." And pressing his young friend's hands, the eccentric
but benevolent old man departed, leaving Haydn full of new
thoughts, his bosom fired with zeal to struggle against adverse
fortune. In such moods does the spiritual champion wrestle with the
powers of the abyss, and mightily prevail.
When Haydn, late that night, threw himself on his bed, weary, ill,
and exhausted, his frame racked with the pains of fever, he had
accomplished the first of an order of works destined to endear his
name to all succeeding time.
While the artist lay on a sick-bed, a brilliant fête was given by Count
Mortzin, an Austrian nobleman of immense wealth and influence, at
which the most distinguished individuals in Vienna were present. The
musical entertainments given by these luxurious patrons of the arts
were at that time, and for some years after, the most splendid in
Europe.
When the concert was over, Prince Antoine Esterhazy expressed the
pleasure he had received, and his obligations to the noble host.
"Chief among your magnificent novelties," said he, "is the new
symphony, St. Maria. One does not hear every day such music. Who
is the composer?"
The count referred to one of his friends. The answer was, "Joseph
Haydn."
"I have heard his quartettos; he is no common artist. Is he in your
service, count?"
"He has been employed by me."
"With your good leave, he shall be transferred to ours; and I shall
take care he has no reason to regret the change. Let him be
presented to us."
There was a murmur among the audience and a movement, but the
composer did not appear; and presently word was brought to his
highness that the young man on whom he intended to confer so
great an honor was detained at home by illness.
"So! Let him be brought to me as soon as he recovers; he shall enter
my service. I like his symphony vastly. Your pardon, count; for we
will rob you of your best man." And the great prince, having decided
the destiny of a greater than himself, turned to those who
surrounded him to speak of other matters.
News of the change in his fortune was brought to Haydn by his
friend Porpora; and so renovating was the effect of hope that he was
strong enough on the following day to pay his respects to his
illustrious patron. His highness was just preparing to ride, but would
see the composer; and he was conducted through a splendid suite
of rooms to the apartment where the proud head of the Esterhazys
deigned to receive an almost nameless artist. The prince, in the
splendid array suited to his rank, glanced somewhat carelessly at the
low, slight figure that stood before him, and said, as he was
presented, "Is this, then, the composer of the music I heard last
night?"
"This is he—Joseph Haydn," replied the friend who introduced him.
"So—a Moor, I should judge from his dark complexion. And you write
such music? Haydn—I recollect the name; and I remember hearing,
too, that you were not well paid for your labors, eh?"
"I have been very unfortunate, your highness—"
"Well, you shall have no reason to complain in my service. My
secretary shall fix your appointments; and name whatever else you
desire. All of your profession find me liberal. Now then, sir Moor, you
may go; and let it be your first care to provide yourself with a new
coat, a wig, and buckles and heels to your shoes. I will have you
respectable in appearance as well as in talents; so let me have no
more of shabby professors. And do your best, my little dusky, to
recruit in flesh—it will add to the stature; and to relieve your olive
with a shade of the ruddy. Such spindle masters would be a walking
discredit to our larder, which is truly a spendthrift one."
So saying, with a laugh, the haughty nobleman dismissed his new
dependent. The artist chafed not at the imperious tone of
patronage; for he did not yet feel the superiority of his own
vocation. It was the bondage-time of genius; the wings were not yet
grown which were to bear his spirit up, when it brooded over a new
world.
The life which Haydn led in the service of Prince Esterhazy, to which
service he was permanently attached by Nicolas, the successor of
Antoine, in the quality of chapel-master, was one so easy that it
might have proved fatal to an artist more inclined to luxury and
pleasure, or less devoted to his art. Now for the first time relieved
from the care of the future, he was enabled to yield to the impulse
of his genius, and create works which gradually extended his fame
over all the countries of Europe.

II.
On the evening of a day in the beginning of April, 1809, all the
lovers of art in Vienna were assembled in the theatre to witness the
performance of the oratorio of The Creation. The entertainment had
been given in honor of the composer of that noble work—the
illustrious Haydn—by his numerous friends and admirers. He had
been enticed from Gumpendorf, his retreat in the suburbs, the
cottage surrounded by a little garden which he had purchased after
his retirement from the Esterhazy service, and where he was
spending the last years of his life. Three hundred musicians assisted
at the performance. The audience rose en masse and greeted with
rapturous applause the white-haired man, who, led forward by the
most distinguished nobles in the city, was conducted to the place of
honor. There, seated with princesses at his right hand, beauty
smiling upon him, the centre of a circle of nobility, the observed and
admired of all, the object of the acclamations of thousands—who
would not have said that Haydn had reached the summit of human
greatness, had more than realized the proudest visions of his youth?
His serene countenance, his clear eye, his air of dignified self-
possession, showed that prosperity had not overcome him, but that
amid the smiles of fortune he had not forgotten the true excellence
of man.
"I can see plainly," remarked one of Haydn's friends, whom we will
call Manuel, "that he will write no more."
"He has done enough; and now we are ready for the farewell of
Haydn," said another.
"The farewell?"
"Did you never hear the story? I have heard him tell it often myself.
It concerns one of his most celebrated symphonies. The occasion
was this: Among the musicians attached to the service of Prince
Esterhazy, were several who, during his sojourn upon his estates,
were obliged to leave their wives at Vienna. At one time his highness
prolonged his stay at Esterhazy castle considerably beyond the usual
period. The disconsolate husbands entreated Haydn to become the
interpreter of their wishes. Thus the idea came to him of composing
a symphony in which each instrument ceased, one after another. He
added at the close of every part the direction, 'Here the light is
extinguished.' Each musician, in his turn, rose, put out his candle,
rolled up his notes, and went away. This pantomime had the desired
effect; the next morning the prince gave orders for their return to
the capital.
"He used to tell us a somewhat similar story of the origin of his
Turkish or military symphony. You know the high appreciation he
met with in his visits to England; but notwithstanding the praise and
homage he received, he could not prevent the enthusiastic audience
from falling asleep during the performance of his compositions. It
occurred to him to devise a kind of ingenious revenge. In this piece,
while the current is gliding softly, and slumber beginning to steal
over the senses of his audience, a sudden and unexpected burst of
martial music, tremendous as a thunder-peal, startles the surprised
sleepers into active attention. I would have liked to see the lethargic
islanders, with their eyes and mouths thrown open by such an
unlooked-for shock!"
A stop was suddenly put to the conversation by the commencement
of the performance. The Creation, the first of Haydn's oratorios, was
regarded as his greatest work, and had often elicited the most
heartfelt applause. Now that the aged and honored composer was
present, probably for the last time, to hear it, an emotion too deep
for utterance seemed to pervade the vast audience. The feeling was
too reverential to be expressed by the ordinary tokens of pleasure. It
seemed as if every eye in the assembly were fixed on the calm,
noble face of the venerated artist; as if every heart beat with love
for him. Then came, like a succession of heavenly melodies, the
music of The Creation, and the listeners felt as if transported back to
the infancy of the world. At the words, "Let there be light, and there
was light," when all the instruments were united in one full burst of
gorgeous harmony, emotion seemed to shake the whole frame of
the aged artist. His pale face crimsoned; his bosom heaved
convulsively; he raised his eyes, streaming with tears, toward
heaven, and, lifting upward his trembling hands, exclaimed, his voice
audible in the pause of the music, "Not unto me—not unto me—but
unto thy name be all the glory, O Lord!"
From this moment Haydn lost the calmness and serenity that had
marked the expression of his countenance. The very depths of his
heart had been stirred, and ill could his wasted strength sustain the
tide of feeling. When the superb chorus at the close of the second
part announced the completion of the work of creation, he could
bear the excitement no longer. Assisted by the prince's physician and
several of his friends, he was carried from the theatre, pausing to
give one last look of gratitude, expressed in his tearful eyes, to the
orchestra who had so nobly executed his conception, and followed
by the lengthened plaudits of the spectators, who felt that they were
never to look upon his face again.
Some weeks after this occurrence, his friend Manuel, who had sent
to inquire after his health, received from him a card on which he had
written, to notes of music, the words, "Meine kraft ist dahin," "My
strength is gone." Haydn was in the habit of sending about these
cards, but his increased feebleness was evident in the handwriting of
this; and Manuel lost no time in hastening to him There, in his quiet
cottage, around which rolled the thunders of war, terrifying others
but not him, sat the venerable composer. His desk stood on one
side, on the other his piano; he smiled, and held out his hand to
greet his friend.
"Many a time," he murmured, "you have cheered my solitude, and
now you have come to see the old man die."
"Speak not thus, my dear friend," cried Manuel, grieved to the heart;
"you will recover."
"Not here," answered Haydn, and pointed upward.
He then made a sign to one of his attendants to open the desk, and
reach him a roll of papers. From these he took one and gave it to his
friend. It was inscribed in his own hand, "Catalogue of all my musical
compositions, which I can remember, since my eighteenth year.
Vienna, 4th December, 1805." Manuel, as he read it, understood the
mute pressure of his friend's hand, and sighed deeply. That hand
would never trace another note.
"Better thus," said Haydn softly, "than a lingering old age of care,
disease, perhaps of poverty! No; I am happy. I have lived not in
vain. I have accomplished my destiny; I have done good. I am ready
for thy call, O Master!"
His spiritual adviser and guide was with him the next hour, and
administered the last consolations of religion. The aged man was
wrapped in devotion. At length he asked to be supported to his
piano; it was opened, and as his trembling fingers touched the keys,
an expression of rapture was kindled in his eyes. The music that
answered his touch seemed the music of inspiration. But it gradually
faded away; the flush gave place to a deadly pallor; and while his
fingers still rested on the keys, he sank back into the arms of his
friend, and gently breathed out his parting spirit. It passed as in a
happy strain of melody!
Prince Esterhazy did honor to the memory of his departed friend by
the pageant of funeral ceremonies. His remains were transported to
Eisenstadt, in Hungary, and placed in the Franciscan vault. The
prince also purchased, at a high price, all his books and manuscripts,
and the numerous medals he had obtained. But his fame belongs to
the world; and in all hearts sensible to the music of truth and nature
is consecrated the memory of Haydn.
PRAYER.
If men but knew—a wise priest gravely said,
His Roman doctor's cap upon his head—
If men but knew what they had won by prayer
Aside from all their worldly thrift and care,
They might be tempted, in a literal sense,
"Always to pray," and with just toil dispense.
THE IMMUTABILITY OF THE
SPECIES.
II.
Of the several circumstances which led to the conception of the
theory here advanced, the first and most important was the
recognition of the fact that variation was left unaccounted for upon
the hypothesis of evolution. Here, if anywhere, we conceived, was to
be found the vulnerable part of Darwinism. It occurred to us that the
probabilities were that a theory was false when it had for its data
phenomena which conform to no law. Our subsequent inquiries
furnished us with nothing by which to rebut this presumption; but
with much to confirm it. Our suspicion at last strengthened into
conviction, and we became confident that contemplation of the
subject of the cause of variation alone could furnish us with a
solution of the whole question.
It is of laws alone of which we speak in these articles. All the facts
adduced by Darwin we accept, and use them merely as illustrations.
We have nothing in common with those who contend that the
refutation of Darwinism lies solely with mere compilers of facts—
fanciers, florists, and breeders. Darwin has heretofore anticipated
nothing but a joinder of issue upon facts. He has apparently never
contemplated being met by a demurrer. He has endeavored to
confound his opponents by a vast multitude of facts; and, owing to
his reverence for whatever has the sanction of antiquity, it has never
entered his mind that any one would be so presumptuous as to
demur to the time-honored conception of new growth, upon which
these facts are based. Of this presumption we are guilty when we
deny the very existence of organic evolution.
In the preceding article we directly intimated, on several occasions,
that no theory other than that of reversion can afford a solution of
the mystery of the appearance of favorable modifications. As some
little diversity of opinion exists respecting Darwin's views on the
subject of the cause of variation, it may be well for us to dwell
awhile on this question, and to furnish some evidence substantiating
our statement.
Darwin, in his Origin of Species, candidly and frankly admits that he
can assign no satisfactory reason for the appearance of favorable
modifications. He ascribes them to "spontaneous variability," and
assures us that "our ignorance of the laws of variation is profound."
We might adduce a number of other expressions equally declaratory
of his inability to assign the cause of variation; but as the Duke of
Argyll has taken such pains to direct attention to this hiatus in
Darwin's evidence, we cannot refrain from quoting from his The
Reign of Law:

"It has not, I think, been sufficiently observed that the theory of
Mr. Darwin does not address itself to the same question, (the
introduction of new forms of life,) and does not even profess to
trace the origin of new forms to any definite law. His theory
gives an explanation, not of the processes by which new forms
first appear, but only of the processes by which, when they have
appeared, they acquire a preference over others, and thus
become established in the world. A new species is, indeed,
according to his theory, as well as with the older theories of
development, simply an unusual birth. The bond of connection
between allied specific and generic forms is, in his view, simply
the bond of inheritance. But Mr. Darwin does not pretend to
have discovered any law or rule according to which new forms
have been born from old forms. He does not hold that outward
conditions, however changed, are sufficient to account for them.
Still less does he connect them with the effort or aspirations of
any organisms after new faculties and powers. He frankly
confesses that 'our ignorance of the laws of variation is
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like