没有合适的资源?快使用搜索试试~ 我知道了~
首页深入理解Java:思维之旅
深入理解Java:思维之旅
需积分: 10 1 下载量 93 浏览量
更新于2024-07-26
收藏 1.07MB PDF 举报
"《Think IN java》是一本深入探讨Java编程思想的书籍,作者Bruce Eckel是MindView, Inc.的总裁。这本书旨在帮助读者理解Java的强大之处,尤其是在解决复杂问题时的优势。书中强调了Java不仅仅是一系列特性的集合,而是需要在设计层面去理解和应用。通过构建一个知识结构模型,读者可以更深入地掌握Java语言,并能够运用它来解决问题。书中的章节围绕特定类型的编程问题展开,提供了挑战性的练习,并特别提到了关于Collections的精彩内容。这本书不仅适合初学者全面学习,也是经验丰富的开发者的重要参考书籍。读者反馈中,有人提到它对于通过Sun Certified Java Programmer考试有很大帮助,同时也称赞其深入浅出的示例和解释,认为它是学习Java的理想教材。"
《Think IN java》第四版深入介绍了Java编程的核心概念,鼓励读者不仅仅是从语法层面去学习Java,而是要理解其设计理念。书中提到,Java的强大在于其在面对复杂问题时的表达能力和灵活性。作者强调,不应孤立地看待Java的特性,而应将它们放在整体的设计框架下去理解。为了帮助读者更好地掌握这些概念,书中的每一章都会围绕一个特定的编程问题进行讲解,通过实例来展示Java如何解决这些问题。
此外,书中还强调建立一个“知识结构”模型的重要性。这个模型可以帮助读者在遇到困难时,将问题放入相应的位置,通过自我演绎找到答案。这种学习方法强调了主动思考和自我解决问题的能力,使学习过程更加高效。
书中的练习部分是提升技能的关键,它们设计得富有挑战性,旨在让读者在实践中深化理解。特别提到的“Collections”章节,可能涵盖了Java集合框架的深入探讨,包括List、Set、Map等接口及其实现类的使用,以及相关算法和数据结构的应用。
读者的评价反映了《Think IN java》的高质量和实用性,无论对于初学者还是有经验的开发者,这本书都提供了极高的价值。它被赞誉为编程教程的典范,以其完整的内容、精准的例子和严谨的解释赢得了高度认可,被认为是学习Java的必备读物。
Unary minus
and plus operators ....................... 69
Auto increment and decrement
............................................. 69
Relational operators............ 70
Testing object equivalence........... 70
Logical operators..................71
Short-circuiting............................ 73
Literals................................. 73
Exponential notation ....................75
Bitwise operators................. 76
Shift operators..................... 76
Ternary if-else operator.....80
String operator
+ and += .............................. 81
Common pitfalls
when using operators.......... 82
Casting operators ................82
Truncation and rounding............. 83
Promotion .................................... 84
Java has no “sizeof”.............84
A compendium
of operators .........................84
Summary ............................. 92
Controlling Execution 93
true and false.................... 93
if-else.................................. 93
Iteration............................... 94
do-while ..................................... 95
for................................................ 95
The comma operator.................... 96
Foreach syntax .................... 97
return................................. 99
break and continue......... 99
The infamous “goto” ..........101
switch............................... 104
Summary ........................... 106
Initialization & Cleanup 107
Guaranteed initialization
with the constructor.......... 107
Method overloading .......... 109
Distinguishing
overloaded methods....................110
Overloading with primitives ........111
Overloading on return values ..... 114
Default constructors........... 115
The this keyword............... 116
Calling constructors
from constructors ....................... 118
The meaning of static................ 119
Cleanup: finalization
and garbage collection....... 120
What is finalize() for? ..............120
You must perform cleanup ......... 121
The termination condition ......... 122
How a garbage collector works... 123
Member initialization........ 125
Specifying initialization.............. 127
Constructor initialization.. 128
Order of initialization .................128
static data initialization ............ 129
Explicit static initialization ....... 131
Non-static
instance initialization ................. 132
Array initialization ............ 134
Variable argument lists .............. 137
Enumerated types ............. 142
Summary ........................... 144
Access Control 145
package:
the library unit................... 146
Code organization....................... 147
Creating unique
package names............................148
A custom tool library ...................151
Using imports
to change behavior...................... 152
Package caveat ............................ 153
Java access specifiers ........ 153
Package access ............................ 153
public: interface access ............. 154
private: you can’t touch that! ... 155
protected: inheritance access .. 156
Interface
and implementation.......... 158
Class access........................ 159
Summary ........................... 162
Reusing Classes 165
Composition syntax........... 165
Inheritance syntax............. 168
Initializing the base class............170
Delegation.......................... 172
Combining composition
and inheritance...................173
Guaranteeing proper cleanup..... 175
Name hiding ............................... 178
Choosing composition
vs. inheritance ................... 179
protected......................... 180
Upcasting............................181
Why “upcasting”?........................182
Composition vs. inheritance revisited
.....................................................182
The final keyword ............ 183
final data ....................................183
final methods ............................ 186
final classes ............................... 188
final caution.............................. 189
Initialization
and class loading ............... 190
Initialization with inheritance ... 190
Summary ............................ 191
Polymorphism 193
Upcasting revisited............ 193
Forgetting the object type...........194
The twist ............................ 196
Method-call binding ...................196
Producing the right behavior......197
Extensibility ................................199
Pitfall: “overriding”
private methods .......................202
Pitfall: fields
and static methods ................... 203
Constructors and polymorphism
...........................................204
Order of constructor calls ..........204
Inheritance and cleanup ............206
Behavior of polymorphic
methods inside constructors...... 210
Covariant return types ...... 212
Designing
with inheritance ................ 213
Substitution vs. extension...........214
Downcasting and runtime
type information .........................215
Summary ............................217
Interfaces 219
Abstract classes
and methods...................... 219
Interfaces........................... 222
Complete decoupling ........ 225
“Multiple inheritance”
in Java ...............................230
Extending an interface
with inheritance ................232
Name collisions when
combining interfaces ................. 233
Adapting to an interface.... 234
Fields in interfaces ............ 236
Initializing fields in interfaces ... 236
Nesting interfaces.............. 237
Interfaces and factories.....239
Summary ...........................242
Inner Classes 243
Creating inner classes .......243
The link to
the outer class....................245
Using .this and .new .......246
Inner classes
and upcasting ....................248
Inner classes in
methods and scopes ..........249
Anonymous
inner classes ...................... 251
Factory Method revisited ...........255
Nested classes.................... 257
Classes inside interfaces ............ 258
Reaching outward from
a multiply nested class................259
Why inner classes? ............260
Closures & callbacks .................. 262
Inner classes &
control frameworks ................... 264
Inheriting from
inner classes ......................270
Can inner classes
be overridden?...................270
Local inner classes............. 272
Inner-class identifiers ....... 273
Summary ...........................274
Holding Your Objects 275
Generics and
type-safe containers .......... 275
Basic concepts ...................278
Adding groups
of elements ....................... 280
Printing containers............ 281
List....................................283
Iterator............................287
ListIterator ............................. 289
LinkedList.......................290
Stack................................. 291
Set .....................................293
Map...................................296
Queue...............................299
PriorityQueue ........................ 300
Collection vs. Iterator ..302
Foreach and iterators ........305
The Adapter Method idiom........307
Summary ...........................309
Error Handling
with Exceptions 313
Concepts .............................313
Basic exceptions ................ 314
Exception arguments ..................315
Catching an exception....... 316
The try block...............................316
Exception handlers .....................316
Creating your
own exceptions...................317
Exceptions and logging...............319
The exception
specification ...................... 322
Catching any exception ..... 323
The stack trace ........................... 324
Rethrowing an exception ........... 325
Exception chaining .................... 328
Standard Java
exceptions...........................331
Special case:
RuntimeException.................331
Performing cleanup
with finally....................... 333
What’s finally for? .................... 334
Using finally during return.... 336
Pitfall: the lost exception ........... 337
Exception restrictions ....... 339
Constructors...................... 341
Exception matching .......... 345
Alternative approaches ..... 347
History........................................ 348
Perspectives ............................... 349
Passing exceptions
to the console ..............................351
Converting checked
to unchecked exceptions.............351
Exception guidelines ......... 353
Summary ........................... 354
Strings 355
Immutable Strings........... 355
Overloading ‘+’ vs. StringBuilder
........................................... 356
Unintended recursion .......360
Operations on Strings ..... 361
Formatting output............. 363
printf() ..................................... 363
System.out.format()............. 363
The Formatter class ................ 364
Format specifiers ....................... 365
Formatter conversions............ 366
String.format()...................... 369
Regular expressions ..........370
Basics ..........................................370
Creating regular expressions......373
Quantifiers ..................................374
Pattern and Matcher ..............375
split()........................................ 383
Replace operations .................... 383
reset()........................................385
Regular expressions
and Java I/O ...............................385
Scanning input .................. 387
Scanner delimiters .................. 389
Scanning with
regular expressions.................... 389
StringTokenizer............390
Summary ........................... 391
Type Information 393
The need for RTTI .............393
The Class object ...............395
Class literals............................... 399
Generic class references .............401
New cast syntax ......................... 404
Checking before a cast.......404
Using class literals ......................410
A dynamic instanceof .............. 411
Counting recursively................... 413
Registered factories........... 414
instanceof vs. Class equivalence
........................................... 417
Reflection: runtime
class information............... 418
A class method extractor ............ 419
Dynamic proxies................422
Null Objects .......................426
Mock Objects & Stubs................. 431
Interfaces and
type information................432
Summary ........................... 437
Generics 439
Comparison with C++ .......440
Simple generics .................440
A tuple library ............................ 442
A stack class ............................... 444
RandomList.............................445
Generic interfaces..............446
Generic methods ...............449
Leveraging type
argument inference ................... 450
Varargs and generic methods.....452
A generic method
to use with Generators............ 453
A general-purpose Generator.454
Simplifying tuple use ................. 455
A Set utility................................ 456
Anonymous
inner classes ...................... 459
Building
complex models................. 461
The mystery of erasure...... 463
The C++ approach ..................... 464
Migration compatibility ............. 466
The problem with erasure.......... 467
The action at the boundaries ..... 469
Compensating
for erasure ......................... 472
Creating instances of types ........ 473
Arrays of generics....................... 475
Bounds...............................480
Wildcards ..........................483
How smart is the compiler?....... 485
Contravariance........................... 487
Unbounded wildcards................ 489
Capture conversion .................... 494
Issues ................................. 495
No primitives
as type parameters ..................... 495
Implementing
parameterized interfaces ........... 497
Casting and warnings................. 497
Overloading................................ 499
Base class hijacks an interface ... 499
Self-bounded types............500
Curiously-recurring generics .....500
Self-bounding............................. 502
Argument covariance ................. 504
Dynamic type safety ..........506
Exceptions ......................... 507
Mixins................................509
Mixins in C++ ............................ 509
Mixing with interfaces ................510
Using the Decorator pattern .......512
Mixins with dynamic proxies......513
Latent typing ......................515
Compensating for
the lack of latent typing..... 518
Reflection ....................................519
Applying a method
to a sequence.............................. 520
When you don’t happen
to have the right interface.......... 522
Simulating latent typing
with adapters ..............................524
Using function objects
as strategies .......................526
Summary: Is casting
really so bad?..................... 531
Further reading...........................533
Arrays 535
Why arrays are special ...... 535
Arrays are
first-class objects ...............536
Returning an array ............539
Multidimensional
arrays .................................540
Arrays and generics........... 543
Creating test data .............. 545
Arrays.fill()..............................546
Data Generators.......................547
Creating arrays
from Generators ...................... 551
Arrays utilities ................. 555
Copying an array.........................555
Comparing arrays .......................557
Array element comparisons ....... 557
Sorting an array .......................... 561
Searching a sorted array.............562
Summary ...........................563
Containers in Depth 567
Full container taxonomy ... 567
Filling containers...............568
A Generator solution ...............569
Map generators.......................... 571
Using Abstract classes..............573
Collection
functionality ......................580
Optional operations...........583
Unsupported operations............ 584
List functionality ..............586
Sets and storage order......589
SortedSet..................................592
Queues ...............................593
Priority queues............................594
Deques ........................................595
Understanding Maps........596
Performance .............................. 598
SortedMap .............................. 600
LinkedHashMap.....................601
Hashing and hash codes....602
Understanding hashCode().... 605
Hashing for speed...................... 608
Overriding hashCode()............ 611
Choosing
an implementation............ 616
A performance
test framework ............................616
Choosing between Lists ............620
Microbenchmarking dangers..... 625
Choosing between Sets.............. 626
Choosing between Maps ........... 628
Utilities .............................. 631
Sorting and searching Lists ...... 634
Making a Collection
or Map unmodifiable ................ 635
Synchronizing a
Collection or Map................... 637
Holding references............638
The WeakHashMap ............... 640
Java 1.0/1.1 containers...... 641
Vector & Enumeration ..........641
Hashtable ................................ 642
Stack ......................................... 642
BitSet ........................................ 644
Summary ...........................646
I/O 647
The File class .................... 647
A directory lister ........................ 647
Directory utilities ....................... 650
Checking for
and creating directories ............. 655
Input and output ............... 657
Types of InputStream............. 657
Types of OutputStream.......... 658
Adding attributes
and useful interfaces ......... 659
Reading from an InputStream with
FilterInputStream................. 660
Writing to an OutputStream
with FilterOutputStream.......661
Readers & Writers.........662
Sources and sinks of data........... 663
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 .................... 671
Piped streams .............................672
File reading
& writing utilities............... 672
Reading binary files ....................675
Standard I/O ..................... 675
Reading from standard input .....675
Changing System.out
to a PrintWriter.......................676
Redirecting standard I/O ...........677
Process control .................. 677
New I/O .............................679
Converting data ......................... 682
Fetching primitives.................... 684
View buffers ............................... 686
Data manipulation
with buffers................................ 689
Buffer details.............................. 690
Memory-mapped files ............... 693
File locking................................. 696
Compression......................699
Simple compression
with GZIP................................... 699
Multifile storage with Zip .......... 700
Java ARchives (JARs)................ 702
Object serialization............703
Finding the class .........................707
Controlling serialization............ 708
Using persistence........................ 715
XML ...................................720
Preferences ........................ 722
Summary ...........................724
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 ................. 733
剩余210页未读,继续阅读
2013-12-07 上传
2012-09-21 上传
2011-03-17 上传
2011-07-25 上传
2008-10-27 上传
2010-03-25 上传
2009-10-26 上传
u010046194
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Aspose资源包:转PDF无水印学习工具
- Go语言控制台输入输出操作教程
- 红外遥控报警器原理及应用详解下载
- 控制卷筒纸侧面位置的先进装置技术解析
- 易语言加解密例程源码详解与实践
- SpringMVC客户管理系统:Hibernate与Bootstrap集成实践
- 深入理解JavaScript Set与WeakSet的使用
- 深入解析接收存储及发送装置的广播技术方法
- zyString模块1.0源码公开-易语言编程利器
- Android记分板UI设计:SimpleScoreboard的简洁与高效
- 量子网格列设置存储组件:开源解决方案
- 全面技术源码合集:CcVita Php Check v1.1
- 中军创易语言抢购软件:付款功能解析
- Python手动实现图像滤波教程
- MATLAB源代码实现基于DFT的量子传输分析
- 开源程序Hukoch.exe:简化食谱管理与导入功能
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功