Instant ebooks textbook Java programming from problem analysis to program design 5th ed Edition D S Malik download all chapters
Instant ebooks textbook Java programming from problem analysis to program design 5th ed Edition D S Malik download all chapters
https://ebookfinal.com/download/c-programming-program-design-
including-data-structures-5th-edition-d-s-malik/
https://ebookfinal.com/download/java-an-introduction-to-problem-
solving-and-programming-7th-edition-walter-savitch/
https://ebookfinal.com/download/simply-java-an-introduction-to-java-
programming-programming-series-1st-edition-james-levenick/
https://ebookfinal.com/download/professional-java-programming-
jdk-5-5th-edition-w-clay-richardson/
Java How to Program 7th Edition Harvey M. Deitel
https://ebookfinal.com/download/java-how-to-program-7th-edition-
harvey-m-deitel/
https://ebookfinal.com/download/java-how-to-program-4th-edition-
harvey-m-deitel/
https://ebookfinal.com/download/asp-net-website-programming-problem-
design-solution-c-edition-marco-bellinaso/
https://ebookfinal.com/download/java-me-game-programming-2nd-ed-
edition-john-p-flynt/
https://ebookfinal.com/download/mastering-aspectj-aspect-oriented-
programming-in-java-1st-edition-joseph-d-gradecki/
Java programming from problem analysis to program
design 5th ed Edition D S Malik Digital Instant Download
Author(s): D S Malik
ISBN(s): 9781111577643, 1111577641
Edition: 5th ed
File Details: PDF, 7.00 MB
Year: 2012
Language: english
This is an electronic version of the print textbook. Due to electronic rights restrictions,
some third party content may be suppressed. Editorial review has deemed that any suppressed
content does not materially affect the overall learning experience. The publisher reserves the right
to remove content from this title at any time if subsequent rights restrictions require it. For
valuable information on pricing, previous editions, changes to current editions, and alternate
formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.
1019763_FM_VOL-I.qxp 9/17/07 4:22 PM Page viii
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
S 50
R 51
FIFTH EDITION
D.S. MALIK
Australia Brazil Japan Korea Mexico Singapore Spain United Kingdom United States
TO
My Daughter
Shelly Malik
B RIEF C ONTENTS
PREFACE xix
1. An Overview of Computers and Programming Languages 1
9. Arrays 551
INDEX 1023
TABLE OF C ONTENTS
Preface xix
Language of a Computer 6
Programming Methodologies 19
Structured Programming 19
Object-Oriented Programming 19
Quick Review 21
Exercises 23
Table of Contents | vii
Data Types 32
Primitive Data Types 32
Expressions 40
Mixed Expressions 41
class String 45
Strings and the Operator + 46
Input 48
Allocating Memory with Named Constants and Variables 48
Putting Data into Variables 51
Declaring and Initializing Variables 55
Input (Read) Statement 56
Reading a Single Character 61
Output 66
Quick Review 94
Exercises 97
Input/Output 129
Formatting Output with printf 129
Using Dialog Boxes for Input/Output 139
Formatting the Output Using the String Method format 146
Exercises 167
Exercises 232
Exercises 306
Exercises 378
Exercises 445
Finalizers 507
Exercises 538
ARRAYS 551
9 Why Do We Need Arrays? 552
Arrays 553
Alternate Ways to Declare an Array 555
Accessing Array Elements 555
Specifying Array Size during Program Execution 557
Array Initialization during Declaration 558
Arrays and the Instance Variable length 558
Processing One-Dimensional Arrays 559
Array Index Out of Bounds Exception 564
Declaring Arrays as Formal Parameters to Methods 564
Assignment Operator, Relational Operators, and Arrays:
A Precaution 565
Arrays as Parameters to Methods 567
Table of Contents | xiii
Exercises 623
Polymorphism 664
Operator instanceof 670
Interfaces 681
xiv | Java Programming: From Problem Analysis to Program Design, Fifth Edition
Exercises 712
Exercises 777
Menus 844
Exercises 866
RECURSION 873
13
Recursive Definitions 874
Direct and Indirect Recursion 876
Infinite Recursion 877
Designing Recursive Methods 877
Exercises 897
Exercises 934
Chapter 2 998
Chapter 3 1001
Chapter 4 1002
Chapter 5 1004
Chapter 6 1007
Chapter 7 1008
Chapter 8 1010
Chapter 9 1014
xviii | Java Programming: From Problem Analysis to Program Design, Fifth Edition
Chapter 10 1016
Chapter 11 1018
Chapter 12 1019
Chapter 13 1020
Chapter 14 1020
INDEX 1023
P REFACE TO THE F IFTH
E DITION
Welcome to Java Programming: From Problem Analysis to Program Design, Fifth Edition.
Designed for a first Computer Science (CS1) Java course, this text will provide a breath of
fresh air to you and your students. The CS1 course serves as the cornerstone of the Computer
Science curriculum. My primary goal is to motivate and excite all programming students,
regardless of their level. Motivation breeds excitement for learning. Motivation and excite-
ment are critical factors that lead to the success of the programming student. This text is the
culmination and development of my classroom notes throughout more than fifty semesters of
teaching successful programming.
Warning: This text can be expected to create a serious reduction in the demand for program-
ming help during your office hours. Other side effects include significantly diminished student
dependency on others while learning to program.
The primary focus in writing this text is on student learning. Therefore, in addition to clear
explanations, we address the key issues that otherwise impede student learning. For example, a
common question that arises naturally during an early programming assignment is: ‘‘How
many variables and what kinds are needed in this program?’’ We illustrate this important and
crucial step by helping students learn why variables are needed and how data in a variable is
manipulated. Next students learn that the analysis of the problem will spill the number and
types of the variables. Once students grasp this key concept, control structures (selection and
loops) become easier to learn. The second major impediment in learning programming is
parameter passing. We pay special attention to this topic. First students learn how to use
predefined methods and how actual and formal parameters relate. Next students learn about
user-defined methods. They see visual diagrams that help them learn how methods are called
and how formal parameters affect actual parameters. Once students have a clear understanding
of these two key concepts, they readily assimilate advanced topics.
The topics are introduced at a pace that is conducive to learning. The writing style is friendly,
engaging, and straightforward. It parallels the learning style of the contemporary CS1 student.
Before introducing a key concept, the student learns why the concept is needed, and then sees
examples illustrating the concept. Special attention is paid to topics that are essential in
mastering the Java programming language and in acquiring a foundation for further study
of computer science.
xx | Java Programming: From Problem Analysis to Program Design, Fifth Edition
Other important topics include debugging techniques and techniques for avoiding programming
bugs. When a beginner compiles his/her first program and sees that the number of errors exceeds the
length of this first program, he/she becomes frustrated by the plethora of errors, only some of which
can be interpreted. To ease this frustration and help students learn to produce correct programs,
debugging and bug avoidance techniques are presented systematically throughout the text.
Approach
Once conceived as a Web programming language, Java slowly but surely found its way into
classrooms where it now serves as a first programming language in computer science curricula
(CS1). Java is a combination of traditional style programming—programming with a non-
graphical user interface—and modern style programming with a graphical user interface
(GUI). This book introduces you to both styles of programming. After giving a brief
description of each chapter, we discuss how to read this book.
Chapter 1 briefly reviews the history of computers and programming languages. The reader
can quickly skim and become familiar with some of the hardware and software components of
the computer. This chapter also gives an example of a Java program and describes how a Java
program is processed. The two basic problem-solving techniques, structured programming
and object-oriented design, are also presented.
After completing Chapter 2, students become familiar with the basics of Java and are ready to
write programs that are complicated enough to do some computations. The debugging section
in this chapter illustrates how to interpret and correct syntax errors.
The three terms that you will encounter throughout the book are—primitive type variables,
reference variables, and objects. Chapter 3 makes clear distinctions between these terms and
sets the tone for the rest of the book. An object is a fundamental entity in an object-oriented
Preface to the Fifth Edition | xxi
programming language. This chapter further explains how an object works. The class
String is one of the most important classes in Java. This chapter introduces this class and
explains how various methods of this class can be used to manipulate strings. Because input/
output is fundamental to any programming language, it is introduced early, and is covered in
detail in Chapter 3. The debugging section in this chapter illustrates how to find and correct
logical errors.
Chapters 4 and 5 introduce control structures used to alter the sequential flow of execution.
The debugging sections in these chapters discuss and illustrate logical errors associated with
selection and looping structures.
Java is equipped with powerful yet easy-to-use graphical user interface (GUI) components
to create user-friendly graphical programs. Chapter 6 introduces various GUI components
and gives examples of how to use these components in Java application programs. Because
Java is an object-oriented programming language, the second part of Chapter 6 discusses
and gives examples of how to solve various problems using object-oriented design
methodology.
Chapter 7 discusses user-defined methods. Parameter passing is a fundamental concept in any
programming language. Several examples, including visual diagrams, help readers understand
this concept. It is recommended that readers with no prior programming background spend
extra time on this concept. The debugging section in this chapter discuss how to debug a
program using stubs and drivers.
Chapter 8 discusses user-defined classes. In Java, a class is an important and widely used
element. It is used to create Java programs, group related operations, and it allows users to
create their own data types. This chapter uses extensive visual diagrams to illustrate how
objects of classes manipulate data.
Chapter 9 describes arrays. This chapter also introduces variable length formal parameter lists.
In addition, this chapter introduces foreach loops and explains how this loop can be used to
process the elements of an array. This chapter also discusses the sequential searching algorithm
and the class Vector.
Inheritance is an important principle of object-oriented design. It encourages code reuse.
Chapter 10 discusses inheritance and gives various examples to illustrate how classes are
derived from existing classes. In addition, this chapter also discusses polymorphism, abstract
classes, inner classes, and composition.
An occurrence of an undesirable situation that can be detected during program execution is
called an exception. For example, division by zero is an exception. Java provides extensive
support for handing exceptions. Chapter 11 shows how to handle exceptions in a program.
Chapter 11 also discusses event handling, which was introduced in Chapter 6. Chapter 12
picks up the discussion of GUI components started in Chapter 6. This chapter introduces
additional GUI components and discusses how to create applets.
Chapter 13 introduces recursion. Several examples illustrate how recursive methods
execute.
xxii | Java Programming: From Problem Analysis to Program Design, Fifth Edition
Chapter 14 discusses a binary search algorithm as well as bubble sort, selection sort, insertion
sort, and quick sort algorithms. Additional content covering the sorting algorithms bubble sort
and quick sort is provided online at www.cengagebrain.com.
Appendix A lists the reserved words in Java. Appendix B shows the precedence and
associativity of the Java operators. Appendix C lists the ASCII (American Standard Code
for Information Interchange) portion of the Unicode character set as well as the EBCDIC
(Extended Binary Code Decimal Interchange) character set.
Appendix D contains additional topics in Java. The topics covered are converting a base 10
number to binary (base 2) number and vice versa, converting a number from base 2 to base 8 (base
16) and vice versa, how to compile and execute a Java program using command line statements,
how to create Java style documentation of the user-defined classes, how to create packages, how to
use user-defined classes in a Java program, and enum type. Appendix E gives answers to the odd-
numbered exercises in the text. Those odd-numbered exercises with very long solutions will not
be in the text, but will be provided to students online at www.cengagebrain.com.
Figure 1 shows a chapter dependency diagram for this book. Solid arrows indicate that the
chapter at the beginning of the arrow is required before studying the chapter at the end of the
arrow. A dotted arrow indicates that the chapter at the beginning of the arrow is not essential
to studying the chapter at the end of the dotted arrow.
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6 Chapter 7
Chapter 8 Chapter 9
Chapter 10 Chapter 14
Chapter 11
Chapter 12
Chapter 13
A dotted arrow means that the chapter is not essential to studying the following chapter.
All source code and solutions have been written, compiled, and quality assurance tested
with Java 6.0 and the version of Java 7.0 available at the time this book was being typeset.
FEATURES OF THE BOOK
Four-color
interior design
shows
accurate code
and related
comments.
The debugging
sections show
how to find
and correct
syntax and
semantic
(logical)
errors.
More than
250 visual
diagrams,
both
extensive and
exhaustive,
illustrate difficult
concepts.
Numbered Examples
illustrate the key
concepts with their
relevant code. The
programming code in
these examples is
followed by a Sample
Run. An explanation
then follows that
describes what each
line in the code does.
Notes highlight
important facts
about the concepts
introduced in the
chapter.
Programming
Examples are
complete programs
featured in each
chapter. These
examples include the
accurate, concrete
stages of Input,
Output, Problem
Analysis and Algorithm
Design, and a
Complete Program
Listing.
Exercises further
reinforce learning
and ensure that
students have, in
fact, mastered the
material.
Programming
Exercises challenge
students to write
Java programs with
a specified
outcome.
S UPPLEMENTAL
R ESOURCES
The following supplemental materials are available when this book is used in a classroom setting.
Most instructor teaching tools, outlined below, are available with this book on a single
CD-ROM, and are also available for instructor access at login.cengage.com.
ExamViewÒ
This textbook is accompanied by ExamView, a powerful testing software package that allows
instructors to create and administer printed, computer (LAN-based), and Internet exams.
ExamView includes hundreds of questions that correspond to the topics covered in this text,
enabling students to generate detailed study guides that include page references for further
review. These computer-based and Internet testing components allow students to take exams
at their computers, and save the instructor time because each exam is graded automatically.
PowerPoint Presentations
Microsoft PowerPoint slides are available for each chapter. These slides are provided as a teaching
aid for classroom presentations, either to make available to students on the network for chapter
review, or to be printed for classroom distribution. Instructors can add their own slides for
additional topics that they introduce to the class.
Distance Learning
Course Technology is proud to present online courses in WebCT and Blackboard to provide
the most complete and dynamic learning experience possible. For more information on how
xxxiv | Java Programming: From Problem Analysis to Program Design, Fifth Edition
to bring distance learning to your course, contact your local Course Technology sales
representative.
Source Code
The source code is available for students at www.cengagebrain.com. At the cengagebrain.com home
page, search for the ISBN of your title (from the back cover of your book) using the search
box at the top of the page. This will take you to the product page where these resources can
be found. The source code is also available on the Instructor Resources CD-ROM. The
input files needed to run some of the programs are also included with the source code.
Solution Files
The solution files for all programming exercises are available for instructor download at
http://login.cengage.com and are also available on the Instructor Resources CD-ROM. The
input files needed to run some of the programming exercises are also included with the
solution files.
A CKNOWLEDGMENTS
There are many people I must thank who, in one way or another, contributed to the success
of this book. First, I would like to thank those who e-mailed numerous comments that helped
to improve on the fourth edition. I am thankful to Professors S.C. Cheng and Randall Crist
for constantly supporting this project.
I owe a great deal to the following reviewers, who patiently read each page of every chapter
of the current version and made critical comments that helped to improve the book:
Nadimpalli Mahadev, Fitchburg State College and Baoqiang Yan, Missouri Western State
University. Additionally, I would like to thank Brian Candido, Springfield Technical Com-
munity College, for his review of the proposal package. The reviewers will recognize that
their suggestions have not been overlooked and, in fact, made this a better book.
Next, I express thanks to Brandi Shailer, Acquisitions Editor, for recognizing the importance
and uniqueness of this project. All this would not have been possible without the careful
planning of Senior Product Manager Alyssa Pratt. I extend my sincere thanks to Alyssa, as well
as to Content Project Manager, Lisa Weidenfeld. I also thank Sreejith Govindan of Integra
Software Services for assisting us in keeping the project on schedule. I would like to thank
Chris Scriver and Serge Palladino of the MQA department of Course Technology for patiently
and carefully proofreading the text, testing the code, and discovering typos and errors.
I am thankful to my parents for their blessings.
Finally, I am thankful to the support of my wife Sadhana, and especially my daughter Shelly,
to whom this book is dedicated. They cheered me up whenever I was overwhelmed during
the writing of this book.
We welcome any comments concerning the text. Comments may be forwarded to the
following e-mail address: malik@creighton.edu.
D.S. Malik
1
CHAPTER
A N O VERVIEW OF
COMPUTERS AND
P ROGRAMMING
L ANGUAGES
I N T H I S C H A P T E R , YO U W I L L :
. Learn about different types of computers
. Explore the hardware and software components of a computer system
. Learn about the language of a computer
. Learn about the evolution of programming languages
. Examine high-level programming languages
. Discover what a compiler is and what it does
. Examine how a Java program is processed
. Learn about the Internet and World Wide Web
. Learn what an algorithm is and explore problem-solving techniques
. Become familiar with structured and object-oriented programming design methodologies
2 | Chapter 1: An Overview of Computers and Programming Languages
Introduction
Terms such as ‘‘the Internet,’’ which was unfamiliar just a few years ago, are now
common. Elementary school students regularly ‘‘surf’’ the Internet and use computers
to design their classroom projects. Many people use the Internet to look up information
and to communicate with others. These Internet activities are all made possible by the
availability of different software, also known as computer programs. Software is devel-
oped by using programming languages. The Java programming language is especially well
suited for developing software to accomplish specific tasks. Our main objective is to teach
you how to write programs in the Java programming language. Before you begin
programming, it is useful if you understand some of the basic terminology and different
components of a computer. We begin with an overview of the history of computers.
Milton Abbey.
King Athelstan. “Athelstan’s Mother.”
Founder of Milton Abbey. Buried in Milton Abbey.
(From a Painting in the Church.) (From a Painting in the Church.)
The view of the church at the beginning of this chapter will save
the necessity of a description of its exterior. But the interior contains
many things which demand notice.
And first of all must be mentioned the “ornament,” which many
antiquaries consider to be a Tabernacle for reserving the Eucharist.
This very beautiful and richly carved “Sacrament-house” dates from
the fifteenth century, and is made of oak in the form of a spire
composed of four storeys, the lowest containing the opening through
which the reserved elements may have been passed. It is not in its
original position, but is now fastened to the west wall of the south
transept beneath the triforium.
The great altar-screen is a very lofty, beautiful, and peculiarly rich
construction, even though the two long rows of ornamental niches
now lack the statues of the saints that once stood in them—saints
with “very bluff countenances, painted in very bright colours and
heavily gilded.” On its lower portion there is a Latin inscription, which
bids prayers for the souls of William Middleton, Abbot of Milton, and
Thomas Wilken, Vicar of the parish, who worthily decorated
(“honorifice depinxerunt”) the screen in 1492. The three stone sedilia
in the sanctuary are fine specimens. The bosses throughout the
church are of very rich design.
The Abbey also contains two fifteenth century oil paintings of a
crude description, one of which represents Athelstan, the founder,
giving to the first head of the monastery a model of the minster (with
three spires)[25] over which he was to preside. The other painting is
supposed to represent Athelstan’s mother—Egwynna, “femina
illustris.”[26]
The tombs of the abbots within the Abbey are most interesting. In
front of the altar steps there is a Purbeck marble grave-slab of the
fourteenth century, which was once inlaid with the brass figure of an
abbot clad in pontificalia, with a marginal Latin inscription in
Lombardic capitals:
ABBA : VALTERE : TE : FATA : CITO : RAPVERE : TE :
RADINGA : DEDIT : SED : MORS : MALE : NOS : TVA :
LEDIT.
This is the slab of an Abbot of Milton whose Christian name was
Walter, and who was formerly a monk of Reading, probably Walter
de Sydelinge, who died in 1315. In the north transept there is a
thirteenth century grave-slab of another abbot. This slab is also of
Purbeck marble, but the upper portion is broken off. The remaining
portion shows part of an incised figure of an abbot, with pastoral
staff, chasuble, stole, maniple, alb, and an imperfect marginal
inscription in Norman French:
VVS ⁝ KI ⁝ PAR ⁝ I ⁝ CI ⁝ PASSET ⁝ PVR ⁝ LEALME ⁝
PRIE...
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com