28,99 €
A beginning coder's resource for learning the most popular coding language With Java All-in-One For Dummies, you get 8 books in one, for the most well-rounded Java knowledge on the market. Updated for Java 19, this book includes all the major changes to the programming language, so you won't fall behind. Start by learning the basics of Java--you can do it, even if you've never written a line of code in your life. Then go in-depth, with all the info you need on object-oriented programming, Java FX, Java web development, and beyond. Grab a hot cup of java and settle in to learn some Java, with friendly For Dummies guidance! * Learn the basics of computer programming and get started with the Java language * Master strings, arrays, and collections * Discover the most recent Java updates and the latest in programming techniques * Launch or further your career as a coder with easy-to-follow instruction This is the go-to Dummies guide for future and current coders who need an all-inclusive guide Java to take their knowledge to the next level.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 1226
Veröffentlichungsjahr: 2023
Java® All-in-One For Dummies®, 7th Edition
Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com
Copyright © 2023 by John Wiley & Sons, Inc., Hoboken, New Jersey
Media and software compilation copyright © 2023 by John Wiley & Sons, Inc. All rights reserved.
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.
Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and may not be used without written permission. Java is a registered trademark of Oracle America, Inc. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: WHILE THE PUBLISHER AND AUTHORS HAVE USED THEIR BEST EFFORTS IN PREPARING THIS WORK, THEY MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES, WRITTEN SALES MATERIALS OR PROMOTIONAL STATEMENTS FOR THIS WORK. THE FACT THAT AN ORGANIZATION, WEBSITE, OR PRODUCT IS REFERRED TO IN THIS WORK AS A CITATION AND/OR POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE PUBLISHER AND AUTHORS ENDORSE THE INFORMATION OR SERVICES THE ORGANIZATION, WEBSITE, OR PRODUCT MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING PROFESSIONAL SERVICES. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR YOUR SITUATION. YOU SHOULD CONSULT WITH A SPECIALIST WHERE APPROPRIATE. FURTHER, READERS SHOULD BE AWARE THAT WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. NEITHER THE PUBLISHER NOR AUTHORS SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES.
For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit https://hub.wiley.com/community/support/dummies.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2022950700
ISBN 978-1-119-98664-5 (pbk); ISBN 978-1-119-98665-2 (ebk); ISBN 978-1-119-98666-9 (ebk)
Cover
Title Page
Copyright
Introduction
About This Book
Foolish Assumptions
Icons Used in This Book
Beyond the Book
Where to Go from Here
Book 1: Java Basics
Chapter 1: Welcome to Java
What Is Java, and Why Is It So Great?
Important Features of the Java Language
Java Version Insanity
What’s in a Name?
Chapter 2: Installing and Using Java Tools
Downloading and Installing the Java Development Kit
Confirming Your Java Version
Using Java’s Command-Line Tools
Using Java Documentation
Chapter 3: Working with TextPad
Downloading and Installing TextPad
Editing Source Files
Compiling a Program
Running a Java Program
Book 2: Programming Basics
Chapter 1: Java Programming Basics
Looking at the Venerable Hello, World! Program
Dealing with Keywords
Working with Statements
Working with Blocks
Creating Identifiers
Crafting Comments
Introducing Object-Oriented Programming
Importing Java API Classes
Chapter 2: Working with Variables and Data Types
Declaring Variables
Initializing Variables
Using Final Variables (Constants)
Working with Primitive Data Types
Working with Strings
Converting and Casting Numeric Data
Thinking Inside the Box
Understanding Scope
Shadowing Variables
Printing Data with System.out
Getting Input with the Scanner Class
Getting Input with the JOptionPane Class
Using enum to Create Your Own Data Types
Chapter 3: Working with Numbers and Expressions
Working with Arithmetic Operators
Dividing Integers
Combining Operators
Using the Unary Plus and Minus Operators
Using Increment and Decrement Operators
Using the Assignment Operator
Using Compound Assignment Operators
Using the Math Class
Formatting Numbers
Recognizing Weird Things about Java Math
Chapter 4: Making Choices
Using Simple Boolean Expressions
Using if Statements
Using Mr. Spock’s Favorite Operators (Logical Ones, of Course)
Using the Conditional Operator
Comparing Strings
Chapter 5: Going Around in Circles (or, Using Loops)
Using Your Basic while Loop
Breaking Out of a Loop
Looping Forever
Using the continue Statement
Running do-while Loops
Validating Input from the User
Using the Famous for Loop
Nesting Your Loops
Chapter 6: Pulling a Switcheroo
Battling else-if Monstrosities
Using the switch Statement
Creating Character Cases
Matching Two or More Values in a Single Case Group
Intentionally Leaving Out a Break Statement
Switching with Strings
Assigning a Value with a Switch Statement
Chapter 7: Adding Some Methods to Your Madness
The Joy of Methods
The Basics of Making Methods
Methods That Return Values
Methods That Take Parameters
Chapter 8: Handling Exceptions
Understanding Exceptions
Catching Exceptions
Handling Exceptions with a Preemptive Strike
Catching All Exceptions at Once
Displaying the Exception Message
Using a finally Block
Handling Checked Exceptions
Throwing Your Own Exceptions
Using the try-with-resources Statement
Book 3: Object-Oriented Programming
Chapter 1: Understanding Object-Oriented Programming
What Is Object-Oriented Programming?
Understanding Objects
Understanding the Life Cycle of an Object
Working with Related Classes
Designing a Program with Objects
Diagramming Classes with UML
Chapter 2: Making Your Own Classes
Declaring a Class
Working with Members
Using Getters and Setters
Overloading Methods
Creating Constructors
Finding More Uses for the this Keyword
Using Initializers
Using Records
Chapter 3: Working with Statics
Understanding Static Fields and Methods
Working with Static Fields
Using Static Methods
Counting Instances
Preventing Instances
Using Static Initializers
Chapter 4: Using Subclasses and Inheritance
Introducing Inheritance
Creating Subclasses
Overriding Methods
Protecting Your Members
Using the this and super Keywords in Your Subclasses
Understanding Inheritance and Constructors
Using the final Keyword
Casting Up and Down
Determining an Object’s Type
Poly What?
Creating Custom Exceptions
Chapter 5: Using Abstract Classes and Interfaces
Using Abstract Classes
Using Interfaces
More Things You Can Do with Interfaces
Using Additional Interface Method Types
Two Interfaces That Enable Java Language Features
Sealing Your Classes
Chapter 6: Using the Object and Class Classes
The Mother of All Classes: Object
The toString Method
The equals Method
The clone Method
The Class Class
Using the instanceof Operator
Chapter 7: Using Inner Classes and Anonymous Classes
Declaring Inner Classes
Using Static Inner Classes
Using Anonymous Inner Classes
Chapter 8: Working with Packages and the Java Module System
Working with Packages
Putting Your Classes in a JAR File
Using Javadoc to Document Your Classes
Using the Java Module System
Book 4: Strings and Other Data Types
Chapter 1: Working with Strings
Reviewing Strings
Using the String Class
Determining Whether a String Is Empty
Using the StringBuilder and StringBuffer Classes
Using the CharSequence Interface
Using Text Blocks
Chapter 2: Using Regular Expressions
Creating a Program for Experimenting with Regular Expressions
Performing Basic Character Matching
Using Regular Expressions in Java Programs
Chapter 3: Working with Dates and Times
Pondering How Time Is Represented
Picking the Right Date and Time Class for Your Application
Using the now Method to Create a Date-Time Object
Using the parse Method to Create a Date-Time Object
Using the of Method to Create a Date-Time Object
Looking Closer at the LocalDate Class
Extracting Information about a Date
Comparing Dates
Calculating with Dates
Formatting Dates
Looking at a Fun Birthday Calculator
Chapter 4: Using the BigDecimal Class
Seeing Why Java Can’t Add
BigDecimal to the Rescue!
Creating BigDecimal Objects
Doing BigDecimal Arithmetic
Rounding BigDecimal Values
Comparing BigDecimal Values
Converting BigDecimals to Strings
Revisiting Sales Tax
Book 5: Data Structures
Chapter 1: Introducing Data Structures
Imagining Models of Computation
Defining Data Structures
Quantifying Performance
Analyzing Arrays
Looking at Linked Lists
Doubling Down with Doubly Linked Lists
Surmising Stacks, Queues, and Deques
Musing about Maps
Checking Out Hash Maps
Tackling Trees
Checking Out Binary Trees
Chapter 2: Using Arrays
Understanding Arrays
Creating Arrays
Initializing an Array
Using for Loops with Arrays
Solving Homework Problems with Arrays
Using the Enhanced for Loop
Using Arrays with Methods
Using Varargs
Using Two-Dimensional Arrays
Working with a Fun but Complicated Example: A Chessboard
Using the Arrays Class
Chapter 3: Using the ArrayList Class
Understanding the ArrayList Class
Creating an ArrayList Object
Adding Elements
Accessing Elements
Printing an ArrayList
Using an Iterator
Updating Elements
Deleting Elements
Chapter 4: Using the LinkedList Class
Understanding the LinkedList Class
Creating a LinkedList
Adding Items to a LinkedList
Retrieving Items from a LinkedList
Updating LinkedList Items
Removing LinkedList Items
Chapter 5: Creating Generic Collection Classes
Why Generics?
Creating a Generic Class
A Generic Stack Class
Using Wildcard-Type Parameters
A Generic Queue Class
Chapter 6: Using Maps and Trees
Mastering Maps
Using the HashMap Class
Removing Entries from a Hash Map
Using the TreeMap Class
Book 6: Algorithms
Chapter 1: Introducing Algorithms
What Is an Algorithm?
Classifying Algorithms
Some Fun Algorithm Challenges
Chapter 2: Using Recursion
Calculating the Classic Factorial Example
Displaying Directories
Playing the Towers of Hanoi
Chapter 3: Sorting
Looking at the Bubble Sort Algorithm
Introducing the Quicksort Algorithm
Chapter 4: Searching
Creating a Data Structure Worth Searching
Looking at Linear Searching
Using a Binary Search
Book 7: Programming Techniques
Chapter 1: Programming Threads
Understanding Threads
Creating a Thread
Implementing the Runnable Interface
Creating Threads That Work Together
Using an Executor
Synchronizing Methods
Creating a Lock
Coping with Threadus Interruptus
Chapter 2: Using Functional Programming and Lambda Expressions
Introducing Functional Programming
Introducing Functional Interfaces
Using Lambda Expressions
Passing Parameters via Lambda Expressions
Using Block Lambda Expressions
Using the java.util.function Package
Chapter 3: Consuming Web Services with HttpClient
Introducing Web Services
Understanding HTTP
Getting Started with Java’s HTTP Client Library
Putting It All Together
The HTTP Tester Program
Book 8: JavaFX
Chapter 1: Hello, JavaFX!
Perusing the Possibilities of JavaFX
Getting Ready to Run JavaFX
Looking at a Simple JavaFX Program
Importing JavaFX Packages
Extending the Application Class
Launching the Application
Overriding the start Method
Creating a Button
Handling an Action Event
Creating a Layout Pane
Making a Scene
Setting the Stage
Examining the Click Counter Program
Chapter 2: Handling Events
Examining Events
Handling Events
Implementing the EventHandler Interface
Handling Events with Inner Classes
Handling Events with Anonymous Inner Classes
Using Lambda Expressions to Handle Events
Chapter 3: Setting the Stage and Scene Layout
Examining the Stage Class
Examining the Scene Class
Switching Scenes
Creating an Alert Box
Exit, Stage Right
Chapter 4: Using Layout Panes to Arrange Your Scenes
Working with Layout Panes
Using the HBox Layout
Spacing Things Out
Adding Space with Margins
Adding Space by Growing Nodes
Using the VBox Layout
Aligning Nodes in a Layout Pane
Using the Flow Layout
Using the Border Layout
Using the GridPane Layout
Chapter 5: Getting Input from the User
Using Text Fields
Validating Numeric Data
Using Check Boxes
Using Radio Buttons
Chapter 6: Choosing from a List
Using Choice Boxes
Working with Observable Lists
Listening for Selection Changes
Using Combo Boxes
Using List Views
Using Tree Views
Index
About the Author
Connect with Dummies
End User License Agreement
Book 1 Chapter 2
TABLE 2-1 Subfolders of the JDK Home Folder
TABLE 2-2 Java Compiler Options
TABLE 2-3 Common Java Command Options
Book 2 Chapter 1
TABLE 1-1 Java’s Keywords
Book 2 Chapter 2
TABLE 2-1 Java's Primitive Types
TABLE 2-2 Escape Sequences for Character Constants
TABLE 2-3 Wrapper Classes for the Primitive Types
TABLE 2-4 Methods That Convert Strings to Numeric Primitive Types
TABLE 2-5 Static Fields of the System Object
TABLE 2-6 Scanner Class Methods That Get Input Values
TABLE 2-7 Scanner Class Methods That Check for Valid Input Values
Book 2 Chapter 3
TABLE 3-1 Java’s Arithmetic Operators
TABLE 3-2 Compound Assignment Operators
TABLE 3-3 Constants of the Math Class
TABLE 3-4 Commonly Used Mathematical Functions Provided by the Math Class
TABLE 3-5 Rounding Functions Provided by the Math Class
TABLE 3-6 Methods of the NumberFormat Class
TABLE 3-7 Special Constants of the float and double Classes
Book 2 Chapter 4
TABLE 4-1 Relational Operators
TABLE 4-2 Logical Operators
Book 2 Chapter 8
TABLE 8-1 Methods of the Exception Class
Book 3 Chapter 1
TABLE 1-1 Visibility Indicators for Class Variables and Methods
Book 3 Chapter 6
TABLE 6-1 Methods of the Object Class
Book 3 Chapter 8
TABLE 8-1 Options for the jar Command
TABLE 8-2 Commonly Used Javadoc Tags
Book 4 Chapter 1
TABLE 1-1 String Class Methods
TABLE 1-2 StringBuilder Methods
Book 4 Chapter 2
TABLE 2-1 Character Classes
TABLE 2-2 Quantifiers
Book 4 Chapter 3
TABLE 3-1 Ten Date-Time Classes in java.time
TABLE 3-2 Date-Time of Methods
TABLE 3-3 Methods of the LocalDate Class
TABLE 3-4 Formatting Characters for the DateTimeFormatter Class
Book 4 Chapter 4
TABLE 4-1 Constructors BigDecimal Class
TABLE 4-2 Arithmetic Methods of the BigDecimal Class
TABLE 4-3 Scaling Methods of the BigDecimal Class
TABLE 4-4 Members of the RoundingMode Enumeration
TABLE 4-5 Comparison Methods of the BigDecimal Class
TABLE 4-6 Conversion Methods of the BigDecimal Class
Book 5 Chapter 1
TABLE 1-1 Performance Characteristics of Arrays
TABLE 1-2 Performance Characteristics of a Linked List
TABLE 1-3 Performance Characteristics of a Doubly Linked List
Book 5 Chapter 2
TABLE 2-1 Handy Methods of the Arrays Class
Book 5 Chapter 3
TABLE 3-1 The ArrayList Class
TABLE 3-2 The Iterator Interface
Book 5 Chapter 4
TABLE 4-1 The LinkedList Class
Book 5 Chapter 6
TABLE 6-1 The HashMap Class
TABLE 6-2 The Map.Entry Interface
TABLE 6-3 The TreeMap Class
Book 7 Chapter 1
TABLE 1-1 Constructors and Methods of the Thread Class
Book 7 Chapter 2
TABLE 2-1 Commonly Used Interfaces in
java.util.function
Book 8 Chapter 3
TABLE 3-1 The HttpClient Class
TABLE 3-2 The HttpRequest and Its Builder Interface
TABLE 3-3 The HttpResponse Class
TABLE 3-4 The BodyHandlers Class
Book 8 Chapter 2
TABLE 2-1 Commonly Used Event Classes
TABLE 2-2 The EventHandler Interface
Book 8 Chapter 3
TABLE 3-1 Commonly Used Methods of the Stage Class
TABLE 3-2 Commonly Used Constructors and Methods of the Scene class
TABLE 3-3 Commonly Used Constructors and Methods of the Alert class
Book 8 Chapter 4
TABLE 4-1 HBox Constructors and Methods
TABLE 4-2 Insets Constructors
TABLE 4-3 The Priority Enumeration
TABLE 4-4 VBox Constructors and Methods
TABLE 4-5 The Pos Enumeration
TABLE 4-6 FlowPane Constructors and Methods
TABLE 4-7 BorderPane Constructors and Methods
TABLE 4-8 GridPane Constructors and Methods
TABLE 4-9 The ColumnConstraints Class
TABLE 4-10 The RowConstraints Class
Book 8 Chapter 5
TABLE 5-1 Handy TextField Constructors and Methods
TABLE 5-2 Methods That Convert Strings to Numbers
TABLE 5-3 Notable CheckBox Constructors and Methods
TABLE 5-4 Various RadioButton Constructors and Methods
Book 8 Chapter 6
TABLE 6-1 Common ChoiceBox Constructors and Methods
TABLE 6-2 Commonly Used ObservableList Methods
TABLE 6-3 Common ComboBox Constructors and Methods
TABLE 6-4 Common ListView Constructors and Methods
TABLE 6-5 The TreeItem Class
TABLE 6-6 The TreeView Class
Book 1 Chapter 2
FIGURE 2-1: The Environment Variables dialog box.
FIGURE 2-2: Creating the
JAVA_HOME
variable.
FIGURE 2-3: Editing the
Path
variable.
FIGURE 2-4: The documentation page for the String class.
Book 1 Chapter 3
FIGURE 3-1: Configuring tools in TextPad.
FIGURE 3-2: Editing a Java file in TextPad.
FIGURE 3-3: Error messages displayed by the Java compiler.
FIGURE 3-4: Running a program.
Book 2 Chapter 1
FIGURE 1-1: The class in Listing 1-4 displays this dialog box.
Book 2 Chapter 2
FIGURE 2-1: Numeric type conversions that are done automatically.
FIGURE 2-2: A dialog box displayed by the JOptionPane class.
Book 2 Chapter 4
FIGURE 4-1: The flowchart for an if statement.
FIGURE 4-2: The flowchart for an if-else statement.
FIGURE 4-3: The flowchart for a sequence of else-if statements.
Book 2 Chapter 5
FIGURE 5-1: The flowchart for a
while
loop.
FIGURE 5-2: The flowchart for a
do-while
loop.
FIGURE 5-3: The flowchart for a
for
loop.
Book 2 Chapter 6
FIGURE 6-1: The flowchart for a switch statement.
Book 2 Chapter 8
FIGURE 8-1: This program has slipped into the Exception Zone.
FIGURE 8-2: Why you have to call next to discard the invalid input.
Book 3 Chapter 1
FIGURE 1-1: Three-layered design.
FIGURE 1-2: A simple class diagram.
FIGURE 1-3: A class.
Book 3 Chapter 4
FIGURE 4-1: The hierarchy of exception classes.
Book 3 Chapter 5
FIGURE 5-1: The Tick Tock application in action.
Book 3 Chapter 8
FIGURE 8-1: A Javadoc index page.
FIGURE 8-2: Documentation for the Employee class.
FIGURE 8-3: A Javadoc code snippet.
Book 5 Chapter 1
FIGURE 1-1: The word RAM model of computation.
FIGURE 1-2: Constant, logarithmic, linear, polynomial, and exponential performa...
FIGURE 1-3: One- and two-dimensional arrays.
FIGURE 1-4: A linked list.
FIGURE 1-5: A doubly linked list.
FIGURE 1-6: Stacks and queues.
FIGURE 1-7: A deque.
FIGURE 1-8: A tree.
FIGURE 1-9: A binary search tree.
Book 5 Chapter 2
FIGURE 2-1: A classic chessboard.
Book 5 Chapter 6
FIGURE 6-1: A red-black tree.
Book 6 Chapter 1
FIGURE 1-1: One solution to the eight queens problem.
FIGURE 1-2: Long division.
FIGURE 1-3: A single elimination tournament bracket.
FIGURE 1-4: A double elimination tournament bracket.
Book 6 Chapter 2
FIGURE 2-1: The Towers of Hanoi game.
FIGURE 2-2: Solving the Towers of Hanoi with two disks.
Book 6 Chapter 4
FIGURE 4-1: The Social Security Administration’s Popular Baby Names page.
Book 8 Chapter 1
FIGURE 1-1: A typical JavaFX program.
FIGURE 1-2: The Click Me program.
FIGURE 1-3: The Click Counter program in action.
Book 8 Chapter 2
FIGURE 2-1: The AddSubtract1 program.
Book 8 Chapter 3
FIGURE 3-1: The SceneSwitcher program.
FIGURE 3-2: An Alert dialog box.
Book 8 Chapter 4
FIGURE 4-1: Four commonly used types of layout panes.
FIGURE 4-2: Using a spacer node to space out buttons in an
HBox
pane.
FIGURE 4-3: Three buttons centered in a
VBox
layout pane.
FIGURE 4-4: A flow layout pane with five buttons.
FIGURE 4-5: How the border layout carves things up.
FIGURE 4-6: Sketching out a panel.
FIGURE 4-7: The Pizza Order application in action.
Book 8 Chapter 5
FIGURE 5-1: The Role Player application in action.
FIGURE 5-2: Three check boxes.
FIGURE 5-3: A frame with three radio buttons.
Book 8 Chapter 6
FIGURE 6-1: A scene with a choice box.
FIGURE 6-2: A combo box.
FIGURE 6-3: A list view control.
FIGURE 6-4: A list view control with horizontal orientation.
FIGURE 6-5: A tree view control.
FIGURE 6-6: A tree view control with the root node hidden.
Cover
Title Page
Copyright
Table of Contents
Begin Reading
Index
About the Author
i
ii
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
535
536
537
538
539
540
541
542
543
544
545
546
547
549
550
551
552
553
554
555
556
557
558
559
561
562
563
564
565
566
567
568
569
570
571
572
573
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
Welcome to Java All-in-One For Dummies, 7th Edition — the one Java book that’s designed to replace an entire shelf full of the dull, tedious titles you’d otherwise have to buy. This book contains all the basic information you need to know to get going with Java programming, starting with writing statements and using variables and ending with techniques for writing programs that use advanced Java features. Along the way, you find plenty of not-so-basic information about programming user interfaces, working with classes and objects, data structures, and algorithms.
You can (and probably should, eventually) buy separate books on each of these topics. It won’t take long before your bookshelf is bulging with 10,000 or more pages of detailed information about every imaginable nuance of Java programming. But before you’re ready to tackle each of those topics in depth, you need to get a bird’s-eye picture. That’s what this book is about.
And if you already own 10,000 pages or more of Java information, you may be overwhelmed by the amount of detail and wonder, “Do I really need to read 1,200 pages about JSP just to create a simple web page? And do I really need a six-pound book on JavaFX?” Truth is, most 1,200-page programming books have about 200 pages of really useful information — the kind you use every day — and about 1,000 pages of excruciating details that apply mostly if you’re writing guidance-control programs for nuclear missiles or trading systems for the New York Stock Exchange.
The basic idea here is that I’ve tried to wring out the 100-or-so most useful pages of information on these different Java programming topics: setup and configuration, basic programming, object-oriented programming, advanced programming techniques, JavaFX, file and database programming, web programming, and animation and game programming. Thus you get a nice, trim book.
So whether you’re just getting started with Java programming or you’re a seasoned pro, you’ve found the right book.
Java All-in-One For Dummies, 7th Edition, is a reference for all the great things (and maybe a few not-so-great things) that you may need to know when you’re writing Java programs. You can, of course, buy a huge 1,200-page book on each of the programming topics covered in this book. But then, who would carry them home from the bookstore for you? And where would you find the shelf space to store them? And when will you find the time to read them?
In this book, all the information you need is conveniently packaged for you in-between one set of covers. And all of the information is current for the newest release of Java, known as JDK 19. This book doesn’t pretend to be a comprehensive reference for every detail on every possible topic related to Java programming. Instead, it shows you how to get up and running fast so that you have more time to do the things you really want to do. Designed using the easy-to-follow For Dummies format, this book helps you get the information you need without laboring to find it.
Java All-in-One For Dummies, 7th Edition, is a big book made up of eight smaller books — minibooks, if you will. Each of these minibooks covers the basics of one key element of programming, such as installing Java and compiling and running programs, or using basic Java statements, or using JavaFX to write GUI applications.
Whenever one big thing is made up of several smaller things, confusion is always a possibility. That’s why this book has multiple access points. At the beginning is a detailed table of contents that covers the entire book. Then each minibook begins with a minitable of contents that shows you at a miniglance what chapters are included in that minibook. Useful running heads appear at the top of each page to point out the topic discussed on that page. And handy thumb tabs run down the side of the pages to help you find each minibook quickly. Finally, a comprehensive index lets you find information anywhere in the entire book.
You and I have never met, so it is difficult for me to make any assumptions about why you are interested in this book. However, let’s start with a few basic assumptions:
You own or have access to a relatively modern computer.
The examples were created on a Windows computer, but you can learn to program in Java just as easily on a Mac or Linux computer.
You’re an experienced computer user.
In other words, I assume that you know the basics of using your computer, such as starting programs and working with the file system.
You’re interested in learning how to write programs in the Java language.
Since that’s what this book teaches, it’s a fair assumption.
I do not make any assumptions about any previous programming experience in Java or in any other programming language. Nor do I make any assumptions about why you want to learn about Java programming. There are all sorts of valid reasons for learning Java. Some want to learn Java for professional reasons; maybe you want to become a professional Java programmer, or maybe you are a C# or C++ programmer who occasionally needs to work in Java. On the other hand, maybe you think programming in Java would make an interesting hobby.
Regardless of your motivation, I do assume that you are a reasonably intelligent person. You don’t have to have a degree in advanced physics, or a degree in anything at all for that matter, to master Java programming. All you have to be is someone who wants to learn and isn’t afraid to try.
Like any For Dummies book, this book is chock-full of helpful icons that draw your attention to items of particular importance. You find the following icons throughout this book:
Danger, Will Robinson! This icon highlights information that may help you avert disaster.
Did I tell you about the memory course I took?
Pay special attention to this icon; it lets you know that some particularly useful tidbit is at hand.
Hold it — overly technical stuff is just around the corner. Obviously, because this is a programming book, almost every paragraph of the next 900 or so pages could get this icon. So I reserve it for those paragraphs that go into greater depth, down into explaining how something works under the covers — probably deeper than you really need to know to use a feature, but often enlightening.
In addition to the material in the print or e-book you’re reading right now, this product also comes with some access-anywhere goodies on the web. Check out the free Cheat Sheet for more on Java. To get this Cheat Sheet, simply go to www.dummies.com and type Java All-in-One For Dummies Cheat Sheet in the Search box.
Visit www.dummies.com/go/javaaiofd7e to dive even deeper into Java. You can find and download the code used in the book at that link. You can also download a bonus minibook covering how to use Java with files and databases.
This isn’t the kind of book you pick up and read from start to finish, as if it were a cheap novel. If I ever see you reading it at the beach, I’ll kick sand in your face. Beaches are for reading romance novels or murder mysteries, not programming books. Although you could read straight through from start to finish, this book is a reference book, the kind you can pick up, open to just about any page, and start reading. You don’t have to memorize anything in this book. It’s a “need-to-know” book: You pick it up when you need to know something. Need a reminder on the constructors for the ArrayList class? Pick up the book. Can’t remember the goofy syntax for anonymous inner classes? Pick up the book. After you find what you need, put the book down and get on with your life.
Book 1
Chapter 1: Welcome to Java
What Is Java, and Why Is It So Great?
Important Features of the Java Language
Java Version Insanity
What’s in a Name?
Chapter 2: Installing and Using Java Tools
Downloading and Installing the Java Development Kit
Confirming Your Java Version
Using Java’s Command-Line Tools
Using Java Documentation
Chapter 3: Working with TextPad
Downloading and Installing TextPad
Editing Source Files
Compiling a Program
Running a Java Program