Introduction to Programming in Java: An Interdisciplinary Approach, 2nd edition

Published by Addison-Wesley Professional (March 30, 2017) © 2017

  • Robert Sedgewick Princeton University
  • Kevin Wayne


per month

  • Anytime, anywhere learning with the Pearson+ app
  • Easy-to-use search, navigation and notebook
  • Simpler studying with flashcards

  • A print text (hardcover or paperback) 
  • Free shipping
  • Also available for purchase as an ebook from all major ebook resellers, including

Programming skills are indispensable in today’s world, not just for computer science students, but also for anyone in any scientific or technical discipline. Introduction to Programming in Java, Second Edition, by Robert Sedgewick and Kevin Wayne is an accessible, interdisciplinary treatment that emphasizes important and engaging applications, not toy problems. The authors supply the tools needed for students and professionals to learn that programming is a natural, satisfying, and creative experience, and to become conversant with one of the world’s most widely used languages.

This example-driven guide focuses on Java’s most useful features and brings programming to life for every student in the sciences, engineering, and computer science.

Coverage includes

  • Basic elements of programming: variables, assignment statements, built-in data types, conditionals, loops, arrays, and I/O, including graphics and sound
  • Functions, modules, and libraries: organizing programs into components that can be independently debugged, maintained, and reused
  • Algorithms and data structures: sort/search algorithms, stacks, queues, and symbol tables
  • Applications from applied math, physics, chemistry, biology, and computer science

Drawing on their extensive classroom experience, throughout the text the authors provide Q&As, exercises, and opportunities for creative engagement with the material. Together with the companion materials described below, this book empowers people to pursue a modern approach to teaching and learning programming.

Companion web site ( contains

  • Chapter summaries
  • Supplementary exercises, some with solutions
  • Detailed instructions for installing a Java programming environment
  • Program code and test data suitable for easy download
  • Detailed creative exercises, projects, and other supplementary materials
  • The ideal beginner's introduction to Java programming -- now fully updated for Java 8
  • An applications-based approach: learn through meaningful real-world examples from science, mathematics, engineering, and commercial computing
  • Focuses on what matters: the important and useful language features you absolutely need to know
  • Adds updated coverage of the Java 64-bit memory model, dynamic and functional programming, hashing, and more -- including a brand-new glossary
  • Includes question-and-answer sections, exercises, and creative exercises throughout
  • From Robert Sedgewick and Kevin Wayne, co-authors of the global best-seller Algorithms and pioneering MOOC instructors who've reached hundreds of thousands of students worldwide

This edition has been updated to be fully compatible with Java 8 throughout. Code has been updated and improved, and reflects dozens of bug fixes. Additions and enhancements include:

Revised 64-bit memory model
New section on dynamic programming Hashing
Functional programming Hundreds of stylistic improvements
Glossary of terms

Programs viii

Preface xi


Chapter 1: Elements of Programming 1

1.1 Your First Program 2

1.2 Built-in Types of Data 14

1.3 Conditionals and Loops 50

1.4 Arrays 90

1.5 Input and Output 126

1.6 Case Study: Random Web Surfer 170


Chapter 2: Functions and Modules 191

2.1 Defining Functions 192

2.2 Libraries and Clients 226

2.3 Recursion 262

2.4 Case Study: Percolation 300


Chapter 3: Object-Oriented Programming 329

3.1 Using Data Types 330

3.2 Creating Data Types 382

3.3 Designing Data Types 428

3.4 Case Study: N-Body Simulation 478


Chapter 4: Algorithms and Data Structures 493

4.1 Performance 494

4.2 Sorting and Searching 532

4.3 Stacks and Queues 566

4.4 Symbol Tables 624

4.5 Case Study: Small-World Phenomenon 670


Context 715


Glossary 721

Index 729

APIs 751

Robert Sedgewick is the William O. Baker Professor of Computer Science at Princeton University, where he was founding chairman of the Department of Computer Science. He has held visiting research positions at Xerox PARC, Institute for Defense Analyses, and INRIA, and served on the board of directors at Adobe Systems. His research interests include analytic combinatorics, design and analysis of algorithms and data structures, and program visualization. He has written seventeen books.

Kevin Wayne is the Phillip Y. Goldman Senior Lecturer in Computer Science at Princeton University, where he has taught since 1998, earning several teaching awards. He is an ACM Distinguished Educator and holds a Ph.D. in operations research and industrial engineering from Cornell University.

Need help? Get in touch


All in one place. Pearson+ offers instant access to eTextbooks, videos and study tools in one intuitive interface. Students choose how they learn best with enhanced search, audio and flashcards. The Pearson+ app lets them read where life takes them, no wi-fi needed. Students can access Pearson+ through a subscription or their MyLab or Mastering course.

Privacy and cookies
By watching, you agree Pearson can share your viewership data for marketing and analytics for one year, revocable by deleting your cookies.

Pearson eTextbook: What’s on the inside just might surprise you

They say you can’t judge a book by its cover. It’s the same with your students. Meet each one right where they are with an engaging, interactive, personalized learning experience that goes beyond the textbook to fit any schedule, any budget, and any lifestyle.