This textbook presents a focused and accessible primer on the fundamentals of Java programming, with extensive use of illustrative examples and hands-on exercises.
Addressing the need to acquire a good working model of objects in order to avoid possible misconceptions, the text introduces the core concepts of object-oriented programming at any stage, supported by the use of contour diagrams. Each chapter has one or more complete programs to illustrate the various ideas presented, and to help readers learn how to write programs on their own. Chapter summaries and practical exercises also are included to help the reader to review their progress and practice their skills.
This substantially updated second edition has been expanded with additional exercises, and includes new material on bit manipulation and parallel processing.
Topics and features:
- Introduces computing concepts in Chapter 0 for new programmers
- Adds new chapters on bit-manipulation and parallel processing
- Contains exercises at the end of each chapter with selected answers
- Supports both text-based and GUI-based Input/Output
- Objects can be introduced first, last, or intermixed with other material
- Uses contour diagrams to illustrate objects and recursion
- Discusses OOP concepts such as overloading, class methods, and inheritance
- Introduces string variables and illustrates arrays and array processing
- Discusses files, elementary exception processing, and the basics of Javadoc
This concise and easy-to-follow textbook/guide is ideal for students in an introductory programming course. It is also suitable as a self-study guide for both practitioners and academics.
Author(s): James T. Streib, Takako Soma
Series: Undergraduate Topics in Computer Science
Edition: 2
Publisher: Springer
Year: 2023
Language: English
Pages: 446
City: Cham
Tags: Contour Diagrams; Java; Object-Oriented; Programming; Algorithms
Preface
Contents
0 Introduction to Computing Concepts
0.1 Introduction
0.2 Overview of Hardware and Software
0.2.1 Hardware
0.2.2 Software
0.2.3 History and Java
0.2.4 High-level Translation
0.3 Introduction to Computational Thinking
0.4 Essentials of Software Design
0.4.1 Syntax, Semantics, and Errors
0.4.2 Design Methodology
0.4.3 Tools and Techniques
0.5 A Brief Look at Computer Ethics
0.6 Summary
0.7 Exercises (Items Marked with an * Have Solutions in Appendix E)
1 Input/Output, Variables, and Arithmetic
1.1 Introduction
1.2 Java Skeleton
1.3 “Hello World!”
1.3.1 Text-based Output
1.3.2 GUI-based Output
1.4 Variables and Constants
1.5 Assignment Statements
1.6 Output
1.6.1 Text-based
1.6.2 GUI-Based
1.7 Input
1.7.1 Text-based
1.7.2 GUI-based
1.8 Arithmetic Statements
1.8.1 Binary Operators
1.8.2 Precedence
1.8.3 Unary Operators
1.8.4 Incrementing
1.8.5 Summing
1.8.6 Arithmetic Functions
1.9 Comments
1.10 Complete Program: Implementing a Simple Program
1.11 Summary
1.12 Exercises (Items Marked with an * Have Solutions in Appendix E)
2 Objects: An Introduction
2.1 Introduction
2.2 Classes and Objects
2.3 Public and Private Data Members
2.4 Value-Returning Methods
2.5 void Methods and Parameters
2.6 Creating Objects and Invoking Methods
2.7 Contour Diagrams
2.8 Constructors
2.9 Multiple Objects and Classes
2.10 Unified Modeling Language (UML) Class Diagrams
2.11 Complete Program: Implementing a Simple Class and Client Program
2.12 Summary
2.13 Exercises (Items Marked with an * Have Solutions in Appendix E)
3 Selection Structures
3.1 Introduction
3.2 If-Then Structure
3.3 If-Then-Else Structure
3.4 Nested If Structures
3.4.1 If-Then-Else-If Structure
3.4.2 If-Then-If Structure
3.4.3 Dangling Else Problem
3.5 Logical Operators
3.6 Case Structure
3.7 Complete Programs: Implementing Selection Structures
3.7.1 Simple Program
3.7.2 Program with Objects
3.8 Summary
3.9 Exercises (Items Marked with an * Have Solutions in Appendix E)
4 Iteration Structures
4.1 Introduction
4.2 Pretest Indefinite Loop Structure
4.2.1 Count-Controlled Indefinite Iteration Structure
4.2.2 Sentinel Controlled Loop
4.3 Posttest Indefinite Loop Structure
4.4 Definite Iteration Loop Structure
4.5 Nested Iteration Structures
4.6 Potential Problems
4.7 Complete Programs: Implementing Iteration Structures
4.7.1 Simple Program
4.7.2 Program with Objects
4.8 Summary
4.9 Exercises (Items Marked with an * Have Solutions in Appendix E)
5 Objects: Revisited
5.1 Sending an Object to a Method
5.2 Returning an Object from a Method
5.3 Overloaded Constructors and Methods
5.3.1 Overloaded Constructors
5.3.2 Default Constructors
5.3.3 Overloaded Methods
5.4 Use of the Reserved Word this
5.5 Class Constants, Variables, and Methods
5.5.1 Local, Instance, and Class Constants
5.5.2 Local, Instance, and Class Variables
5.5.3 Class Methods
5.6 Complete Programs: Implementing Objects
5.6.1 Program Focusing on Overloaded Methods
5.6.2 Program Focusing on Class Data Members and Class Methods
5.7 Summary
5.8 Exercises (Items Marked with an * Have Solutions in Appendix E)
6 Strings
6.1 Introduction
6.2 String Class
6.3 String Concatenation
6.4 Methods in String Class
6.4.1 The length Method
6.4.2 The indexOf Method
6.4.3 The substring Method
6.4.4 Comparison of Two String Objects
6.4.5 The equalsIgnoreCase Method
6.4.6 The charAt Method
6.5 The toString Method
6.6 Complete Program: Implementing String Objects
6.7 Summary
6.8 Exercises (Items Marked with an * Have Solutions in Appendix E)
7 Arrays
7.1 Introduction
7.2 Array Declaration
7.3 Array Access
7.4 Input, Output, Simple Processing, and Methods
7.4.1 Input
7.4.2 Output
7.4.3 Simple Processing
7.4.4 Passing an Array to and from a Method
7.5 Reversing an Array
7.6 Searching an Array
7.6.1 Sequential Search
7.6.2 Binary Search
7.6.3 Elementary Analysis
7.7 Sorting an Array
7.7.1 Simplified Bubble Sort
7.7.2 Modified Bubble Sort
7.8 Two-Dimensional Arrays
7.8.1 Declaration, Creation, and Initialization
7.8.2 Input and Output
7.8.3 Processing Data
7.8.4 Passing a Two-Dimensional Array to and from a Method
7.8.5 Asymmetrical Two-Dimensional Arrays
7.9 Arrays of Objects
7.10 Complete Program: Implementing an Array
7.11 Summary
7.12 Exercises (Items Marked with an * Have Solutions in Appendix E)
8 Recursion
8.1 Introduction
8.2 The Power Function
8.3 Stack Frames
8.4 Fibonacci Numbers
8.5 Complete Program: Implementing Recursion
8.6 Summary
8.7 Exercises (Items Marked with an * Have Solutions in Appendix E)
9 Objects: Inheritance and Polymorphism
9.1 Inheritance
9.2 Protected Variables and Methods
9.3 Abstract Classes
9.4 Polymorphism
9.5 Complete Program: Implementing Inheritance and Polymorphism
9.6 Summary
9.7 Exercises (Items Marked with an * Have Solutions in Appendix E)
10 Elementary File Input and Output
10.1 Introduction
10.2 File Input
10.3 File Output
10.4 File Input and Output Using an Array
10.5 Specifying the File Location
10.6 Complete Programs: Implementing File Input and Output
10.6.1 Matrix Multiplication
10.6.2 Sorting Data in a File
10.7 Summary
10.8 Exercises (Items Marked with an * Have Solutions in Appendix E)
11 Bit Manipulation
11.1 Introduction
11.2 Simple Conversions
11.3 Declarations and Assignments
11.4 Bit-wise Logic Operations
11.5 Testing, Clearing, Setting, and Toggling
11.6 Shifting
11.7 Precedence
11.8 Complete Program: Implementing Bit-wise Operators
11.9 Summary
11.10 Exercises (Items Marked with an * Have Solutions in Appendix E)
12 Introduction to Parallel Processing Programming
12.1 Multiprocessor Systems
12.2 Programming Multi-core and Shared Memory Multiprocessor Using Pyjama
12.2.1 Using Pyjama to Write Multithreaded Programs
12.2.2 “Hello World”
12.2.3 Sorting Building Blocks
12.3 Analysis
12.4 Complete Program: Implementing Parallel Inner Product
12.5 Summary
12.6 Exercises (Items Marked with an * Have Solutions in Appendix E)
Appendix A: Explanation and Elaboration of Concepts in Chapter 1
A.1 Skeleton Program and “Hello World”
A.2 Text-based Output: print and println
A.3 Text-based Input
A.4 Overview of Java Packages
A.5 More on GUI-based Output and Input
A.6 Confirmation Dialog Boxes
A.7 Option Dialog Boxes
Appendix B: Exceptions
B.1 Exception Class and Error Class
B.2 Handling an Exception
B.3 Throwing Exceptions and Multiple catch Blocks
B.4 Checked and Unchecked Exceptions
Appendix C: Javadoc Comments
C.1 Javadoc
C.2 More Javadoc Tags
C.3 Generating Javadoc Documentation from a Command Line
Appendix D: Glossary
Appendix E: Answers to Selected Exercises
References and Useful Websites
Index