Java: The Complete Reference, Eleventh Edition

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

The Definitive Java Programming Guide Fully updated for Java SE 11, Java: The Complete Reference, Eleventh Edition explains how to develop, compile, debug, and run Java programs. Best-selling programming author Herb Schildt covers the entire Java language, including its syntax, keywords, and fundamental programming principles. You’ll also find information on key portions of the Java API library, such as I/O, the Collections Framework, the stream library, and the concurrency utilities. Swing, JavaBeans, and servlets are examined and numerous examples demonstrate Java in action. Of course, the very important module system is discussed in detail. This Oracle Press resource also offers an introduction to JShell, Java’s interactive programming tool. Best of all, the book is written in the clear, crisp, uncompromising style that has made Schildt the choice of millions worldwide. Coverage includes: •Data types, variables, arrays, and operators •Control statements •Classes, objects, and methods •Method overloading and overriding •Inheritance •Local variable type inference •Interfaces and packages •Exception handling •Multithreaded programming •Enumerations, autoboxing, and annotations •The I/O classes •Generics •Lambda expressions •Modules •String handling •The Collections Framework •Networking •Event handling •AWT •Swing •The Concurrent API •The Stream API •Regular expressions •JavaBeans •Servlets •Much, much more Code examples in the book are available for download at www.OraclePressBooks.com.

Author(s): Herbert Schildt
Publisher: McGraw-Hill Education
Year: 2019

Language: English
Pages: 1882

Title Page......Page 3
Copyright Page......Page 5
Contents at a Glance......Page 8
Contents......Page 10
Preface......Page 42
Part I The Java Language......Page 46
Chapter 1 The History and Evolution of Java......Page 49
Java’s Lineage......Page 50
The Birth of Modern Programming: C......Page 51
C++: The Next Step......Page 52
The Creation of Java......Page 54
The C# Connection......Page 56
Java Applets......Page 57
Portability......Page 58
Java’s Magic: The Bytecode......Page 59
Moving Beyond Applets......Page 60
A Faster Release Schedule......Page 61
The Java Buzzwords......Page 62
Robust......Page 63
Architecture-Neutral......Page 64
The Evolution of Java......Page 65
A Culture of Innovation......Page 72
Chapter 2 An Overview of Java......Page 73
Two Paradigms......Page 74
Abstraction......Page 75
The Three OOP Principles......Page 76
A First Simple Program......Page 82
Compiling the Program......Page 83
A Closer Look at the First Sample Program......Page 84
A Second Short Program......Page 87
Two Control Statements......Page 89
The if Statement......Page 90
The for Loop......Page 91
Using Blocks of Code......Page 93
Identifiers......Page 95
Separators......Page 96
The Java Keywords......Page 97
The Java Class Libraries......Page 98
Chapter 3 Data Types, Variables, and Arrays......Page 100
The Primitive Types......Page 101
Integers......Page 102
int......Page 103
Floating-Point Types......Page 104
double......Page 105
Characters......Page 106
Booleans......Page 108
Integer Literals......Page 110
Floating-Point Literals......Page 111
Character Literals......Page 112
String Literals......Page 113
Dynamic Initialization......Page 114
The Scope and Lifetime of Variables......Page 115
Java’s Automatic Conversions......Page 119
Casting Incompatible Types......Page 120
Automatic Type Promotion in Expressions......Page 121
The Type Promotion Rules......Page 122
Arrays......Page 123
One-Dimensional Arrays......Page 124
Multidimensional Arrays......Page 127
Alternative Array Declaration Syntax......Page 133
Introducing Type Inference with Local Variables......Page 134
Some var Restrictions......Page 137
A Few Words About Strings......Page 138
Chapter 4 Operators......Page 139
Arithmetic Operators......Page 140
The Basic Arithmetic Operators......Page 141
Arithmetic Compound Assignment Operators......Page 143
Increment and Decrement......Page 145
The Bitwise Operators......Page 147
The Bitwise Logical Operators......Page 149
The Left Shift......Page 152
The Right Shift......Page 154
The Unsigned Right Shift......Page 156
Bitwise Operator Compound Assignments......Page 158
Relational Operators......Page 159
Boolean Logical Operators......Page 160
Short-Circuit Logical Operators......Page 162
The Assignment Operator......Page 163
The ? Operator......Page 164
Operator Precedence......Page 165
Using Parentheses......Page 166
Chapter 5 Control Statements......Page 168
if......Page 169
switch......Page 173
while......Page 181
do-while......Page 183
for......Page 187
The For-Each Version of the for Loop......Page 193
Local Variable Type Inference in a for Loop......Page 200
Jump Statements......Page 202
Using break......Page 203
Using continue......Page 209
Chapter 6 Introducing Classes......Page 212
The General Form of a Class......Page 213
A Simple Class......Page 215
Declaring Objects......Page 219
A Closer Look at new......Page 220
Assigning Object Reference Variables......Page 221
Introducing Methods......Page 222
Adding a Method to the Box Class......Page 223
Returning a Value......Page 225
Adding a Method That Takes Parameters......Page 228
Constructors......Page 232
Parameterized Constructors......Page 234
Instance Variable Hiding......Page 237
Garbage Collection......Page 238
A Stack Class......Page 239
Chapter 7 A Closer Look at Methods and Classes......Page 243
Overloading Methods......Page 244
Overloading Constructors......Page 248
Using Objects as Parameters......Page 251
A Closer Look at Argument Passing......Page 254
Returning Objects......Page 257
Recursion......Page 258
Introducing Access Control......Page 261
Understanding static......Page 265
Introducing final......Page 268
Arrays Revisited......Page 269
Introducing Nested and Inner Classes......Page 272
Exploring the String Class......Page 276
Using Command-Line Arguments......Page 279
Varargs: Variable-Length Arguments......Page 280
Overloading Vararg Methods......Page 284
Varargs and Ambiguity......Page 286
Local Variable Type Inference with Reference Types......Page 288
Chapter 8 Inheritance......Page 291
Inheritance Basics......Page 292
Member Access and Inheritance......Page 295
A More Practical Example......Page 297
A Superclass Variable Can Reference a Subclass Object......Page 300
Using super to Call Superclass Constructors......Page 302
A Second Use for super......Page 307
Creating a Multilevel Hierarchy......Page 309
When Constructors Are Executed......Page 313
Method Overriding......Page 315
Dynamic Method Dispatch......Page 319
Why Overridden Methods?......Page 321
Applying Method Overriding......Page 322
Using Abstract Classes......Page 324
Using final to Prevent Overriding......Page 329
Using final to Prevent Inheritance......Page 330
Local Variable Type Inference and Inheritance......Page 331
The Object Class......Page 334
Chapter 9 Packages and Interfaces......Page 336
Packages......Page 337
Defining a Package......Page 338
Finding Packages and CLASSPATH......Page 339
A Short Package Example......Page 340
Packages and Member Access......Page 341
An Access Example......Page 342
Importing Packages......Page 347
Defining an Interface......Page 350
Implementing Interfaces......Page 352
Nested Interfaces......Page 355
Applying Interfaces......Page 357
Variables in Interfaces......Page 362
Interfaces Can Be Extended......Page 364
Default Interface Methods......Page 366
Default Method Fundamentals......Page 367
A More Practical Example......Page 369
Multiple Inheritance Issues......Page 370
Use static Methods in an Interface......Page 371
Private Interface Methods......Page 372
Final Thoughts on Packages and Interfaces......Page 375
Chapter 10 Exception Handling......Page 376
Exception-Handling Fundamentals......Page 378
Exception Types......Page 379
Uncaught Exceptions......Page 380
Using try and catch......Page 382
Displaying a Description of an Exception......Page 384
Multiple catch Clauses......Page 385
Nested try Statements......Page 387
throw......Page 391
throws......Page 393
finally......Page 394
Java’s Built-in Exceptions......Page 397
Creating Your Own Exception Subclasses......Page 399
Chained Exceptions......Page 403
Three Additional Exception Features......Page 405
Using Exceptions......Page 406
Chapter 11 Multithreaded Programming......Page 408
The Java Thread Model......Page 411
Thread Priorities......Page 412
Synchronization......Page 413
The Main Thread......Page 414
Creating a Thread......Page 417
Implementing Runnable......Page 418
Extending Thread......Page 421
Creating Multiple Threads......Page 423
Using isAlive( ) and join( )......Page 426
Thread Priorities......Page 429
Synchronization......Page 430
Using Synchronized Methods......Page 431
The synchronized Statement......Page 433
Interthread Communication......Page 436
Deadlock......Page 443
Suspending, Resuming, and Stopping Threads......Page 446
Obtaining a Thread’s State......Page 449
Using a Factory Method to Create and Start a Thread......Page 452
Using Multithreading......Page 453
Chapter 12 Enumerations, Autoboxing, and Annotations......Page 454
Enumeration Fundamentals......Page 456
The values( ) and valueOf( ) Methods......Page 460
Java Enumerations Are Class Types......Page 462
Enumerations Inherit Enum......Page 464
Another Enumeration Example......Page 467
Character......Page 470
The Numeric Type Wrappers......Page 471
Autoboxing......Page 473
Autoboxing and Methods......Page 475
Autoboxing/Unboxing Occurs in Expressions......Page 476
Autoboxing/Unboxing Boolean and Character Values......Page 478
Autoboxing/Unboxing Helps Prevent Errors......Page 479
A Word of Warning......Page 480
Annotation Basics......Page 481
Specifying a Retention Policy......Page 482
Obtaining Annotations at Run Time by Use of Reflection......Page 483
The AnnotatedElement Interface......Page 491
Using Default Values......Page 492
Marker Annotations......Page 494
Single-Member Annotations......Page 496
The Built-In Annotations......Page 498
Type Annotations......Page 501
Repeating Annotations......Page 508
Some Restrictions......Page 511
Chapter 13 I/O, Try-with-Resources, and Other Topics......Page 512
I/O Basics......Page 514
Byte Streams and Character Streams......Page 515
Reading Console Input......Page 518
Reading Characters......Page 519
Reading Strings......Page 520
Writing Console Output......Page 522
The PrintWriter Class......Page 523
Reading and Writing Files......Page 525
Automatically Closing a File......Page 535
The transient and volatile Modifiers......Page 539
Using instanceof......Page 540
Native Methods......Page 544
Using assert......Page 545
Static Import......Page 549
Invoking Overloaded Constructors Through this( )......Page 553
A Word About Compact API Profiles......Page 556
Chapter 14 Generics......Page 558
A Simple Generics Example......Page 561
Generic Types Differ Based on Their Type Arguments......Page 567
How Generics Improve Type Safety......Page 568
A Generic Class with Two Type Parameters......Page 571
The General Form of a Generic Class......Page 573
Bounded Types......Page 574
Using Wildcard Arguments......Page 577
Bounded Wildcards......Page 581
Creating a Generic Method......Page 589
Generic Constructors......Page 592
Generic Interfaces......Page 593
Raw Types and Legacy Code......Page 597
Using a Generic Superclass......Page 601
A Generic Subclass......Page 605
Run-Time Type Comparisons Within a Generic Hierarchy......Page 607
Overriding Methods in a Generic Class......Page 611
Type Inference with Generics......Page 613
Local Variable Type Inference and Generics......Page 614
Erasure......Page 615
Bridge Methods......Page 616
Ambiguity Errors......Page 618
Type Parameters Can’t Be Instantiated......Page 620
Generic Array Restrictions......Page 621
Generic Exception Restriction......Page 623
Chapter 15 Lambda Expressions......Page 624
Introducing Lambda Expressions......Page 626
Lambda Expression Fundamentals......Page 627
Functional Interfaces......Page 628
Some Lambda Expression Examples......Page 630
Block Lambda Expressions......Page 633
Generic Functional Interfaces......Page 636
Passing Lambda Expressions as Arguments......Page 638
Lambda Expressions and Exceptions......Page 642
Lambda Expressions and Variable Capture......Page 644
Method References......Page 645
Method References to static Methods......Page 646
Method References to Instance Methods......Page 648
Method References with Generics......Page 653
Constructor References......Page 658
Predefined Functional Interfaces......Page 665
Chapter 16 Modules......Page 667
Module Basics......Page 669
A Simple Module Example......Page 670
Compile and Run the First Module Example......Page 677
A Closer Look at requires and exports......Page 678
java.base and the Platform Modules......Page 680
Legacy Code and the Unnamed Module......Page 681
Exporting to a Specific Module......Page 682
Using requires transitive......Page 684
Use Services......Page 689
Service and Service Provider Basics......Page 690
A Module-Based Service Example......Page 691
Three Specialized Module Features......Page 701
The opens Statement......Page 702
Linking Files in an Exploded Directory......Page 703
Linking Modular JAR Files......Page 704
A Brief Word About Layers and Automatic Modules......Page 705
Final Thoughts on Modules......Page 706
Part II The Java Library......Page 707
Chapter 17 String Handling......Page 711
The String Constructors......Page 714
String Literals......Page 717
String Concatenation......Page 718
String Conversion and toString( )......Page 719
charAt( )......Page 721
getBytes( )......Page 722
equals( ) and equalsIgnoreCase( )......Page 723
regionMatches( )......Page 724
startsWith( ) and endsWith( )......Page 725
compareTo( )......Page 726
Searching Strings......Page 728
Modifying a String......Page 730
substring( )......Page 731
replace( )......Page 732
trim( ) and strip( )......Page 733
Changing the Case of Characters Within a String......Page 735
Additional String Methods......Page 737
StringBuffer Constructors......Page 739
length( ) and capacity( )......Page 740
charAt( ) and setCharAt( )......Page 741
getChars( )......Page 742
insert( )......Page 743
reverse( )......Page 744
delete( ) and deleteCharAt( )......Page 745
replace( )......Page 746
Additional StringBuffer Methods......Page 747
StringBuilder......Page 749
Chapter 18 Exploring java.lang......Page 750
Double and Float......Page 753
Understanding isInfinite( ) and isNaN( )......Page 759
Byte, Short, Integer, and Long......Page 760
Character......Page 773
Additions to Character for Unicode Code Point Support......Page 777
Boolean......Page 779
Process......Page 781
Runtime......Page 783
Memory Management......Page 786
Executing Other Programs......Page 788
Runtime.Version......Page 789
ProcessBuilder......Page 791
System......Page 794
Using currentTimeMillis( ) to Time Program Execution......Page 796
Using arraycopy( )......Page 797
Environment Properties......Page 798
Object......Page 799
Using clone( ) and the Cloneable Interface......Page 800
Class......Page 803
Trigonometric Functions......Page 809
Rounding Functions......Page 810
Miscellaneous Math Methods......Page 812
Thread......Page 815
ThreadGroup......Page 819
Package......Page 826
Module......Page 828
SecurityManager......Page 829
StackTraceElement......Page 830
StackWalker and StackWalker.StackFrame......Page 831
Enum......Page 832
The Comparable Interface......Page 833
The Iterable Interface......Page 834
The AutoCloseable Interface......Page 835
java.lang.annotation......Page 836
java.lang.reflect......Page 837
Chapter 19 java.util Part 1: The Collections Framework......Page 839
Collections Overview......Page 842
The Collection Interfaces......Page 844
The Collection Interface......Page 845
The List Interface......Page 849
The Set Interface......Page 852
The SortedSet Interface......Page 853
The NavigableSet Interface......Page 854
The Queue Interface......Page 855
The Deque Interface......Page 856
The Collection Classes......Page 859
The ArrayList Class......Page 860
The LinkedList Class......Page 866
The HashSet Class......Page 868
The LinkedHashSet Class......Page 870
The TreeSet Class......Page 871
The PriorityQueue Class......Page 872
The ArrayDeque Class......Page 874
The EnumSet Class......Page 875
Accessing a Collection via an Iterator......Page 876
Using an Iterator......Page 878
The For-Each Alternative to Iterators......Page 881
Spliterators......Page 883
Storing User-Defined Classes in Collections......Page 886
Working with Maps......Page 889
The Map Interfaces......Page 890
The Map Classes......Page 899
Comparators......Page 906
Using a Comparator......Page 910
The Collection Algorithms......Page 919
Arrays......Page 929
The Enumeration Interface......Page 937
Vector......Page 938
Stack......Page 945
Dictionary......Page 947
Hashtable......Page 948
Properties......Page 953
Using store( ) and load( )......Page 959
Parting Thoughts on Collections......Page 962
Chapter 20 java.util Part 2: More Utility Classes......Page 963
StringTokenizer......Page 965
BitSet......Page 967
Optional, OptionalDouble, OptionalInt, and OptionalLong......Page 971
Date......Page 975
Calendar......Page 977
GregorianCalendar......Page 982
TimeZone......Page 984
SimpleTimeZone......Page 985
Locale......Page 987
Random......Page 988
Timer and TimerTask......Page 991
Currency......Page 994
The Formatter Constructors......Page 996
The Formatter Methods......Page 997
Formatting Basics......Page 998
Formatting Numbers......Page 1001
Formatting Time and Date......Page 1003
The %n and %% Specifiers......Page 1005
Specifying a Minimum Field Width......Page 1006
Specifying Precision......Page 1008
Using the Format Flags......Page 1009
Justifying Output......Page 1010
The Space, +, 0, and ( Flags......Page 1011
The Uppercase Option......Page 1013
Using an Argument Index......Page 1014
Closing a Formatter......Page 1016
The Scanner Constructors......Page 1017
Scanning Basics......Page 1019
Some Scanner Examples......Page 1022
Setting Delimiters......Page 1029
Other Scanner Features......Page 1031
The ResourceBundle, ListResourceBundle, and PropertyResourceBundle Classes......Page 1033
Miscellaneous Utility Classes and Interfaces......Page 1039
java.util.function......Page 1040
java.util.prefs......Page 1044
java.util.zip......Page 1045
Chapter 21 Input/Output: Exploring java.io......Page 1046
The I/O Classes and Interfaces......Page 1048
File......Page 1050
Directories......Page 1053
Using FilenameFilter......Page 1054
Creating Directories......Page 1056
The AutoCloseable, Closeable, and Flushable Interfaces......Page 1057
Two Ways to Close a Stream......Page 1058
The Byte Streams......Page 1060
InputStream......Page 1061
FileInputStream......Page 1063
FileOutputStream......Page 1066
ByteArrayInputStream......Page 1070
ByteArrayOutputStream......Page 1072
Buffered Byte Streams......Page 1075
SequenceInputStream......Page 1081
PrintStream......Page 1083
DataOutputStream and DataInputStream......Page 1087
RandomAccessFile......Page 1090
Reader......Page 1091
Writer......Page 1092
FileReader......Page 1093
FileWriter......Page 1094
CharArrayReader......Page 1095
CharArrayWriter......Page 1098
BufferedReader......Page 1100
PushbackReader......Page 1102
PrintWriter......Page 1103
The Console Class......Page 1105
Serialization......Page 1107
ObjectOutput......Page 1108
ObjectOutputStream......Page 1109
ObjectInput......Page 1110
ObjectInputStream......Page 1111
A Serialization Example......Page 1113
Stream Benefits......Page 1115
Chapter 22 Exploring NIO......Page 1117
The NIO Classes......Page 1119
Buffers......Page 1120
Channels......Page 1123
Charsets and Selectors......Page 1125
The Path Interface......Page 1126
The Files Class......Page 1128
The Paths Class......Page 1131
The File Attribute Interfaces......Page 1132
Using the NIO System......Page 1134
Use NIO for Channel-Based I/O......Page 1135
Use NIO for Stream-Based I/O......Page 1149
Use NIO for Path and File System Operations......Page 1153
Chapter 23 Networking......Page 1166
Networking Basics......Page 1168
The java.net Networking Classes and Interfaces......Page 1170
Factory Methods......Page 1171
Instance Methods......Page 1172
TCP/IP Client Sockets......Page 1173
URL......Page 1178
URLConnection......Page 1180
HttpURLConnection......Page 1184
TCP/IP Server Sockets......Page 1187
Datagrams......Page 1188
DatagramSocket......Page 1189
DatagramPacket......Page 1190
A Datagram Example......Page 1191
Introducing java.net.http......Page 1193
Three Key Elements......Page 1194
A Simple HTTP Client Example......Page 1198
Things to Explore in java.net.http......Page 1200
Chapter 24 Event Handling......Page 1201
Two Event Handling Mechanisms......Page 1203
Events......Page 1204
Event Sources......Page 1205
Event Classes......Page 1206
The ActionEvent Class......Page 1208
The AdjustmentEvent Class......Page 1209
The ComponentEvent Class......Page 1210
The FocusEvent Class......Page 1211
The InputEvent Class......Page 1212
The ItemEvent Class......Page 1214
The KeyEvent Class......Page 1215
The MouseEvent Class......Page 1216
The MouseWheelEvent Class......Page 1217
The WindowEvent Class......Page 1219
Sources of Events......Page 1220
Event Listener Interfaces......Page 1221
The ComponentListener Interface......Page 1222
The KeyListener Interface......Page 1223
The TextListener Interface......Page 1224
Using the Delegation Event Model......Page 1225
Some Key AWT GUI Concepts......Page 1226
Handling Mouse Events......Page 1227
Handling Keyboard Events......Page 1232
Adapter Classes......Page 1237
Inner Classes......Page 1240
Anonymous Inner Classes......Page 1244
Chapter 25 Introducing the AWT: Working with Windows, Graphics, and Text......Page 1247
AWT Classes......Page 1250
Window Fundamentals......Page 1252
Container......Page 1253
Working with Frame Windows......Page 1254
Setting a Window’s Title......Page 1255
The paint( ) Method......Page 1256
Setting the Foreground and Background Colors......Page 1257
Requesting Repainting......Page 1258
Creating a Frame-Based Application......Page 1259
Introducing Graphics......Page 1260
Drawing Ellipses and Circles......Page 1261
Demonstrating the Drawing Methods......Page 1262
Sizing Graphics......Page 1264
Color Methods......Page 1267
A Color Demonstration Program......Page 1269
Setting the Paint Mode......Page 1271
Working with Fonts......Page 1274
Determining the Available Fonts......Page 1276
Creating and Selecting a Font......Page 1278
Obtaining Font Information......Page 1281
Managing Text Output Using FontMetrics......Page 1283
Chapter 26 Using AWT Controls, Layout Managers, and Menus......Page 1288
Adding and Removing Controls......Page 1291
Labels......Page 1292
Handling Buttons......Page 1295
Applying Check Boxes......Page 1301
Handling Check Boxes......Page 1302
CheckboxGroup......Page 1306
Choice Controls......Page 1309
Handling Choice Lists......Page 1310
Using Lists......Page 1313
Handling Lists......Page 1314
Managing Scroll Bars......Page 1317
Handling Scroll Bars......Page 1318
Using a TextField......Page 1322
Handling a TextField......Page 1323
Using a TextArea......Page 1326
Understanding Layout Managers......Page 1328
FlowLayout......Page 1329
BorderLayout......Page 1330
Using Insets......Page 1333
GridLayout......Page 1335
CardLayout......Page 1337
GridBagLayout......Page 1341
Menu Bars and Menus......Page 1348
Dialog Boxes......Page 1355
A Word About Overriding paint( )......Page 1362
Chapter 27 Images......Page 1363
File Formats......Page 1365
Creating an Image Object......Page 1366
Displaying an Image......Page 1367
Double Buffering......Page 1370
ImageProducer......Page 1373
MemoryImageSource......Page 1374
PixelGrabber......Page 1376
ImageFilter......Page 1380
CropImageFilter......Page 1381
RGBImageFilter......Page 1384
Additional Imaging Classes......Page 1402
Chapter 28 The Concurrency Utilities......Page 1403
java.util.concurrent......Page 1406
Using Synchronization Objects......Page 1408
Semaphore......Page 1409
CountDownLatch......Page 1417
CyclicBarrier......Page 1420
Exchanger......Page 1424
Phaser......Page 1427
Using an Executor......Page 1437
A Simple Executor Example......Page 1439
Using Callable and Future......Page 1441
The TimeUnit Enumeration......Page 1445
Locks......Page 1447
Atomic Operations......Page 1452
Parallel Programming via the Fork/Join Framework......Page 1454
The Main Fork/Join Classes......Page 1455
The Divide-and-Conquer Strategy......Page 1460
A Simple First Fork/Join Example......Page 1461
Understanding the Impact of the Level of Parallelism......Page 1465
An Example that Uses RecursiveTask......Page 1470
Executing a Task Asynchronously......Page 1473
Determining a Task’s Completion Status......Page 1474
Things to Explore......Page 1475
Some Fork/Join Tips......Page 1477
The Concurrency Utilities Versus Java’s Traditional Approach......Page 1478
Chapter 29 The Stream API......Page 1479
Stream Basics......Page 1481
Stream Interfaces......Page 1482
How to Obtain a Stream......Page 1486
A Simple Stream Example......Page 1487
Reduction Operations......Page 1492
Using Parallel Streams......Page 1495
Mapping......Page 1498
Collecting......Page 1505
Iterators and Streams......Page 1510
Use an Iterator with a Stream......Page 1511
Use Spliterator......Page 1512
More to Explore in the Stream API......Page 1517
Chapter 30 Regular Expressions and Other Packages......Page 1518
Regular Expression Processing......Page 1520
Matcher......Page 1521
Regular Expression Syntax......Page 1522
Demonstrating Pattern Matching......Page 1523
Two Pattern-Matching Options......Page 1531
Reflection......Page 1532
A Simple Client/Server Application Using RMI......Page 1538
Formatting Date and Time with java.text......Page 1543
DateFormat Class......Page 1544
SimpleDateFormat Class......Page 1546
The java.time Time and Date API......Page 1548
Time and Date Fundamentals......Page 1549
Formatting Date and Time......Page 1551
Parsing Date and Time Strings......Page 1555
Other Things to Explore in java.time......Page 1556
Part III Introducing GUI Programming with Swing......Page 1558
Chapter 31 Introducing Swing......Page 1560
The Origins of Swing......Page 1562
Swing Components Are Lightweight......Page 1563
The MVC Connection......Page 1564
Components......Page 1566
Containers......Page 1567
The Swing Packages......Page 1568
A Simple Swing Application......Page 1569
Event Handling......Page 1575
Painting in Swing......Page 1579
Painting Fundamentals......Page 1580
Compute the Paintable Area......Page 1581
A Paint Example......Page 1582
Chapter 32 Exploring Swing......Page 1587
JLabel and ImageIcon......Page 1589
JTextField......Page 1592
JButton......Page 1595
JToggleButton......Page 1599
Check Boxes......Page 1602
Radio Buttons......Page 1605
JTabbedPane......Page 1608
JScrollPane......Page 1611
JList......Page 1614
JComboBox......Page 1619
Trees......Page 1622
JTable......Page 1627
Chapter 33 Introducing Swing Menus......Page 1632
Menu Basics......Page 1634
JMenuBar......Page 1636
JMenu......Page 1638
JMenuItem......Page 1639
Create a Main Menu......Page 1640
Add Mnemonics and Accelerators to Menu Items......Page 1646
Add Images and Tooltips to Menu Items......Page 1649
Use JRadioButtonMenuItem and JCheckBoxMenuItem......Page 1651
Create a Popup Menu......Page 1655
Create a Toolbar......Page 1659
Use Actions......Page 1662
Put the Entire MenuDemo Program Together......Page 1669
Continuing Your Exploration of Swing......Page 1681
Part IV Applying Java......Page 1683
Chapter 34 Java Beans......Page 1686
What Is a Java Bean?......Page 1688
Introspection......Page 1689
Design Patterns for Properties......Page 1690
Design Patterns for Events......Page 1692
Using the BeanInfo Interface......Page 1693
Customizers......Page 1694
The JavaBeans API......Page 1695
MethodDescriptor......Page 1698
A Bean Example......Page 1699
Chapter 35 Introducing Servlets......Page 1704
Background......Page 1706
The Life Cycle of a Servlet......Page 1707
Servlet Development Options......Page 1708
Using Tomcat......Page 1709
Create and Compile the Servlet Source Code......Page 1711
The Servlet API......Page 1712
The javax.servlet Package......Page 1713
The Servlet Interface......Page 1714
The ServletRequest Interface......Page 1715
The ServletResponse Interface......Page 1716
The ServletInputStream Class......Page 1717
Reading Servlet Parameters......Page 1718
The HttpServletRequest Interface......Page 1721
The HttpServletResponse Interface......Page 1722
The HttpSession Interface......Page 1723
The Cookie Class......Page 1724
Handling HTTP Requests and Responses......Page 1726
Handling HTTP GET Requests......Page 1727
Handling HTTP POST Requests......Page 1729
Using Cookies......Page 1730
Session Tracking......Page 1734
Part V Appendixes......Page 1736
Appendix A Using Java’s Documentation Comments......Page 1738
The javadoc Tags......Page 1739
@author......Page 1740
@exception......Page 1741
{@link}......Page 1742
@return......Page 1743
@serialField......Page 1744
@uses......Page 1745
The General Form of a Documentation Comment......Page 1746
An Example that Uses Documentation Comments......Page 1747
Appendix B Introducing JShell......Page 1750
JShell Basics......Page 1751
List, Edit, and Rerun Code......Page 1754
Add a Method......Page 1755
Create a Class......Page 1757
Use an Interface......Page 1758
Evaluate Expressions and Use Built-in Variables......Page 1760
Importing Packages......Page 1761
Some More JShell Commands......Page 1762
Exploring JShell Further......Page 1763
Appendix C Compile and Run Simple Single-File Programs in One Step......Page 1765
Index......Page 1768