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

Thinking in Java - 4th Edition


DisciplinaProgramação Orientada A Objetos4.521 materiais64.682 seguidores
Pré-visualização50 páginas
879 
CountDownLatch .................. 879 
CyclicBarrier .......................... 881 
DelayQueue ........................... 883 
PriorityBlockingQueue....... 885 
The greenhouse controller 
with ScheduledExecutor ...... 887 
Semaphore ............................. 890 
Exchanger .............................. 893 
Simulation .......................... 896 
Bank teller simulation .............. 896 
The restaurant simulation ........ 900 
Distributing work ..................... 904 
Performance tuning ........... 909 
Comparing 
mutex technologies ................... 909 
Lock-free containers .................. 916 
Optimistic locking...................... 922 
ReadWriteLocks .................... 923 
Active objects ..................... 925 
Summary ............................ 929 
Further reading .......................... 931 
Graphical 
User Interfaces 933 
Applets ............................... 935 
Swing basics ....................... 935 
A display framework .................. 937 
Making a button ................. 938 
Capturing an event ............. 939 
Text areas ........................... 941 
Controlling layout .............. 942 
BorderLayout ......................... 942 
FlowLayout ............................. 943 
GridLayout .............................. 944 
GridBagLayout....................... 944 
Absolute positioning .................. 945 
BoxLayout ............................... 945 
The best approach? .................... 945 
The Swing event model ..... 945 
Event and listener types ........... 946 
Tracking multiple events ........... 951 
A selection of 
Swing components ............ 953 
Buttons ....................................... 953 
Icons .......................................... 955 
Tool tips ..................................... 957 
Text fields ................................... 957 
Borders ....................................... 959 
A mini-editor.............................. 959 
Check boxes .............................. 960 
Radio buttons ............................. 961 
Combo boxes 
(drop-down lists) ...................... 962 
List boxes .................................. 963 
Tabbed panes ............................. 965 
Message boxes ........................... 965 
Menus ......................................... 967 
Pop-up menus ............................ 972 
Drawing ...................................... 973 
Dialog boxes ............................... 975 
File dialogs .................................978 
HTML on 
Swing components .................... 980 
Sliders and progress bars ......... 980 
Selecting look & feel ................... 981 
Trees, tables & clipboard .......... 983 
JNLP and 
Java Web Start ................... 983 
Concurrency & Swing ........ 988 
Long-running tasks ................... 988 
Visual threading ........................ 994 
Visual programming 
and JavaBeans ................... 996 
What is a JavaBean? ................. 996 
Extracting Beanlnfo 
with the Introspector ............ 998 
A more sophisticated Bean ..... 1002 
JavaBeans and 
synchronization ....................... 1005 
Packaging a Bean .................... 1008 
More complex Bean support .. 1009 
More to Beans .......................... 1010 
Alternatives to Swing ........ 1010 
Building Flash Web 
clients with Flex ................ 1011 
Hello, Flex ................................. 1011 
Compiling MXML .................... 1012 
MXML and ActionScript.......... 1013 
Containers and controls........... 1013 
Effects and styles ..................... 1015 
Events ....................................... 1016 
Connecting to Java .................. 1016 
Data models 
and data binding ...................... 1018 
Building and deploying............ 1019 
Creating SWT 
applications ...................... 1020 
Installing SWT ......................... 1020 
Hello, SWT ............................... 1021 
Eliminating redundant code.... 1023 
Menus ...................................... 1024 
Tabbed panes, buttons, 
and events ................................ 1025 
Graphics ................................... 1028 
Concurrency in SWT ................ 1030 
SWT vs. Swing? ........................ 1032 
Summary .......................... 1033 
Resources ................................. 1033 
A: Supplements 1035 
Downloadable 
supplements ..................... 1035 
Thinking in C: 
Foundations for Java ....... 1035 
Thinking in Java 
seminar ............................. 1035 
Hands-On Java 
seminar-on-CD ................ 1036 
Thinking in Objects 
seminar ............................. 1036 
Thinking in 
Enterprise Java ................ 1036 
Thinking in Patterns 
(with Java) ....................... 1037 
Thinking in Patterns 
seminar ............................. 1037 
Design consulting 
and reviews ...................... 1038 
B: Resources 1039 
Software ........................... 1039 
Editors & IDEs ................. 1039 
Books ................................ 1039 
Analysis & design ..................... 1040 
Python ...................................... 1042 
My own list of books ................ 1042 
Index 1045 
 
Preface 
I originally approached Java as \u201cjust another programming 
language,\u201d which in many senses it is. 
But as time passed and I studied it more deeply, I began to see that the fundamental intent of 
this language was different from other languages I had seen up to that point. 
Programming is about managing complexity: the complexity of the problem you want to 
solve, laid upon the complexity of the machine in which it is solved. Because of this 
complexity, most of our programming projects fail. And yet, of all the programming 
languages of which I am aware, almost none have gone all out and decided that their main 
design goal would be to conquer the complexity of developing and maintaining programs.1 Of 
course, many language design decisions were made with complexity in mind, but at some 
point there were always other issues that were considered essential to be added into the mix. 
Inevitably, those other issues are what cause programmers to eventually \u201chit the wall\u201d with 
that language. For example, C++ had to be backwards-compatible with C (to allow easy 
migration for C programmers), as well as efficient. Those are both very useful goals and 
account for much of the success of C++, but they also expose extra complexity that prevents 
some projects from being finished (certainly, you can blame programmers and management, 
but if a language can help by catching your mistakes, why shouldn\u2019t it?). As another example, 
Visual BASIC (VB) was tied to BASIC, which wasn\u2019t really designed to be an extensible 
language, so all the extensions piled upon VB have produced some truly unmaintainable 
syntax. Perl is backwards-compatible with awk, sed, grep, and other Unix tools it was meant 
to replace, and as a result it is often accused of producing \u201cwrite-only code\u201d (that is, after a 
while you can\u2019t read it). On the other hand, C++, VB, Perl, and other languages like Smalltalk 
had some of their design efforts focused on the issue of complexity and as a result are 
remarkably successful in solving certain types of problems. 
What has impressed me most as I have come to understand Java is that somewhere in the 
mix of Sun\u2019s design objectives, it seems that there was a goal of reducing complexity for the 
programmer. As if to say, \u201cWe care about reducing the time and difficulty of producing 
robust code.\u201d In the early days, this goal resulted in code that didn\u2019t run very fast (although 
this has improved over time), but it has indeed produced amazing reductions in development 
time\u2014half or less of the time that it takes to create an equivalent C++ program. This result 
alone can save incredible amounts of time and money, but Java doesn\u2019t stop there. It goes on 
to wrap many of the complex tasks that have become important, such as multithreading