Java SE8 for Programmers
By

Rating

Product Description
Product Details

Table of Contents

 

 

Foreword xxiii

Preface xxv

Before You Begin xxxvii

 

Chapter 1: Introduction to Java and Test-Driving a Java Application 1

1.1 Introduction 2

1.2 Object Technology Concepts 4

1.3 Open Source Software 7

1.4 Java 8

1.5 A Typical Java Development Environment 9

1.6 Test-Driving a Java Application 12

1.7 Software Technologies 16

1.8 Keeping Up-to-Date with Information Technologies 18

 

Chapter 2: Introduction to Java Applications; Input/Output and Operators 20

2.1 Introduction 21

2.2 Your First Program in Java: Printing a Line of Text 21

2.3 Modifying Your First Java Program 26

2.4 Displaying Text with printf 28

2.5 Another Application: Adding Integers 29

2.6 Arithmetic 33

2.7 Decision Making: Equality and Relational Operators 34

2.8 Wrap-Up 37

 

Chapter 3: Introduction to Classes, Objects, Methods and Strings 38

3.1 Introduction 39

3.2 Instance Variables, set Methods and get Methods 39

3.3 Primitive Types vs. Reference Types 49

3.4 Account Class: Initializing Objects with Constructors 50

3.5 Account Class with a Balance; Floating-Point Numbers 53

3.6 Wrap-Up 58

 

Chapter 4: Control Statements: Part 1; Assignment, ++ and --Operators 59

4.1 Introduction 60

4.2 Control Structures 60

4.3 if Single-Selection Statement 62

4.4 if…else Double-Selection Statement 63

4.5 Student Class: Nested if…else Statements 67

4.6 while Repetition Statement 69

4.7 Counter-Controlled Repetition 71

4.8 Sentinel-Controlled Repetition 74

4.9 Nested Control Statements 79

4.10 Compound Assignment Operators 81

4.11 Increment and Decrement Operators 81

4.12 Primitive Types 84

4.13 Wrap-Up 85

 

Chapter 5: Control Statements: Part 2; Logical Operators 86

5.1 Introduction 87

5.2 Essentials of Counter-Controlled Repetition 87

5.3 for Repetition Statement 88

5.4 Examples Using the for Statement 92

5.5 do…while Repetition Statement 97

5.6 switch Multiple-Selection Statement 98

5.7 Class AutoPolicy Case Study: Strings in switch Statements 104

5.8 break and continue Statements 108

5.9 Logical Operators 110

5.10 Wrap-Up 115

 

Chapter 6: Methods: ADeeperLook 117

6.1 Introduction 118

6.2 Program Modules in Java 118

6.3 static Methods, static Fields and Class Math 119

6.4 Declaring Methods with Multiple Parameters 121

6.5 Notes on Declaring and Using Methods 124

6.6 Argument Promotion and Casting 125

6.7 Java API Packages 127

6.8 Case Study: Secure Random-Number Generation 128

6.9 Case Study: A Game of Chance; Introducing enum Types 133

6.10 Scope of Declarations 138

6.11 Method Overloading 140

6.12 Wrap-Up 142

 

Chapter 7: Arrays and ArrayLists 144

7.1 Introduction 145

7.2 Arrays 146

7.3 Declaring and Creating Arrays 147

7.4 Examples Using Arrays 148

7.5 Exception Handling: Processing the Incorrect Response 157

7.6 Case Study: Card Shuffling and Dealing Simulation 158

7.7 Enhanced for Statement 163

7.8 Passing Arrays to Methods 164

7.9 Pass-By-Value vs. Pass-By-Reference 166

7.10 Case Study: Class GradeBook Using an Array to Store Grades 167

7.11 Multidimensional Arrays 173

7.12 Case Study: Class GradeBook Using a Two-Dimensional Array 176

7.13 Variable-Length Argument Lists 182

7.14 Using Command-Line Arguments 184

7.15 Class Arrays 186

7.16 Introduction to Collections and Class ArrayList 188

7.17 Wrap-Up 192

 

Chapter 8: Classes and Objects: ADeeperLook 193

8.1 Introduction 194

8.2 Time Class Case Study 194

8.3 Controlling Access to Members 199

8.4 Referring to the Current Object’s Members with the this Reference 200

8.5 Time Class Case Study: Overloaded Constructors 202

8.6 Default and No-Argument Constructors 208

8.7 Notes on Set and Get Methods 208

8.8 Composition 210

8.9 enum Types 213

8.10 Garbage Collection 215

8.11 static Class Members 216

8.12 static Import 220

8.13 final Instance Variables 221

8.14 Time Class Case Study: Creating Packages 222

8.15 Package Access 228

8.16 Using BigDecimal for Precise Monetary Calculations 230

8.17 Wrap-Up 232

 

Chapter 9: Object-Oriented Programming: Inheritance 234

9.1 Introduction 235

9.2 Superclasses and Subclasses 236

9.3 protected Members 238

9.4 Relationship Between Superclasses and Subclasses 239

9.5 Constructors in Subclasses 261

9.6 Class Object 261

9.7 Wrap-Up 262

 

Chapter 10: Object-Oriented Programming: Polymorphism and Interfaces 264

10.1 Introduction 265

10.2 Polymorphism Examples 267

10.3 Demonstrating Polymorphic Behavior 268

10.4 Abstract Classes and Methods 270

10.5 Case Study: Payroll System Using Polymorphism 273

10.6 Allowed Assignments Between Superclass and Subclass Variables 288

10.7 final Methods and Classes 288

10.8 A Deeper Explanation of Issues with Calling Methods from Constructors 289

10.9 Creating and Using Interfaces 290

10.10 Java SE 8 Interface Enhancements 301

10.11 Wrap-Up 302

 

Chapter 11: Exception Handling: A Deeper Look 304

11.1 Introduction 305

11.2 Example: Divide by Zero without Exception Handling 306

11.3 Exception Handling: ArithmeticExceptions and InputMismatchExceptions 308

11.4 When to Use Exception Handling 314

11.5 Java Exception Hierarchy 314

11.6 finally Block 317

11.7 Stack Unwinding and Obtaining Information from an Exception Object 322

11.8 Chained Exceptions 324

11.9 Declaring New Exception Types 327

11.10 Preconditions and Postconditions 327

11.11 Assertions 328

11.12 try-with-Resources: Automatic Resource Deallocation 330

11.13 Wrap-Up 330

 

Chapter 12: Swing GUI Components: Part 1 332

12.1 Introduction 333

12.2 Java’s Nimbus Look-and-Feel 334

12.3 Simple GUI-Based Input/Output with JOptionPane 335

12.4 Overview of Swing Components 338

12.5 Displaying Text and Images in a Window 340

12.6 Text Fields and an Introduction to Event Handling with Nested Classes 344

12.7 Common GUI Event Types and Listener Interfaces 350

12.8 How Event Handling Works 352

12.9 JButton 354

12.10 Buttons That Maintain State 357

12.11 JComboBox; Using an Anonymous Inner Class for Event Handling 363

12.12 JList 367

12.13 Multiple-Selection Lists 370

12.14 Mouse Event Handling 372

12.15 Adapter Classes 377

12.16 JPanel Subclass for Drawing with the Mouse 381

12.17 Key Event Handling 384

12.18 Introduction to Layout Managers 387

12.19 Using Panels to Manage More Complex Layouts 397

12.20 JTextArea 398

12.21 Wrap-Up 401

 

Chapter 13: Graphics and Java 2D 402

13.1 Introduction 403

13.2 Graphics Contexts and Graphics Objects 405

13.3 Color Control 406

13.4 Manipulating Fonts 413

13.5 Drawing Lines, Rectangles and Ovals 418

13.6 Drawing Arcs 422

13.7 Drawing Polygons and Polylines 425

13.8 Java 2D API 428

13.9 Wrap-Up 435

 

Chapter 14: Strings, Characters and Regular Expressions 436

14.1 Introduction 437

14.2 Fundamentals of Characters and Strings 437

14.3 Class String 438

14.4 Class StringBuilder 451

14.5 Class Character 458

14.6 Tokenizing Strings 463

14.7 Regular Expressions, Class Pattern and Class Matcher 464

14.8 Wrap-Up 473

 

Chapter 15: Files, Streams and Object Serialization 474

15.1 Introduction 475

15.2 Files and Streams 475

15.3 Using NIO Classes and Interfaces to Get File and Directory Information 477

15.4 Sequential-Access Text Files 481

15.5 Object Serialization 492

15.6 Opening Files with JFileChooser 500

15.7 (Optional) Additional java.io Classes 503

15.8 Wrap-Up 506

 

Chapter 16: Generic Collections 507

16.1 Introduction 508

16.2 Collections Overview 508

16.3 Type-Wrapper Classes 510

16.4 Autoboxing and Auto-Unboxing 510

16.5 Interface Collection and Class Collections 510

16.6 Lists 511

16.7 Collections Methods 519

16.8 Stack Class of Package java.util 531

16.9 Class PriorityQueue and Interface Queue 533

16.10 Sets 534

16.11 Maps 537

16.12 Properties Class 541

16.13 Synchronized Collections 544

16.14 Unmodifiable Collections 544

16.15 Abstract Implementations 545

16.16 Wrap-Up 545

 

Chapter 17: Java SE 8 Lambdas and Streams 547

17.1 Introduction 548

17.2 Functional Programming Technologies Overview 549

17.3 IntStream Operations 554

17.4 Stream Manipulations 561

17.5 Stream Manipulations 564

17.6 Stream Manipulations 566

17.7 Creating a Stream from a File 576

17.8 Generating Streams of Random Values 579

17.9 Lambda Event Handlers 581

17.10 Additional Notes on Java SE 8 Interfaces 581

17.11 Java SE 8 and Functional Programming Resources 582

17.12 Wrap-Up 582

 

Chapter 18: Generic Classes and Methods 584

18.1 Introduction 585

18.2 Motivation for Generic Methods 585

18.3 Generic Methods: Implementation and Compile-Time Translation 587

18.4 Additional Compile-Time Translation Issues: Methods That Use a Type Parameter as the Return Type 590

18.5 Overloading Generic Methods 593

18.6 Generic Classes 594

18.7 Raw Types 601

18.8 Wildcards in Methods That Accept Type Parameters 605

18.9 Wrap-Up 609

 

Chapter 19: Swing GUI Components: Part 2 611

19.1 Introduction 612

19.2 JSlider 612

19.3 Understanding Windows in Java 616

19.4 Using Menus with Frames 617

19.5 JPopupMenu 625

19.6 Pluggable Look-and-Feel 628

19.7 JDesktopPane and JInternalFrame 633

19.8 JTabbedPane 636

19.9 BoxLayout Layout Manager 638

19.10 GridBagLayout Layout Manager 642

19.11 Wrap-Up 652

 

Chapter 20: Concurrency 653

20.1 Introduction 654

20.2 Thread States and Life Cycle 656

20.3 Creating and Executing Threads with the Executor Framework 659

20.4 Thread Synchronization 663

20.5 Producer/Consumer Relationship without Synchronization 672

20.6 Producer/Consumer Relationship: ArrayBlockingQueue 680

20.7 (Advanced) Producer/Consumer Relationship with synchronized, wait, notify and notifyAll 683

20.8 (Advanced) Producer/Consumer Relationship: Bounded Buffers 690

20.9 (Advanced) Producer/Consumer Relationship: The Lock and Condition Interfaces 698

20.10 Concurrent Collections 705

20.11 Multithreading with GUI: SwingWorker 707

20.12 sort/parallelSort Timings with the Java SE 8 Date/Time API 721

20.13 Java SE 8: Sequential vs. Parallel Streams 723

20.14 (Advanced) Interfaces Callable and Future 726

20.15 (Advanced) Fork/Join Framework 730

20.16 Wrap-Up 730

 

Chapter 21: Accessing Databases with JDBC 732

21.1 Introduction 733

21.2 Relational Databases 734

21.3 A books Database 735

21.4 SQL 739 21.4.1 Basic SELECT Query 739

21.5 Setting up a Java DB Database 747

21.6 Manipulating Databases with JDBC 750

21.7 RowSet Interface 767

21.8 PreparedStatements 769

21.9 Stored Procedures 785

21.10 Transaction Processing 785

21.11 Wrap-Up 786

 

Chapter 22: JavaFX GUI 787

22.1 Introduction 788

22.2 JavaFX Scene Builder and the NetBeans IDE 789

22.3 JavaFX App Window Structure 790

22.4 Welcome App–Displaying Text and an Image 791

22.5 Tip Calculator App–Introduction to Event Handling 798

22.6 Wrap-Up 813

 

Chapter 23: ATM Case Study, Part 1: Object-Oriented Design with the UML 815

23.1 Case Study Introduction 816

23.2 Examining the Requirements Document 816

23.3 Identifying the Classes in a Requirements Document 824

23.4 Identifying Class Attributes 830

23.5 Identifying Objects’ States and Activities 835

23.6 Identifying Class Operations 839

23.7 Indicating Collaboration Among Objects 845

23.8 Wrap-Up 852

 

Chapter 24: ATM Case Study Part 2: Implementing an Object-Oriented Design 856

24.1 Introduction 857

24.2 Starting to Program the Classes of the ATM System 857

24.3 Incorporating Inheritance and Polymorphism into the ATM System 862

24.4 ATM Case Study Implementation 868

24.5 Wrap-Up 893

 

Appendix A: Operator Precedence Chart 895

 

Appendix B: ASCII Character Set 897

 

Appendix C: Keywords and Reserved Words 898

 

Appendix D: Primitive Types 899

 

Appendix E: Using the Debugger 900

E.1 Introduction 901

E.2 Breakpoints and the run, stop, cont and print Commands 901

E.3 The print and set Commands 905

E.4 Controlling Execution Using the step, step up and next Commands 907

E.5 The watch Command 909

E.6 The clear Command 912

E.7 Wrap-Up 914

 

Appendix F: Using the Java API Documentation 915

F.1 Introduction 915

F.2 Navigating the Java API 916

 

Appendix G: Creating Documentation with javadoc 924

G.1 Introduction 924

G.2 Documentation Comments 924

G.3 Documenting Java Source Code 925

G.4 javadoc 932

G.5 Files Produced by javadoc 933

 

Appendix H: Unicode® 937

H.1 Introduction 937

H.2 Unicode Transformation Formats 938

H.3 Characters and Glyphs 939

H.4 Advantages/Disadvantages of Unicode 940

H.5 Using Unicode 940

H.6 Character Ranges 942

 

Appendix I: Formatted Output 944

I.1 Introduction 945

I.2 Streams 945

I.3 Formatting Output with printf 945

I.4 Printing Integers 946

I.5 Printing Floating-Point Numbers 947

I.6 Printing Strings and Characters 949

I.7 Printing Dates and Times 950

I.8 Other Conversion Characters 952

I.9 Printing with Field Widths and Precisions 954

I.10 Using Flags in the printf Format String 956

I.11 Printing with Argument Indices 960

I.12 Printing Literals and Escape Sequences 960

I.13 Formatting Output with Class Formatter 961

I.14 Wrap-Up 962

 

Appendix J: Number Systems 963

J.1 Introduction 964

J.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers 967

J.3 Converting Octal and Hexadecimal Numbers to Binary Numbers 968

J.4 Converting from Binary, Octal or Hexadecimal to Decimal 968

J.5 Converting from Decimal to Binary, Octal or Hexadecimal 969

J.6 Negative Binary Numbers: Two’s Complement Notation 971

 

Appendix K: Bit Manipulation 973

K.1 Introduction 973

K.2 Bit Manipulation and the Bitwise Operators 973

K.3 BitSet Class 983

 

Appendix L: Labeled break and continue Statements 987

L.1 Introduction 987

L.2 Labeled break Statement 987

L.3 Labeled continue Statement 988

 

Appendix M: UML 2: Additional Diagram Types 990

M.1 Introduction 990

M.2 Additional Diagram Types 990

 

Appendix N: Design Patterns 992

N.1 Introduction 992

N.2 Creational, Structural and Behavioral Design Patterns 993

N.3 Design Patterns in Packages java.awt and javax.swing 998

N.4 Concurrency Design Patterns 1005

N.5 Design Patterns Used in Packages java.io and java.net 1006

N.6 Design Patterns Used in Package java.util 1010

N.7 Wrap-Up 1011

 

 

Index 1013

 

About the Author

Paul Deitel and Harvey Deitel are from Deitel & Associates, Inc., the internationally recognized programming languages authoring and corporate-training organization. Millions of people worldwide have used Deitel books, e-books, LiveLessons video training and online resource centers to master Java™, C++, Android™ app development, iOS® app development, C#, .NET, Visual Basic®,  Visual C++®, C, Internet and web programming, JavaScript®, XML, Perl®,  Python®, PHP and more.

Reviews

COMMENTS FROM RECENT EDITIONS REVIEWERS   “This book is amazing if you want to learn how to program in Java SE 8.”
—Jorge Vargas, Yumbling and a Java Champion
“Excellent introduction to functional programming with lambdas and streams.”—Manfred Riem, Java Champion
“A great overview on how concurrency can help developers; it’s very readable and focuses on leveraging  multi-core processors.”—Johan Vos, LodgON and Java Champion
“Gives programmers the benefit of the wisdom derived from many years of software development experience.”
—Edward F. Gehringer, North Carolina State University
‘‘You’ll be well on your way to becoming a great Java programmer with this book.’’
—Peter Pilgrim, Java Champion, Consultant
‘‘Comprehensive introduction to Java, now in its eighth major iteration. With clear descriptions and useful tips and hints, this is a great book for studying the world’s most popular programming language. Introduces good design practices and methodologies right from the beginning. An excellent starting point for developing high-quality robust Java applications.’’—Simon Ritter, Oracle Corporation
‘‘Provides a great jump-start on JavaFX, the successor to Swing. A very impressive treatment is given to many JavaFX concepts, from developing a simple application without writing any code, to developing an application  that contains a variety of graphical user interface elements.’’—James L. Weaver, Oracle Java Evangelist and author of Pro JavaFX 2
‘‘Fantastic book and reference. Provides great detail on the latest Java features including lambdas. The code examples make it easy to understand the concepts.’’
—Lance Andersen, Principal Member of the Technical Staff, Oracle Corporation
“Introduces JavaFX, the great new way to develop client applications in Java; I like the use of Scene Builder to create the  GUI with drag-and-drop design rather than doing it by hand, which shows the way it should be done.” 
—Simon Ritter, Oracle Corporation
“I like the DeckOfCards example [in the Arrays and ArrayLists chapter]. The evolving inheritance example is a good approach to motivating inheritance. I like the [polymorphism] employee example. Very thorough and well explained GUI chapter. Thorough strings chapter; I like the clear definitions of regular expressions. Good introduction to collections; Hashtable performance  discussion was good. Solid treatment of threading.”—Dr. Danny Coward, Oracle Corporation
“A great book with a myriad of examples from various application domains.”—William E. Duncan, Louisiana State University
“Updated to reflect the state of the art in Java technologies; deep and crystal-clear explanations.”
—José Antonio González Seco, Parliament of Andalusia
“Very interesting and entertaining. Good job explaining arrays before the more abstract collections. Guiding the reader to avoid dangerous patterns is equally important as explaining the correct syntax; great work! Excellent introduction to object-oriented concepts; rather than just a theoretical overview, it points the reader to how OO is implemented. Great polymorphism chapter— should help the reader distinguish between abstract classes and Java 8 interfaces with default methods. Good discussion of  analyzing stack traces, since exceptions provide useful debugging information. Great job explaining Java2D. Shows how easily files and the filesystem are accessible using Java. Very good introduction to hash tables. Pushing all lambda-related content in a single chapter is hard, but the authors succeeded; I like the way they show how lambda expressions compare to existing code with inner classes; they show that it’s the compiler that does the work. Great introduction to BigInteger and BigDecimal. One of the best explanations of generics I’ve read. Clearly explains collections, and when and how they should be used; it’s important  that developers understand this, since choosing a wrong implementation can lead to massive performance penalties  or hard-to-understand programs.”—Johan Vos, LodgON and Java Champion
“An easy-to-read conversational style. Clear code examples propel readers to become proficient in Java.”
—Patty Kraft, San Diego State University

“The [early] introduction of the class concept is clearly presented. I applaud the authors for their topical research and illustrative examples.The clearest explanation of pass-by-value and pass-by-reference that I’ve encountered. A logical progression of  inheritance and the rationale for properly implementing encapsulation in a system involving an inheritance hierarchy.  The polymorphism and exception-handling discussions are the best I’ve seen. An excellent strings chapter.”
—Ric Heishman, George Mason University

“Of immense value to practitioners of the object-oriented approach. Demystifies inheritance and polymorphism, and illustrates their use in getting elegant, simple and maintainable code. The OO design case study presents the object-oriented approach in  a simple manner, from requirements to Java code.”—Vinod Varma, Astro Infotech Private Limited
“Easy-to-follow examples! OO design techniques are incorporated throughout. The concept of inheritance is built through  examples and is very understandable. Great examples of polymorphism and interfaces. I appreciate the coverage of  GUI threading issues.“—Sue McFarland Metzger, Villanova University
“Most major concepts are illustrated by complete, annotated programs. JDBC is explained well.” —Shyamal Mitra, University of Texas at Austin “A great reference for anyone working with Java. Good introduction to the software engineering process.” —Lance Andersen, Oracle Corporation “Suitable for new programmers, intermediate-level programmers who want to hone their skills, and expert programmers  who need a well organized reference. Event handling and layouts are well explained.”
—Manjeet Rege, Rochester Institute of Technology  “Comprehensive treatment of Java programming, covering both the latest version of the language and Java SE APIs.”—Dr. Danny Coward, Oracle Corporation

“A nice illustration of how to use Java to generate impressive graphics.”—Amr Sabry, Indiana University
“The OOD ATM case study puts many concepts from previous chapters together in a plan for a large program, showing the  object-oriented design process—the discussion of inheritance and polymorphism is especially good as the authors integrate these into the design.”—Susan Rodger, Duke University
“The transition from design to implementation is explained powerfully—the reader can easily understand the design issues  and how to implement them in Java.”—S. Sivakumar, Astro Infotech Private Limited
“If you think a 3rd edition is just going to be a repeat then you would not do this book justice. It has the breadth and depth to get  a beginning Java programmer started, but at the same time it is a good companion for a more seasoned programmer who wants to get updated to the latest version of Java. Perfect introduction to strings. Good explanation of static vs. non-static methods and variables.  Best introduction to Java 2D I’ve seen! The collections framework is well explained. A nice introduction to JavaFX.” 
—Manfred Riem, Java Champion

“Clearly describes the use cases for different parts of the Java APIs. The tips and observations are very useful. Clearly explains opportunities and pitfalls in Java. Rather than telling the reader what to do and not do, the rationale behind these opportunities and pitfalls is explained. The new features introduced in Java 8 are well mixed with older functionality.”
—Johan Vos, LodgON and Java Champion

“Really good, clear explanation of object-oriented programming fundamentals. Excellent polymorphism chapter. Covers all the essentials of strings. Good to see things like try-with-resources and DirectoryStream being used. Excellent generic collections chapter. Covering lambdas and streams in one chapter is a tough challenge; you’ve done well. Concurrency chapter gives good coverage of numerous aspects.”—Simon Ritter, Oracle Corporation
“GUI examples are very good. Graphics examples are easy to follow. The JavaFX GUI chapter provides a solid introduction to using the JavaFX Scene Builder, demonstrating how easy it is to create Java-based GUI applications.“ 
—Lance Andersen, Oracle Corporation
“Nice breadth of coverage of traditional core Java and programming topics as well as newer areas such as lambda expressions and areas becoming more critical such as concurrent programming. Very nice coverage of files, streams, object serialization and generics.”
—Evan Golub, University of Maryland
“The real-world examples can be used with Java SE 7 or 8; great case studies. The inheritance chapter is excellent; examples are gender neutral which is perfect.”—Khallai Taylor, Triton College and Lonestar College-Kingwood
“Good approach to important concepts like static, accessors and private fields and their validation. [Classes and Objects:  A Deeper Look] coverage is very interesting—I like how the book flows. Excellent explanations of Java SE 8 interfaces  and exceptions.”—Jorge Vargas, Yumbling and a Java Champion  

Ask a Question About this Product More...
 
Look for similar items by category
Home » Books » Computers » Programming » Java
This title is unavailable for purchase as none of our regular suppliers have stock available. If you are the publisher, author or distributor for this item, please visit this link.

Back to top