DevelopMentor Chief Scientist Stuart Halloway presents unprecedented, in-depth coverage of writing, deploying, and maintaining Java components. Halloway begins by showing how to use, control, and troubleshoot components. He offers real-world guidance on reflection performance, and demonstrates how reflection is used to build the Java serialization architecture. He also offers detailed coverage of using the Java Native Interface JNI to control the boundaries between Java code and components written in other environments. In Part II, Halloway presents a practical vision for using component services to become a more effective Java developer.
|Published (Last):||5 May 2017|
|PDF File Size:||13.96 Mb|
|ePub File Size:||10.88 Mb|
|Price:||Free* [*Free Regsitration Required]|
Where those designations appear in this book and Addison-Wesley, Inc. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers discounts on this book when ordered in quantity for special sales.
ISBN 1. Java Computer programming language 2. System design. All rights reserved. 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, or otherwise, without the prior consent of the publisher. Printed in the United States of America.
Published simultaneously in Canada. For information on obtaining permission for use of material from this work, please submit a written request to: Pearson Education, Inc. GetField Caveats 4. While many of his colleagues felt he had lost his senses, Stu ignored our skepticism and walked away from COM completely.
This was especially difcult given the fact that his employer had a tremendous investment in COM and had achieved relatively little traction in the Java world at the time. Based on this book, I feel the move was benecial both to Stu and to those who will be inuenced by this book. Are there languages and compilers that generate these components? Rather, Stu focuses the reader on the role the JVM plays in software integration.
After spending over eight years working with COM and now two years with its successor, the Common Language Runtime CLR , I believe that the key to understanding any component technology is to rst look at how component code is discovered, initialized, and scoped during execution. In the JVM, the class loader is responsible for all of these tasks, and Stu gives that devil more than its due. The JVM and the Java platform as a whole has a serious competitor now that Microsoft has more or less subsumed most Java technology into its.
Hopefully, Sun will remain true to this basic design principle as the pressures of platform warfare pull them in the direction of adding feature upon feature for market positioning rather than aesthetic reasons. In this book, the term component has a very specic meaning.
A component is an independent unit of production and deployment that is combined with other components to assemble an application. To elaborate on this denition, consider the difference between objects and components. An object represents an entity in the problem domain, while a component is an atomic1 piece of the installed solution.
The object and component perspectives are complementary, and good designs take account of both. Modern development platforms such as Java provide the infrastructure that developers need to create classes and components. To support object-oriented programming, Java provides encapsulation, inheritance, and polymorphism. To support components, Java provides loaders and rich type information.
Loaders are responsible for locating, bringing into memory, and connecting components at runtime. Load components dynamically as needed. Load components from other machines on the network.
Locate components from custom repositories. Create mobile code agents that live across multiple virtual machines. Import the services of non-Java components. Atomic here means "indivisible," not necessarily "stands alone. In a world of distributed applications and multiple component suppliers, loaders locate and connect compatible components.
Type information describes the capabilities of some unit of code. In some development environments type information is present only in source code. In Java, type information is not merely a source code artifact; it is also an intrinsic part of a compiled class and is available at runtime through a programmatic interface.
Because Java type information is never "compiled away," loaders use it to verify linkages between classes at runtime. In application programming, you can use type information to Serialize the state of Java objects so that they can be recreated on another virtual machine. Create dynamic proxies at runtime, to provide generic services that can decorate any interface. Translate data into alternate representations to interoperate with non-Java components.
Convert method calls into network messages. Convert between Java and XML, the new lingua franca of enterprise systems. Annotate components with application-specic metadata. Type information automates many tasks that might otherwise be coded by hand, and it helps to make components forward compatible to platforms of the future. Who Should Read This Book You should read this book if you want to design, develop, or deploy substantial applications in Java.
Taking a full-lifecycle view of a Java application requires that you consider not just objects, but components. This book is about the core features of Java as a component platform: class loaders, reection, serialization, and interoperation with other platforms. You should already know the basics of Java syntax and have some experience in object-oriented programming with Java.
If you learn how to use the component services described here, you will understand how these high-level technologies are built, which is the key to employing them effectively.
Security is also an important aspect of component development and deployment. It is too complex a topic to handle fairly here, and it deserves its own book-length treatment. See [Gon99] for coverage of security on the Java platform. Organization of the Book The chapters of this book fall into three sections. Chapter 1 introduces components. Chapters 2 through 6 explain loaders and type information on the Java platform.
Chapter 7 shows more advanced uses of these services. Chapter 1 introduces component-oriented programming. Component relationships must be established not only at compile time, but also at deployment and runtime. This chapter asks the key questions of component programming and relates them to the Java platform services discussed in subsequent chapters.
Though the other chapters might be read out of order, you should denitely read this chapter rst. Chapter 2 shows how to use and troubleshoot class loaders. Class loaders control the loading of code and create namespace boundaries between code in the same process.
With class loaders you can load code dynamically at runtime, even from other machines. Class loader namespaces permit multiple versions of the same class in a single Java virtual machine. You can use class loaders to reload changed classes without ever shutting down the virtual machine. You will see how to use class loaders, how the class loader delegation model creates namespaces, and how to troubleshoot class loading bugs. You will also learn to effectively control the bootclasspath, extensions path, and classpath.
Chapter 3 introduces Java type information. Java preserves type information in the binary class format. You can access type information at runtime via reection, and you can use type information to build generic services that add capability to any object.
You will see how to use dynamic invocation, dynamic proxies, package reection, and custom attributes. Chapter 3 also includes a discussion of reection performance. Chapter 4 shows how Java serialization uses reection. Serialization is a perfect example of a generic service. You will see how the serialization format embeds its own style of type information and how you can customize that representation.
You will also see how to extend default serialization, replace it entirely with custom externalization code, or tune it to handle multiple versions of a class as code evolves. You will then learn how to validate objects being deserialized into your application and how to annotate serialized objects with instructions for nding the correct class loader.
Chapter 5 returns to class loaders and shows you how to implement your own. While the standard class loaders are dominant in most applications, custom class loaders allow you to transform class code as classes are loaded. These transformations could include decryption, adding instrumentation for performance monitoring, or even building new classes on-the-y at runtime. Chapter 6 presents the Java Native Interface JNI as a basic means of controlling the boundary between Java code and components written in other environments.
JNI provides a set of low-level tools for exposing Java objects to platform native code and native code to Java objects. You will learn to use the JNI application programming interface API to translate between Java and native programming styles—which differ markedly in their approach to class loading, type information, resource management, error handling, and array storage. Chapter 7 discusses using Java metadata to automate the creation of source code or bytecode.
Generated code is a high-performance strategy for reuse because you generate only the exact code paths that you will need at runtime. The chapter rst presents JSP and EJB as examples of existing applications that auto-generate code, and then it introduces some ideas for code generation in your own programs.
Appendix A returns to interoperation. This chapter uses the open source Jawin library as an example, to show you how to generate Java stubs for Win32 objects, and vice versa. Sample Code, Website, Feedback… Unless specically noted otherwise, all the sample code in this book is open source. Most of the code in the book will work identically under SDK versions 1.
Where this is not the case, the text will include a specic reference to the appropriate SDK version. The author welcomes your comments, corrections, and feedback.
Please send email to stu develop. Acknowledgments First and foremost, thanks to my wife Joanna.
Component Development For The Java Platform
Where those designations appear in this book and Addison-Wesley, Inc. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers discounts on this book when ordered in quantity for special sales. ISBN 1. Java Computer programming language 2. System design.
Java Type Information and Reflection
Most of this metadata is type information enumerating the base class, superinterfaces, fields, and methods of the class. Type information is used to make the dynamic linking of code more reliable by verifying at runtime that clients and servers share a common view of the classes they use to communicate. The presence of type information also enables dynamic styles of programming. You can introspect against a binary class to discover its fields and methods at runtime.
Component Development for the Java™ Platform by Stuart Dabbs Halloway
Component Development for the Java Platform