Thinking in Java - 4th Edition
1079 pág.

Thinking in Java - 4th Edition


DisciplinaProgramação Orientada A Objetos5.150 materiais78.207 seguidores
Pré-visualização50 páginas
561 
Summary ............................ 564 
Containers in Depth 567 
Full container taxonomy .... 567 
Filling containers ............... 568 
A Generator solution .............. 569 
Map generators ......................... 570 
Using Abstract classes ............. 573 
Collection 
functionality ....................... 580 
Optional operations ........... 582 
Unsupported operations............ 583 
List functionality ............... 586 
Sets and storage order ...... 589 
SortedSet ................................. 591 
Queues ................................ 594 
Priority queues ........................... 594 
Deques ....................................... 595 
Understanding Maps ........ 598 
Performance .............................. 599 
SortedMap ............................. 602 
LinkedHashMap ................... 603 
Hashing and hash codes .... 605 
Understanding hashCodeQ .... 607 
Hashing for speed ...................... 610 
Overriding hashCode() ........... 613 
Choosing 
an implementation .............. 617 
A performance 
test framework ........................... 618 
Choosing between Lists ............ 621 
Microbenchmarking dangers .... 626 
Choosing between Sets ............. 627 
Choosing between Maps ........... 629 
Utilities ............................... 632 
Sorting and searching Lists ...... 635 
 
Making a Collection 
or Map unmodifiable ............... 636 
Synchronizing a 
Collection or Map ................... 637 
Holding references ............ 639 
The WeakHashMap .............. 640 
Java 1.0/1.1 containers ...... 642 
Vector & Enumeration ........ 642 
Hashtable ............................... 643 
Stack ........................................ 643 
BitSet ....................................... 644 
Summary ............................ 646 
I/O 647 
The File class .................... 647 
A directory lister ........................ 647 
Directory utilities ...................... 650 
Checking for 
and creating directories ............. 654 
Input and output ............... 656 
Types of InputStream ............. 657 
Types of OutputStream ......... 658 
Adding attributes 
and useful interfaces .......... 659 
Reading from an InputStream 
with FilterlnputStream ........ 660 
Writing to an OutputStream 
with FilterOutputStream ...... 661 
Readers & Writers ......... 662 
Sources and sinks of data ......... 662 
Modifying stream behavior ...... 663 
Unchanged classes .................... 664 
Off by itself: 
RandomAccessFile ....... 665 
Typical uses 
of I/O streams .................... 665 
Buffered input file ...................... 665 
Input from memory .................. 666 
Formatted memory input .......... 667 
Basic file output ........................ 668 
Storing and recovering data ..... 669 
Reading and writing 
random-access files .................. 670 
Piped streams ............................ 672 
File reading 
& writing utilities ............... 672 
Reading binary files ................... 674 
Standard I/O ....................... 675 
Reading from standard input .... 675 
Changing System.out 
to a PrintWriter ...................... 676 
Redirecting standard I/O .......... 676 
Process control ................... 677 
New I/O ............................. 679 
Converting data.......................... 681 
Fetching primitives ................... 684 
View buffers ............................... 685 
Data manipulation 
with buffers ............................... 688 
Buffer details ............................. 689 
Memory-mapped files ............... 692 
File locking ................................. 695 
Compression ...................... 698 
Simple compression 
with GZIP .................................. 698 
Multifile storage with Zip .......... 699 
Java ARchives (JARs) ................ 701 
Object serialization ............ 703 
Finding the class ........................ 706 
Controlling serialization ............ 707 
Using persistence ....................... 713 
XML .................................... 718 
Preferences .......................... 721 
Summary ............................ 722 
Enumerated Types 725 
Basic enum features ......... 725 
Using static imports 
with enums ............................... 726 
Adding methods 
to an enum ........................ 727 
Overriding enum methods ....... 728 
enums in 
switch statements ............. 728 
The mystery 
of values() ........................ 729 
Implements, 
not inherits ......................... 732 
Random selection .............. 732 
Using interfaces 
for organization .................. 734 
Using EnumSet 
instead of flags ................... 737 
Using EnumMap ............. 739 
Constant-specific 
methods .............................. 740 
Chain of Responsibility 
with enums ............................... 743 
State machines with enums ..... 746 
Multiple dispatching ........... 751 
Dispatching with enums .......... 753 
Using 
constant-specific methods ......... 755 
Dispatching 
with EnumMaps ...................... 756 
Using a 2-D array ....................... 757 
Summary ............................ 759 
 
Annotations 761 
Basic syntax ....................... 762 
Defining annotations ................. 762 
Meta-annotations ...................... 763 
Writing 
annotation processors ........ 765 
Annotation elements ................. 765 
Default value constraints ........... 766 
Generating external files............ 766 
Annotations don\u2019t 
support inheritance ................... 769 
Implementing the processor...... 769 
Using apt to 
process annotations ............ 772 
Using the Visitor pattern 
with apt .............................. 775 
Annotation-based 
unit testing .......................... 778 
Using @Unit with generics ....... 785 
No \u201csuites\u201d necessary .................786 
Implementing @Unit ............... 787 
Removing test code .................... 792 
Summary ............................. 795 
Concurrency 797 
The many faces of 
concurrency ....................... 798 
Faster execution .........................798 
Improving code design ............. 800 
Basic threading .................. 801 
Defining tasks ............................ 801 
The Thread class ..................... 802 
Using Executors ..................... 804 
Producing return values 
from tasks ................................. 806 
Sleeping ..................................... 808 
Priority ...................................... 809 
Yielding ...................................... 810 
Daemon threads ......................... 810 
Coding variations ....................... 814 
Terminology ............................... 819 
Joining a thread ......................... 819 
Creating responsive 
user interfaces ............................ 821 
Thread groups ........................... 822 
Catching exceptions .................. 822 
Sharing resources .............. 824 
Improperly 
accessing resources ................... 825 
Resolving shared 
resource contention ................... 827 
Atomicity and volatility ............. 831 
Atomic classes ........................... 836 
Critical sections .......................... 837 
 
Synchronizing on 
other objects .............................. 841 
Thread local storage ..................843 
Terminating tasks .............. 844 
The ornamental garden ............ 844 
Terminating when blocked ........ 847 
Interruption .............................. 848 
Checking for an interrupt .......... 854 
Cooperation 
between tasks ..................... 856 
wait() and notifyAll() ............ 857 
notify() vs. notifyAll() ........... 861 
Producers and consumers ........ 863 
Producer-consumers 
and queues ................................ 868 
Using pipes for I/O 
between tasks ............................. 872 
Deadlock ............................. 874 
New library 
components ........................