Java for Programmers, 5/e
Deitel Developer SeriesThe professional programmer’s Deitel® guide to Java with integrated generative AI
Written for programmers with a background in another high-level language, in this book, you’ll learn modern Java development hands on using the latest Java idioms and features and genAIs. For more details, see the Preface and its two-page “High-Level Overview.”
In the context of 200+ real-world code examples, you’ll quickly master Java fundamentals then move on to arrays, strings, regular expressions, JSON/CSV processing with the Jackson library, private- and public-key cryptography, classes, inheritance, polymorphism, interfaces, dependency injection, exceptions, generic collections, custom generics, functional programming with lambdas and streams, JavaFX GUI, graphics and multimedia, platform threads, virtual threads, structured concurrency, scoped values, building API-based Java genAI apps, database with JDBC and SQLite, the Java Platform Module System and JShell for Python-like interactivity.
Note: Java for Programmers, 5/e is a subset of Java How to Program, 12/e — please do not purchase both books.
Source Code
Not a GitHub user? Download the ZIP file
Preface
View the Preface to learn about the book’s approach and features
Table of Contents
View the full Table of Contents for each chapter’s coverage.
Buy the Book
Before You Begin
View the Before You Begin for info on setting up your environment.
Features:
GenAI Prompt Engineering, API Calls, 600 GenAI Exercises
ChatGPT, Gemini, Claude, Perplexity
Multimodal: Text, Code, Images, Audio, Speech-to-Text, Text-to-Speech, Video
Generics: Collections, Classes, Methods
Functional Programming: Lambdas & Streams
JavaFX: GUI, Graphics, Multimedia
Concurrency: Parallel Streams, Virtual Threads, Structured Concurrency, Scoped Values, Concurrent Collections, Multi-Core
Database: JDBC, SQL, SQLite
Java Platform Module System (JPMS)
Objects Natural: Java API, String, BigInteger, BigDecimal, Date/Time, Cryptography, ArrayList, Regex, JSON, CSV, Web Services
JShell for Python-Like Interactivity
Generative AI Innovations in Java for Programmers, 5/e
Fully Coded GenAI Case Studies
Chapter 19 presents the following code examples that interact with OpenAI’s APIs: Text Summarization, Sentiment Analysis, Accessible Image Descriptions, Language Detection & Translation, Java Code Generation, Named-Entity Recognition & Structured Outputs, Speech-to-Text, Text-to-Speech, Image Generation, Creating Closed Captions for a Video, Moderation.
GenAI Prompt Exercises
We fed the complete list of all the book’s approximately 600 genAI exercises (a 100+ page PDF) to ChatGPT, Gemini, Claude and Perplexity, asking them to categorize the kinds of things we do in those exercises. Next, we fed their categorized lists to the four genAIs, asking them to summarize the summaries, and we chose the best one—Claude in this case:
- Code Generation and Implementation—Writing new Java programs from specifications. Implementing specific features, algorithms and APIs. Creating test programs and practical applications. Generating solutions for basic and advanced tasks.
- Code Refactoring and Enhancement—Modernizing code. Improving code structure, readability, and maintainability. Converting between different approaches while maintaining functionality. Improving performance.
- Educational Content—Creating tutorials, exercises, and learning materials. Further exploring complex concepts. Developing programming exercises. Writing comprehensive documentation and guides.
- Technical Analysis—Analyzing code behavior and feature implementations. Comparing different approaches, tools, and frameworks. Evaluating trade-offs in design decisions. Breaking down complex technical concepts.
- Best Practices and Standards—Implementing coding standards and design patterns. Addressing security considerations. Optimizing performance. Following Java development best practices.
- Technology Evaluation—Comparing libraries, tools, and frameworks. Assessing the pros and cons of different approaches. Making informed technology choices. Exploring new features and updates.
- Debugging and Error Handling—Finding and fixing syntax and logical errors. Implementing exception handling. Improving fault tolerance. Preventing common pitfalls.
- API and Library Integration—Working with Java APIs and external libraries. Understanding API features and capabilities. Implementing integration techniques. Creating API documentation and tutorials.
- Real-world Applications—Developing practical use cases and industry applications. Creating interactive applications (GUIs, games, multimedia). Implementing real-world scenarios. Building sample projects.
- Performance Optimization—Analyzing and improving performance. Optimizing resource usage. Conducting benchmarks. Implementing efficiency improvements.
- Creative Development—Building multimodal applications. Creating visualizations. Generating test scenarios and sample data. Developing unique use cases.
GenAI API-Based Java Programming Exercises
Chapter 19, Building API-Based Java Generative AI Applications, suggests challenging project exercises like creating genAI multimedia apps that can debate one another and using genAIs to build and solve crossword puzzles. We fed the 94 exercises into the genAIs, asking for a categorized summary of them, then summarized the summaries. Here’s what Claude produced:
- Multimodal Applications— Building comprehensive tools that combine text, image, audio, speech and video capabilities. Creating integrated experiences like interactive books. Developing multimedia educational content.
- Text-Based Applications—Document processing (indexing, summarization, exploration). Creative writing (stories, poetry, debates). Language tools (translation, tone rewriting). Professional document creation (resumes, presentations). Structured outputs.
- Image Processing Applications—Generative art and design (logos, fashion, floor plans). Technical visualization (UML diagrams). Image analysis and recognition.
- Audio and Music Applications—Speech processing (transcription, voice cloning). Music generation (MIDI, Magenta AI). Multilingual audio applications. Podcast and audio content analysis.
- Educational Tools—Programming tutors (Java, coding exercises). Subject-specific learning aids (math). Course content creation. Interactive educational experiences.
- Gaming and Puzzle Applications—Puzzle generators and solvers. Interactive game development.
- Video—Investigating and experimenting with generative AI video creation tools.
- Chatbot Development—Character-based chat experiences. Specialized domain experts.
- Research and Analysis Tools—Medical applications (researching drug discovery and personalized medicine). AI capability exploration. Text detection and analysis. Educational research.
- Creative Applications—Children’s book creation. Interactive storytelling. Artistic content generation. Creative writing.
- Practical Tools and Utilities—Document generators. Translation services. Content summarizers. Professional tools (resume filters, presentation creators).
Testimonials from the
Java for Programmers, 5/e Reviewers
From the Back Cover
■ Brian Canada, Professor of Computational Science, University of South Carolina Beaufort
“The future of Java programming is here, and this new edition of Deitel is leading the charge! By embracing genAI head-on, the authors are potentially revolutionizing programming education. Through its integrative approach to the use and study of genAI, this book is positioned to be the leading book in modern Java and its applications. Indeed, I expect that it should be widely adopted by instructors who want to ingrain in their students an appreciation for the critical role that Java will play in data science, machine learning, artificial intelligence, and cybersecurity.
The book’s innovative and forward-thinking use of genAI facilitates reader engagement and inspires readers to think critically about the benefits and limitations of AI as a programming aid. Chapter 19 could become everyone’s favorite new Java book chapter—the generative AI API-based code examples are interesting and fun.
All audiences of this book should read the Preface—there’s so much to get excited about! It demonstrates, with refreshing transparency and honesty, how much love and care went into the reinvention of an already outstanding Java book by bringing it into a new frontier of what it means to be a programmer in today’s world. Bravo! Your Preface statement: “GenAI has created an ultra-high-level programming capability that will leverage your Java learning experience and ability to produce robust, top-quality Java software quickly, conveniently and economically.” is a great conclusion to the Preface intro—really helps justify the use of genAI!”
■ Emily Navarro, Ph.D., Continuing Lecturer, Department of Informatics, University of California, Irvine
“After reading your whole book, it was fun to read the Preface that wraps everything up at a high level. You have done some amazing work here, and I’m glad to have been a small part of it as a reviewer! I especially appreciate how difficult it must have been to make sure everything was as up to date as possible with the speed at which things change in this fi eld, and the deftness with which you incorporated all the focus on GenAI and data science that’s in this book.”
■ Jeanne Boyarsky, CodeRanch, Java Champion
“The generative AI exercises are awesome and refl ect the way modern developers work! They are fun and let the reader explore and learn about AI by using AI—how meta. This allows readers to expand their knowledge and get a feel for the AIs’ code-related capabilities.”
Additional Testimonials
■ Brian Canada, Professor of Computational Science, University of South Carolina Beaufort
Excellent coverage of the latest Java language features. The Strings chapter sets the stage for important applications in NLP (a critical ingredient to making genAI systems work) and cryptography (a critical ingredient to information security) that are introduced in objects-natural case studies in Chapters 7 (private-key cryptography) and 11 (public-key cryptography). The objects-natural case study on class BigInteger is especially pertinent at a time when cybersecurity is more important than ever and programmers need to develop an appreciation for secure software engineering practices.
Real-World Modeling with Inheritance, Polymorphism and Interfaces, covers a lot but I feel smarter after reading it and going through the associated genAI exercises! These are cleverly written so prompted AIs will guide the reader to “fill in the gaps” and provide application areas where these techniques are used.
The objects-natural case study on ArrayLists provides a “sneak peek” at the Java Collections Framework showing how this data structure solves problems caused by the limitations of Java arrays. The Java Collections Framework chapter does an admirable job covering most key data structures and how Java’s built-in collections implement them. The section on hash tables is informative. The coverage of newer JDK techniques, such as convenience factory methods, is appropriate.
The genAI exercises are highly valuable and fun, giving the reader new tools for filling in details and thinking critically about how and why certain practices are followed in Java in particular and object-oriented programming in general. An admirable job of contrasting “checked” and “unchecked” exceptions. Suggests mechanisms for “bulletproofing your code” with validation logic so that certain exceptions aren’t thrown in the first place. The genAI prompt exercises on the types of OpenAI API messages passed to the chat completion API were very helpful for cementing my understating.
A broad introduction to fundamental OOP inheritance and polymorphism concepts. The use of interfaces to implement runtime polymorphism logically follows a similar discussion involving abstract classes. I like the discussion of the relative benefits of composition vs. inheritance. Accomplishes the herculean task of covering tight vs. loose coupling and dependency injection in just a few pages. Great to see the Builder design pattern in action.
Amazing AI description of the beach photo! In grad school my research group was barely scratching the surface of identifying objects in images—things have come a long way! The closed captions demo is cool!
■ Ron Veen, Java Developer, Special Agent at Team Rockstars IT, co-author Virtual Threads, Structured Concurrency, and Scoped Values: Explore Java’s New Threading Model
This is the best book for learning Java that I have come across in 25+ years of Java experience. I‘ve suggested using it to train developers in my company and in the companies where I do consultancy. A detailed explanation of every major part of the core Java language. Excellent discussion of inheritance and polymorphism.
Teaches how to use and incorporate AI in your daily software creation process. Using tools like ChatGPT, Gemini, Claude and Perplexity is now an essential skill to gain a competitive advantage. Awesome Chapter 19 that clearly introduces the power of AI API-based app development.
I have never seen such a clear explanation of Java concurrency. The Big O discussion teaches the costs and consequences of design decisions. Great discussion of creating custom classes. Excellent intro to the Java Platform Module System. Best intro to JShell I’ve seen. I like the detailed discussion of how streams and lambdas work and the thorough explanation of exceptions.
■ Emily Navarro, Ph.D., Continuing Lecturer, Department of Informatics, University of California, Irvine
The book’s “objects-natural” approach introduces substantial pre-existing Java classes and object interaction before diving into custom class creation in later chapters. I like the objects-natural case study with the date/time example—a good forced dive into the Java API documentation. I like that inheritance, interfaces, and composition are covered in the same chapter, as it is a logical progression that tells the story of what is the best approach for an OO Java program.
The Building Java Generative AI API-Based Applications chapter taught me things I did not know. Interesting and useful genAI challenges are presented. I appreciate how AI tools were used to help write the chapter and the text was transparent about it. The 94 end-of-chapter genAI exercises are exciting, creative, and fun.
I really enjoyed the Files chapter—it brought in a lot of the latest and most-used technologies, such as JSON, CSV, networking APIs, and cryptography. Great job introducing and motivating generic class and method concepts and bringing in CS theory to support the practical application of Java’s generic collection data structures.
■ Jeanne Boyarsky, CodeRanch, Java Champion
Uses the latest Java features to write code in the most modern ways.
Cool, genAIs can read diagrams! [Prompt genAIs with class Account’s UML class diagram, asking them to generate the corresponding Java class declaration.] I like the genAI “why questions,” such as, “prompt genAIs for insights as to why Java constructors cannot return values.” I didn’t know GenAI would tell me to fix the errors even if I didn’t ask or could explain how the Java method-call stack works using text-only, step-by-step diagrams made of characters! Cool!
Great list of NLP applications! The objects natural NLP, regex and cryptography security examples are awesome! They let the reader use String knowledge while also learning real-world principles. I like how the industrial-strength encryption warning is emphasized in the objects natural cryptography case study!
Includes a substantial treatment of JavaFX. The walkthrough of how to set up a JavaFX application in Scene Builder was excellent. Great JavaFX layouts table—I get a good sense of what I can do. Nice to see accessibility in the JavaFX chapters.
A good intro to modules. Covers all of the basics (and more) while remaining approachable. I like that you included the structure of a modularized application. The VideoPlayer module-dependency graph is a great real example. The progression of running the services example with no providers, then one, then two is a fun way to show the ServiceLoader really is picking providers at runtime!
I like the number and variety of JShell examples and exercises. I like how lambdas and method references are presented. Generics can be a complicated topic—the authors focused on the most common use cases and made them easy to understand. Yay. An objects-natural case study on BigDecimal! Interesting discussion of how half-even banker’s rounding works for processing monetary amounts.
I like the concurrency examples. It was nice seeing concepts from other chapters like JavaFX and the OpenWeatherMap example making another appearance. The explanations of virtual threads, structured concurrency and scoped values were good.
■ Carl Dea, Lead Software Developer at a global business consulting and services company, co-author JavaFX 9 by Example
Kudos (Loved it)!!! By far Chapter 17 is the most compelling, fun, and comprehensive presentation of JavaFX Graphics and Multimedia APIs for those wanting to build graphics apps and games. This chapter is practically flawless!
I like how the authors begin with CSS styling on various vector-based shapes then later present how to reproduce the shapes using the Canvas API. Next, we learn how to transform scene graph nodes and investigate the JavaFX animation APIs to perform motion effects such as rotation, scaling, & translation. The authors also demo the powerful AnimationTimer API.
I really like the Media Player example showing how to play MP4 video of Nasa’s Artemus 1. They also show how to display 3D shapes and colorize their surfaces, and use cameras and light sources. Some great additions are JavaFX23 CSS transitions and an intro to FXGL (game library). Nice to see lambdas improving code readability, especially in the media player event handlers. GenAI prompts allow the reader to gain more insight on JavaFX topics.
Great intro to JavaFX for career minded individuals to become the next generation of app developers. I like how the authors along with genAI prompts first take the reader through a design-centric approach to visualize the application’s UI by using Scene Builder without jumping into Java source code right away.
All examples are real-world problems. Your SpotOn app is a fun game with cool sound effects. A really fun Chapter 16 progresses to more advanced topics including mouse events, layouts, properties, and displaying & scaling images. Many examples/exercises are reminiscent of common desktop applications such as Paint and Photo Viewer programs. Excellent use of record classes for a Book object.
■ José Antonio González Seco, Parliament of Andalusia, Spain
New in this edition is the perfect integration of generative AI technologies as tools to reinforce learning, deepen understanding of the topics and help in the programmer’s daily work. Provides readers practical instruction in prompt engineering, which has become essential to maintaining productivity in any field. The generative AI exercises are very interesting and give the book a modern feel. It’s a bit scary how well ChatGPT solves some of the exercises and explains its solutions. Dependency injection (DI) is a great addition to this fifth edition.
■ Trisha Gee, Java Champion
The combination of theory, clear explanations and example code makes this both a great learning experience and an excellent reference that is useful for any developer to have close at hand. A great job of covering pretty much everything in inheritance, polymorphism and interfaces starting from the simplest to the most advanced. Perfect level of exception handling coverage. You get a good feel for when you’d use lambdas and streams. Great overview of the Java Platform Module System! Code examples are sufficiently complex to be realistic, but simple enough to understand. Covers all the topics I expected to see on modularity (more actually, especially around visualizing dependencies). Solid intro to JShell with plenty of hands-on code demos.
■ Bob Myers, Computer Science Department, Florida State University
A nice mix of core language concepts with illustrations from many useful Java libraries. I like the contrast drawn in the objects-natural case study between use of raw floating point types and the BigDecimal class type when handling monetary amounts.
A good overview of class building, with a solid cross-section of examples. The new information about record classes is well-presented. A nice intro to the core concepts of relational databases. Great examples of core SQL query commands and advice on prepared statements.
Nice intro to tasks that AIs can accomplish. Good sections illustrating test runs for common tasks, like translating between languages, creating summaries of text, generating images, generating descriptions from an image, etc. Lots of exercises to practice these tasks! A clear and concise discussion of JShell.
■ Johan Vos, Co-founder and CTO, Cloud Products at Gluon, Java Champion, co-author The Definitive Guide to Modern Java Clients with JavaFX: Cross-Platform Mobile and Cloud Development
Easy intro on how to start with JavaFX. It is clear that the developer doesn’t need to learn lots of new concepts/ideas, yet immediately can start creating applications with Scene Builder. Well done! Covers a number of fundamental JavaFX components, enabling developers to create real applications.
■ David Vlijmincx, Senior Software Developer, JPoint, co-author Virtual Threads, Structured Concurrency, and Scoped Values: Explore Java’s New Threading Model
I really liked the Concurrency chapter and its breadth—it covers all the basics one needs to work with platform and virtual threads.
Previous Java How to Program Reviewers
We’re grateful to the many academic and technical reviewers who’ve contributed their time and expertise to reviewing Java How to Program‘s previous editions.
Reviewers and their affiliations at the time:
- Marty Allen (University of Wisconsin-La Crosse)
- Lance Andersen (Oracle Corporation)
- Soundararajan Angusamy (Sun Microsystems)
- Joseph Bowbeer (Consultant)
- Dr. Danny Coward (Oracle Corporation)
- William E. Duncan (Louisiana State University)
- Robert Field (JShell chapter only; JShell Architect, Oracle)
- Diana Franklin (University of California, Santa Barbara)
- Trisha Gee (JetBrains, Java Champion)
- Edward F. Gehringer (North Carolina State University)
- Jonathan Giles (Consulting Member of Technical Staff, Oracle)
- Brian Goetz (Oracle Corporation)
- Evan Golub (University of Maryland)
- Dr. Huiwei Guan (Professor, Department of Computer & Information Science, North Shore Community College)
- Edwin Harris (M.S. Instructor at The University of North Florida’s School of Computing), Ric Heishman (George Mason University)
- Dr. Heinz Kabutz (JavaSpecialists.eu)
- Patty Kraft (San Diego State University)
- Lawrence Premkumar (Sun Microsystems)
- Tim Margush (University of Akron)
- Sue McFarland Metzger (Villanova University)
- Shyamal Mitra (The University of Texas at Austin)
- Maurice Naftalin (Java Champion)
- Peter Pilgrim (Consultant)
- Manjeet Rege, Ph.D. (Rochester Institute of Technology)
- Manfred Riem (Java Champion)
- Simon Ritter (Oracle Corporation)
- Susan Rodger (Duke University)
- Amr Sabry (Indiana University)
- José Antonio González Seco (Parliament of Andalusia)
- Robert C. Seacord (CERT, Software Engineering Institute, Carnegie Mellon University)
- Sang Shin (Sun Microsystems)
- S. Sivakumar (Astra Infotech Private Limited)
- Bruno Souza (President of SouJava—the Brazilian Java Society, Java Specialist at ToolsCloud, Java Champion and SouJava representative at the Java Community Process),
- Raghavan “Rags” Srinivas (Intuit)
- Dr. Venkat Subramaniam (President, Agile Developer, Inc. and Instructional Professor, University of Houston, Java Champion)
- Monica Sweat (Georgia Tech)
- Khallai Taylor (Assistant Professor, Triton College and Adjunct Professor, Lonestar College—Kingwood)
- Jorge Vargas (Yumbling and a Java Champion)
- Vinod Varma (Astra Infotech Private Limited)
- Johan Vos (CTO, Cloud Products at Gluon, Java Champion)
- James L. Weaver (Oracle Corporation and author of Pro JavaFX 2)
- Alexander Zuev (Sun Microsystems)
Share This Page