Quick+Java+(David+Matuszek)+(Z-Library)
java
No Description
890
Views
60
Downloads
0.00
Total Donations
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
Quick Java “We’ll be doing this next project in Java.” Unfortunately, you’re a C++ programmer, or maybe a Python programmer. How are you going to get up to speed in a hurry? There are lots of Java books for beginners, telling you all about what a computer is and how it represents everything in bits. You don’t need that. At the other extreme, there are thousand-page tomes that you aren’t going to get through in a few days, if ever. You need something in-between. This book is intended to fill that gap. It’s written for the programmer who doesn’t need to be taught how to program, just how to do it in Java—and who needs to get started in a hurry. Java is covered from the inside out. First, all the things that go inside a class, most of which are practically identical to C++. After that, all the various and complicated kinds of classes and interfaces and how they relate to each other in large-scale programs. Testing is essential, so (unlike most Java books) JUnit is covered in detail. Then, in case you need to go in that direction, some functional programming, a little about parallel programming, and more than enough to get you started in building GUIs (graphical user interfaces) and doing animation. There’s a lot in this little book and, despite my best efforts, you won’t learn Java in a weekend. But it should be a good start.
Page
3
FEATURES • Circular approach allows very fast entry into Java • Full description of JUnit testing • Summary of functional programming in Java • Introduction to synchronization and parallel processing • Extensive description of building GUIs
Page
4
Quick Java David Matuszek
Page
5
Designed cover image: David Matuszek First edition published 2024 by CRC Press 2385 NW Executive Center Drive, Suite 320, Boca Raton FL 33431 and by CRC Press 4 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN CRC Press is an imprint of Taylor & Francis Group, LLC © 2024 David Matuszek Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, access www.copyright. com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not available on CCC please contact mpkbookspermissions@tandf.co.uk Trademark notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification and explanation without intent to infringe. Library of Congress Cataloging-in-Publication Data Names: Matuszek, David L., author. Title: Quick Java / David Matuszek. Description: First edition. | Boca Raton : CRC Press, 2024. | Series: Quick programming | Includes bibliographical references and index. Identifiers: LCCN 2023011142 (print) | LCCN 2023011143 (ebook) | ISBN 9781032502779 (paperback) | ISBN 9781032515830 (hardback) | ISBN 9781003402947 (ebook) Subjects: LCSH: Java (Computer program language) Classification: LCC QA76.73.J38 M35257 2024 (print) | LCC QA76.73.J38 (ebook) | DDC 005.13/3‐‐dc23/eng/20230609 LC record available at https://lccn.loc.gov/2023011142 LC ebook record available at https://lccn.loc.gov/2023011143 ISBN: 978-1-032-51583-0 (hbk) ISBN: 978-1-032-50277-9 (pbk) ISBN: 978-1-003-40294-7 (ebk) DOI: 10.1201/9781003402947 Typeset in Minion by MPS Limited, Dehradun
Page
6
To all my students past, present, and future
Page
7
(This page has no text content)
Page
8
Contents Author, xv Preface, xvii Versions, xix Chapter 1 ■ A Lightning Tour of Java 1 1.1 Projects 1 1.2 First Glimpse: The Circle Class 2 1.3 Data 4 1.4 Operators 5 1.5 Program Structure 6 1.6 Statements 8 1.7 Program Execution 9 1.8 Hello World 10 Chapter 2 ■ Preliminaries 13 2.1 IDEs 13 2.2 Comments and Tags 14 Chapter 3 ■ The “Inner Language” of Java 17 3.1 Variables and Naming Conventions 17 3.2 Basic Data Types 19 3.2.1 Primitive Types 19 3.2.2 Arrays 19 vii
Page
9
3.2.3 Strings 21 3.2.4 Exceptions 22 3.2.5 Operators and Precedence 23 3.2.6 Declarations and Casting 25 3.2.7 Constants 26 3.2.8 Methods 27 3.2.9 Methods Calling Methods 29 3.2.10 Overloading 30 3.2.11 Scope 30 3.2.11.1 Variables Declared in Classes 30 3.2.11.2 Variables Declared in Methods 31 3.2.11.3 Variables Declared in Blocks 32 3.3 Statement Types 32 3.3.1 Statements Also in C++ 34 3.3.1.1 Blocks 34 3.3.1.2 Assignment Statements 35 3.3.1.3 Method Calls and Varargs 36 3.3.1.4 If Statements 36 3.3.1.5 While Loops 38 3.3.1.6 Do-while Loops 39 3.3.1.7 Traditional For Loops 40 3.3.1.8 For-each Loop 41 3.3.1.9 Classic switch Statements 42 3.3.1.10 Labeled Statements 44 3.3.1.11 Break Statements 44 3.3.1.12 Continue Statements 45 3.3.1.13 Return Statements 46 3.3.1.14 Empty Statements 46 3.3.2 Statements Not in C++ 47 3.3.2.1 Assert Statements 47 3.3.2.2 Print “Statements” 48 viii ▪ Contents
Page
10
3.3.2.3 Switch Statements and Expressions 49 3.3.2.4 Pattern Matching in switch Statements 50 3.3.2.5 Try-catch-finally 52 3.3.2.6 Throw Statements 53 3.3.3 Reading from a File 54 3.3.4 Try With Resources 55 3.3.5 Writing to a File 56 3.4 Classes and Objects 57 3.4.1 Some Useful Objects 58 3.4.1.1 String Objects 58 3.4.1.2 StringBuilder Objects 59 3.4.1.3 Using Scanner 60 3.4.1.4 Console 61 3.4.1.5 Objects, Generics, and Stacks 62 3.4.1.6 Maps 63 3.4.1.7 The Java API 64 3.5 Objects and Classes 66 Chapter 4 ■ The “Outer Language” of Java 69 4.1 Class Structure 69 4.1.1 A Simple Class 70 4.1.2 The Class Header 71 4.1.3 Interfaces I 72 4.1.4 Fields 73 4.1.5 Constructors I 74 4.1.6 Defining Methods 75 4.1.7 Example: Bank Account 77 4.1.8 References 78 4.1.9 Constructors II 80 4.1.10 Static 82 4.1.11 Escaping Static 84 Contents ▪ ix
Page
11
4.1.12 The Main Method 84 4.1.13 A More Complete Example 86 4.2 Inheritance 88 4.3 Casting Objects 89 4.4 Overriding 90 4.4.1 Overriding toString 92 4.4.2 Overriding equals 93 4.4.3 Overriding hashCode 94 Chapter 5 ■ Advanced Java 97 5.1 Information Hiding 97 5.1.1 Reasons for Privacy 98 5.1.2 Getters and Setters 98 5.1.3 Private Constructors 99 5.2 The Inner Language 100 5.2.1 General 100 5.2.1.1 Ordering 100 5.2.1.2 Javadoc 101 5.2.1.3 Var Declarations 104 5.2.1.4 Namespaces 104 5.2.2 Data 105 5.2.2.1 Wrapper Classes 105 5.2.2.2 Integers 105 5.2.2.3 Doubles 107 5.2.2.4 Characters and Unicode 107 5.2.2.5 Booleans 109 5.2.2.6 Other Primitives 109 5.2.2.7 Arrays 110 5.2.2.8 Strings 111 5.2.2.9 Multiline Strings 112 5.2.2.10 Formatter 113 5.2.2.11 Regular Expressions 116 x ▪ Contents
Page
12
5.2.3 Collections 117 5.2.3.1 Iterators 119 5.2.4 Additional Operators 120 5.2.4.1 instanceof 120 5.2.4.2 The Ternary Operator 120 5.2.4.3 Bit and Shift Operators 121 5.2.4.4 Increment and Decrement Operators 121 5.3 The Outer Language 122 5.3.1 Generic Classes 122 5.3.2 Interfaces II 124 5.3.3 Abstract Classes 126 5.3.4 Final and Sealed Classes 128 5.3.5 Inner Classes 129 5.3.5.1 Member Classes 129 5.3.5.2 Static Member Classes 130 5.3.5.3 Local Inner Classes 131 5.3.5.4 Anonymous Inner Classes 132 5.3.6 Enums 133 5.3.7 Records 135 5.3.8 Serialization 136 5.3.9 Modules 137 5.3.10 Build Tools 138 Chapter 6 ■ Functional Programming 141 6.1 Function Literals 141 6.2 Functional Interfaces 142 6.3 Implicit Functional Interfaces 144 6.4 Persistent Data Structures 144 Chapter 7 ■ Unit Testing 147 7.1 Philosophy 147 7.2 What to Test 148 Contents ▪ xi
Page
13
7.3 JUnit 149 7.4 JUnit 5 Assertions 150 7.5 Testing Exceptions 152 7.6 Assumptions 153 7.7 Simple Test Example 153 Chapter 8 ■ GUIs and Dialogs 157 8.1 A Brief History 157 8.2 Dialogs 157 8.2.1 Message Dialog 158 8.2.2 Confirm Dialog 158 8.2.3 Input Dialog 158 8.2.4 Option Dialog 159 8.2.5 Color Chooser Dialog 160 8.2.6 Load File Dialog 160 8.2.7 Save File Dialog 161 8.2.8 Custom Dialog 162 Chapter 9 ■ How to Build a GUI Program 163 9.1 Event-Driven Programs 163 9.2 The Event Dispatch Thread 164 9.3 Import the Necessary Packages 164 9.4 Make a Container 165 9.5 Add a layout manager 166 9.6 Create components 168 9.7 Add listeners 169 9.8 Sample code 170 9.8.1 JFrame and JPanel 170 9.8.2 JEditorPane 171 9.8.3 JScrollPane 172 9.8.4 JTabbedPane 173 9.8.5 JButton 174 xii ▪ Contents
Page
14
9.8.6 JTextField 175 9.8.7 JTextArea 175 9.8.8 JCheckBox 177 9.8.9 JRadioButton 177 9.8.10 JLabel 179 9.8.11 JComboBox 180 9.8.12 JSlider 180 9.8.13 JSpinner 181 9.8.14 JProgressBar 182 9.8.15 Menus 183 9.8.16 Keyboard Input 183 9.8.17 Mouse Input 185 9.9 DiceRoller 186 Chapter 10 ■ Threads and Animation 189 10.1 Threads 189 10.2 Synchronization 191 10.3 Timers 192 10.4 Property Changes 192 10.5 Swingworker 193 10.6 The Bouncing Ball 197 10.6.1 MVC 198 10.6.2 Controller 198 10.6.3 Model 199 10.6.4 View 200 Appendix A ■ Code for BouncingBall 201 Bouncing Ball: Controller 201 Bouncing Ball: Model 204 Bouncing Ball: View 206 Index, 209 Contents ▪ xiii
Page
15
(This page has no text content)
Page
16
Author I ’M DAVID MATUSZEK, known to most of my students as “Dr. Dave.” I wrote my first program on punched cards in 1963 and immediately got hooked. I taught my first computer classes in 1970 as a graduate student in computer science at the University of Texas in Austin. I eventually got my PhD from there, and I’ve been teaching ever since. Admittedly, I spent over a dozen years in industry, but even then I taught as an adjunct at Villanova University. I finally escaped from industry and joined the Villanova faculty full-time for a few years, then I moved to the University of Pennsylvania, where I directed a Master’s in Computer and Information Technology (MCIT) program for students entering computer science from another discipline. Throughout my career, my main interests have been in artificial intelligence (AI) and programming languages. I’ve used a lot of pro- gramming languages. I retired in 2017, but I can’t stop teaching, so I’m writing a series of “quick start” books on programming and programming languages. I’ve also written three science fiction novels—Ice Jockey, All True Value, and A Prophet in Paradise—and I expect to write more. Check them out! And, hey, if you’re a former student of mine, drop me a note. I’d love to hear from you at david.matuszek@gmail.com. xv
Page
17
(This page has no text content)
Page
18
Preface I F YOU ARE AN EXPERIENCED PROGRAMMER, this book is your guide to getting up to speed in Java in a hurry. Not just the language, but also the basics of unit testing, graphical user interfaces, threads, animation, and functional programming. If you are coming from one of the C languages, you will find most of the statement types familiar. These are clearly designated, so you can just skim over that material. If you are coming from C++, you will find the object-oriented concepts are very similar, but the terminology is different. If you are coming from another language, such as Python, there is very little you can skip. Sorry. Let’s get started! xvii
Page
19
(This page has no text content)
Page
20
Versions T HIS BOOK IS ABOUT Java 8 and Java 17. Why those two? Java 8 is the last version that is free for commercial use. If you are programming for Android, Java 8 (also known as version 1.8) is the last version you can use. For these reasons, additions to Java after version 8 will be noted as such. As this book is being written, the current version is 17. A new version is released every six months, so when you buy this book, the latest version number is probably higher. This should not be a concern, because Java “never throws anything away.” Newer versions do not invalidate older versions, and the language changes gradually. In fact, Java 17 is an LTS (Long Term Support) version, along with versions 8 and 11. If you are uncertain which version of Java you have, you can execute this from the command line: java -version or execute the following println statement from within a running Java program: System.out.println(System.getProperty("java.version")); Since Java 9, you can also run jshell from the command line. This program lets you execute Java statements (such as the above print statement) one at a time. This is no way to write a program, but it’s handy for trying things out. xix
The above is a preview of the first 20 pages. Register to read the complete e-book.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
# Quick Java — Reading Guide
【One-Line Pitch】
A fast-paced, no-nonsense Java crash course for experienced programmers (especially C++ or Python developers) who need to get productive in Java within days, not weeks—covering everything from core syntax to JUnit testing, functional programming, concurrency, and GUI building.
【Book Arc】
- **Opening (~0%–1%)**: The book opens by positioning itself as a "middle ground" between beginner Java tutorials and thousand-page reference tomes. It's explicitly written for programmers who already know how to code and just need to learn Java's syntax and idioms quickly. The author promises a "circular approach" that starts from the inside of a class and works outward.
- **Early (~1%–3%)**: The core language fundamentals are introduced—everything that goes inside a class, most of which the author notes is "practically identical to C++." This section is designed for rapid entry, leveraging the reader's existing programming knowledge rather than teaching computer science basics.
- **Middle (~3%–8%)**: The book transitions to the more complex aspects of Java: the various kinds of classes and interfaces, and how they relate to each other in large-scale programs. This is where Java's object-oriented architecture—beyond simple syntax—gets serious attention.
- **Late (~8%–11%)**: Testing takes center stage. Unlike most Java books, JUnit is covered in detail here, reflecting the author's emphasis on testing as essential practice. The book then moves into more advanced topics: functional programming in Java, parallel programming and synchronization, and finally building GUIs and animation.
- **Ending (~11%+)**: The final sections round out the practical toolkit with GUI development and animation, giving readers enough to start building interactive applications. The author is honest that this is "a good start" rather than complete mastery—the goal is rapid onboarding, not exhaustive coverage.
【Key Takeaways】
- **Java is designed for experienced programmers to pick up quickly** (Early): The book deliberately skips computer fundamentals and beginner material, assuming you already know how to program. If you're coming from C++ or Python, the syntax will feel familiar enough that you can start writing real code almost immediately.
- **The "inside-out" approach accelerates learning** (Early): By starting with what goes inside a class—variables, methods, constructors—before tackling the broader class/interface ecosystem, the book mirrors how you'll actually write Java code day-to-day. This ordering means you can write working programs before understanding the full architecture.
- **Classes and interfaces are where Java's complexity lives** (Middle): The relationship between different kinds of classes and interfaces in large-scale programs is the real differentiator between "knowing Java syntax" and "writing maintainable Java." This section is where the book earns its keep for professional developers.
- **JUnit testing is treated as essential, not optional** (Late): Unlike many Java books that relegate testing to an afterthought, this one covers JUnit in detail. For developers coming from other languages, this is a practical gap-filler—testing is where Java's tooling and conventions differ most from C++ or Python.
- **Functional programming is covered as a complement, not a replacement** (Late): Java's functional features (lambdas, streams) are summarized for readers who may need them, acknowledging that modern Java is multi-paradigm. This is positioned as a "if you need to go in that direction" topic rather than the core of the language.
- **Concurrency and parallel programming get a practical introduction** (Late): Synchronization and parallel processing are introduced at a level sufficient to understand Java's threading model and avoid common pitfalls—enough to be dangerous, but with awareness of what you don't know yet.
- **GUI and animation coverage is extensive but entry-level** (Late): The book provides "more than enough to get you started" with building graphical interfaces and animation. This is practical for developers who need to prototype UI work, though it's clearly not a deep dive into JavaFX or Swing mastery.
【Reading Tips】
- **Skim the early chapters if you're a C++ developer**: The author explicitly notes that much of the "inside a class" material is nearly identical to C++. Focus on Java-specific differences (garbage collection, no pointers, package system) rather than re-reading familiar territory.
- **Deep-read the class/interface section**: This is where Java's architecture differs most from other languages. Understanding how interfaces, abstract classes, and inheritance interact in large programs is the difference between writing Java and writing Java well.
- **Don't skip the JUnit chapter**: Even if you're in a hurry, testing conventions are where Java's ecosystem expectations differ most from other languages. Knowing how to write and run tests will save you time when you join a Java team or contribute to a Java codebase.
- **Treat the functional programming and concurrency sections as reference material**: These are summarized rather than exhaustive. Read them once to know what's available, then come back when you actually need those features.
- **Set realistic expectations**: The author is upfront that you won't learn Java in a weekend. Budget several focused days, and use the GUI/animation material as a starting point rather than expecting production-ready UI skills.
【Coverage Limits】
This guide is based on excerpts covering approximately the first 11% of the book, including the preface, table of contents, and early chapter material. Specific chapter titles, code examples, and detailed topic coverage beyond the book's stated structure are not covered in the source material.
Passage locations
Excerpt 1
书名: 长安的荔枝 (马伯庸) (Z-Library) 作者: 马伯庸 大唐天宝十四年,长安城的小吏李善德突然接到一个任务:要在贵妃诞日之前,从岭南运来新鲜荔枝。荔枝“一日色变,两日香变,三日味变”,而岭南距长安五千余里,山水迢迢,这是个不可能完成的任务,可为了家人,李善德决心放手一搏:“就算失败,我也想知道,自...
View in text
Excerpt 2
n Cantrill Afterword by Scott Hanselman Blogs that get read Blog post patterns covered in this book “Bug Hunt” posts share the thrill of finding and fixing s...
View in text
Excerpt 3
gned by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York,...
View in text
Excerpt 4
载的一应开销用度,正月里先由户部的度支郎中做一个预算,司金和仓部负责出纳,从左、右藏署和司农寺划拨出钱粮,给你们上林署。等这些钱粮用完了,我们刑部的比部司还要审验账目,看有无浮滥贪挪之弊——是这么个过程吧?” 随着韩承叙说,一条笔直的酒渍浮现在案面上,两人俱是点了点头。 “但是!圣人近年来喜欢设置各种差遣之职,因...
View in text
Recommended for You
{{#thumbnailUrl}}
{{/thumbnailUrl}}
{{^thumbnailUrl}}
{{/thumbnailUrl}}
Loading recommended books...
Failed to load, please try again later
Tip the Site
Scan the WeChat Pay or Alipay code to tip. No login required.
WeChat Pay
Alipay