Back to description
The past two major releases of the JDK have seen some significant changes. JDK 5 introduced new features at the language... more
The past two major releases of the JDK have seen some significant changes. JDK 5 introduced new features at the language level, something that has not happened since Java was first released. Some of the most significant features added to the language are generics (parameterized types), enumerations, and metadata. With JDK 6, one of the biggest changes is the inclusion of a lightweight database known as Derby, which is from the Apache Database project.
The first half of this chapter introduces Derby and reviews the new language features from JDK 5. The second half of this chapter details certain key utility packages in the java.util branch of the class library that are useful for professional programming in Java.
java.util
... less
Many beginning Java developers master the concepts of the Java programming language fairly well and still have a difficult... more
Many beginning Java developers master the concepts of the Java programming language fairly well and still have a difficult time reaching the next level as a professional Java developer.
This is because most Java books simply focus on teaching only the Java language, a Java tool (like Ant or TestNG), or a language-neutral software methodology. This leaves you to learn techniques and practices from other software developers or at the proverbial “school of hard knocks.”
Chapter 1 discussed the advanced features of the Java languagea continuation on the theme of most beginning Java books. But now, you are starting the transition to a new kind of Java book, one more experience-centric, starting with this chapter. In this chapter, you will get a feel for the tools and techniques of modern Java development. It introduces you to “thinking like a professional Java developer,” which continues in the next chaptera discussion of Java design patterns.
By the end of this chapter, you should have acquired the following skills:
Familiarity with the principles of quality software development
Familiarity with the habits of an effective software developer
Awareness of a number of the prominent software development methodologies
Acquaintance with many of the tools commonly found in Java development environments
In Chapter 2, you learned about half of “thinking like a Java developer” when software development methodologies... more
In Chapter 2, you learned about half of “thinking like a Java developer” when software development methodologies were discussed. This chapter handles the other halfthe use of patterns to make you an effective Java developer.
This is not a patterns book. This chapter is included because patterns are critical to understanding and communicating the designs of application programming interfaces, tools, and other applications. This is because the vast majority of these technologies are built on top of design patterns.
If I had to pick one aspect of software engineering that I absolutely love, hands down, it would be software design. Designing software well is challenging and it requires a combination of creativity and problem-solving skills. The experience of creating a solution in software can be very rewarding. If you are just becoming familiar with the Java programming language, software design can be a little overwhelming. It’s like a blank canvas with a lot of colors from which to choose. Design decisions are difficult to make becausewithout experienceit is difficult to understand how the choices you make will affect the application later.
Learning design patterns is the single best way to increase your abilities as a software engineer. Technology changes very quickly. To give things a little perspective, learning a new technology is like reading a good book; learning patterns is like learning to read.
The focus of this chapter is to communicate why design patterns are important and highlight commonly occurring patterns. Hopefully, if you haven’t been turned on to patterns already, this chapter will give you some reasons to pursue them.
There are plenty of patterns books. I feel these three represent some of the best work written on the subject: Refactoring: Improving the Design of Existing Code by Martin Fowler; Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides; and Applying UML and Patterns: An Introduction to Objected-Orient Analysis and Design and the Unified Process by Craig Larman.
This chapter provides you with a strong definition of a pattern, an understanding of why patterns are important, tricks to understanding a pattern, and an explanation of important Java patterns. This chapter is divided into three main sections. The first section discusses the rationale behind learning patterns and some examples of where they are used in software design. The second section, building patterns from design principles, walks you through a series of exercises that show how to form patterns from basic design principles. Finally, the important patterns section walks you through code examples of a subset of well-known design patterns.
Java Foundation Classes (JFC) is a package of libraries for developing robust graphical user displays for client-side... more
Java Foundation Classes (JFC) is a package of libraries for developing robust graphical user displays for client-side applications that can be implemented on enterprise systems. The JFC API libraries comprise five different components:
AWT. The Abstract Windowing Toolkit (AWT) classes are comprised of legacy graphics code from Java 1.x that were developed to create simple user interfaces for applications and applets.
Accessibility. The Accessibility classes accommodate assistive technologies that provide access to information in user interface components.
Java 2D. The Java 2D classes contain a broad set of advanced graphics APIs that allow users to create and manipulate image, shape, and text components.
Drag and Drop. The Drag and Drop classes allow users to initiate drag operations so components can be dropped on designated target areas. This is accomplished by setting up a drop target listener to handle drop events and a management object to handle drag-and-drop operations.
Swing. The Swing classes are built atop of the AWT classes to provide high-quality GUI components for enterprise applications.
Large tomes have been written about JFC, specifically Swing libraries and their advanced presentation features, with numerous pages of APIs affiliated with those libraries that could easily be acquired by your Integrated Development Environment (IDE) or the Internet during your development activities. Along with those library presentations were some simple applications that provided little instructional value other than to demonstrate how things work in a basic fashion. Rather than getting bogged down with a recital of those voluminous APIs, this chapter concentrates the discussion on many of the Swing features that you will need to incorporate into your professional development activities to be successful. You’ll learn advanced GUI applications that combine multiple layout managers to achieve relevant presentation applications that manage data and navigation flow in an efficient manner. All of the sample applications incorporate listeners and their interfaces to manage events generated by users in their navigation activities along with Gang of Four (GoF) design patterns to promote best practices in your modeling and implementation operations.
This chapter starts by demonstrating some foundation knowledge about layout managers so that you can conceptualize Swing layout designs from a high-level perspective and then implement them using JFC libraries in an efficient manner. With a solid handle on what these libraries can do for you, you will be able to approach your development tasks with greater confidence, which will result in more germane product development. The next two sections of this chapter cover some practical applications concerning the new Mustang desktop features and how navigation flows in your GUI application can be managed with the assistance GoF design patterns.
The previous chapter discussed building user interfaces and stand-alone Java applications using the Java Foundation Classes... more
The previous chapter discussed building user interfaces and stand-alone Java applications using the Java Foundation Classes (JFC). A key feature of many applications is the ability to save its state off to a file. Image manipulation programs need to read and write images to disk. Word processing and other office-productivity applications need to read and write spreadsheets, presentations, and text-based documents. Essentially, to do any of these save operations, an application must take its in-memory representation of its state, and write it to disk. Later on, this file can be read back into memory, putting the application back to exactly where the user had left using it.
Different applications need to save different pieces of information to disk. Some applications really only need to save their configuration to disk, because they may save their other data to a database (the subsequent chapter shows you how to persist your application’s data to a database). A typical single-user application such as a word processor or image manipulation program will need to save its state to files. Java provides a couple of built-in mechanisms for saving or serializing data to disk. The two major APIs in the JDK for persisting application data to disk are the Java Serialization API for generic serialization and the XMLEncoder/Decoder API for serializing JavaBean components.
This chapter looks at the Java Serialization API, the XMLEncoder/Decoder API, and the Java API for XML Binding (JAXB). JAXB provides mechanisms to read and write to user-defined XML file formats. Each of these three APIs has different approaches to serialization and as such should be used in different circumstances. This chapter looks at the Serialization API first, followed by the XMLEncoder/Decoder API, and finishes with JAXB.
In the previous chapter, you learned about how to persist the state of your application using file-based mechanisms.... more
In the previous chapter, you learned about how to persist the state of your application using file-based mechanisms. This is a useful way to handle things in a single-user model, but when multiple users need to share the same data, databases are the solution. In this chapter, you learn about how to persist your application to a database.
Java is an object-oriented programming language. Database programming and object-oriented design can feel like oil and water. Because of this difference between the two technologies, there are two schools of thought for database development in an object-oriented environment. The first is that the database is just a resource, like any other, and the API that communicates with the database needs to have robust tools related to working tabular data. The second school of thought is that the objects in the application represent the data, there is no separation; therefore, the access should be seamless.
This chapter is organized around those two thoughts. The first section explores the JDBC 4.0 API, which provides robust tools for dealing with tabular relational data. In my view, JDBC is one of the most highly used and significant APIs developed for the Java platform. It’s one of the reasons Java is portable across platform and database alike.
The second section of the chapter explores the Object Relational Mapping (ORM) approach. An ORM framework is used to abstract data access. This allows your application to communicate directly with objects, instead of relational table structures.
Database access has always required effort, regardless of your development language. Java has been making substantial leaps in this area and has come a long way in making the task much easier with its addition of the JDBC 4.0 API. This chapter discusses how to persist your application’s data to a database using features of the JDBC 4.0 API. JDBC has undergone major improvements building upon JDK 5’s introduction of Annotations. JDK 1.6 and JDBC 4.0 have made it easier to do database development.
Java and its open source community are becoming extremely aware of the importance of data persistence, especially for a developer in the J2EE architecture. Therefore they continue to enhance the JDBC API to support the ever-growing needs of its developers.
Look into any web application, and you should recognize the presence of some web navigation scheme that dictates how pages... more
Look into any web application, and you should recognize the presence of some web navigation scheme that dictates how pages should flow along with the data that needs to be processed with them. Some applications employ Model 1 Architecture practices that hard code these flows in the pages that comprise their web applications, whereas others use Model 2 practices that embed flow attributes in an external file so that maintenance and navigation paths can be handled outside the code itself. Inevitably, speculations during the design phase of your program will have to be made as to which method will be put into practice prior to software deployment. Outside influences, like experimentation and lessons learned from previous engagements (“been there, done that, got the T-shirt”), could be used in your decision making, but more likely, delivery timelines, staff maturity, and scheduling constraints will affect this decision.
This chapter demonstrates how you can overcome speculation over how to construct a web application using the Model 1 Architecture by constructing a hands-on Contact Management Tool. Two different types of Java syntax, JSTL 1.1 and JSP 2.0, will be utilized to craft the sample GUI component that will allow users to manage contact information through upload and query activities. The sample application’s use of Model 1 was chosen to suit design and implementation needs for a quick prototype that can be implemented by novice Java Web developers in an easy fashion, and to demonstrate some of the new Java language enhancements that were delivered with the JSTL 1.1 and JSP 2.0 specifications.
Additionally, consideration is shown for the very popular AJAX technology and some language extensions that circumvent traditional request/response operations accompanying web page submission and refresh activities.
In the previous chapter, you learned about building web applications using the Model 1 Architecture,... more
In the previous chapter, you learned about building web applications using the Model 1 Architecture, which is heavily dependent on a page-centric development focus. In this chapter, you review and apply a prominent pattern in software development known as Model-View-Controller (MVC) to build web applications in a more modular and componentized manner. You learn a little about the Model 2 Architecture, particularly a framework known as WebWork, and its use of a concept known as Inversion of Control. You will see an example of how componentized development with WebWork provides a tremendous advantage to you as a web developer, as it saves you time in having to rebuild the same components over and over in your application.
This chapter discusses connecting Java programs to programs written in C/C++. Java Native Interface (JNI) provides a sophisticated... more
This chapter discusses connecting Java programs to programs written in C/C++. Java Native Interface (JNI) provides a sophisticated mechanism for invoking routines written in native code, and also provides a mechanism for native code to call routines that are written in Java.
Many developers were introduced to the promise of Enterprise JavaBeans (EJBs) eight years ago during the dotcom era where... more
Many developers were introduced to the promise of Enterprise JavaBeans (EJBs) eight years ago during the dotcom era where mad speculation about what was necessary to be successful in business with new technologies relied more on hype than reality for normal business operations. On effort after effort people were convinced that large solutions implemented with EJBs would solve all problems when most were easily handled by simple web applications accompanied by other services (security, caching, and so forth).
More often than not, complexities of the EJB architecture necessitated the development of bloated models too cumbersome to deploy and maintain on software deployments. XML deployment descriptor requirements for individual EJBs and extraneous callback method generation, along with difficult EJB Query Language constructs, all contributed to an unpleasant development experience that forced developers to seek alternative technologies for their enterprise implementations. Also, EJBs promoted non-object-oriented-like code generation that dictated the use of parameter passing constructs to marshal data collections across the network.
But the biggest reason why EJBs were a problem in the past was how entity beans gave rise to latency issues on the systems they ran on when those systems performed lots of transactions. In earlier releases, entity beans were individual resources, shared by both session and thread processes, that were always accessed within transactions. This access meant that a bean was dedicated to that transaction until that process was either rolled back or committed, causing other processes that wanted access to that entity to queue up for it. As the number of entity beans being accessed grew on a system, so did the performance problems.
During the past few years, the introduction of two new Object-Relational Mapping (O/RM) libraries, Hibernate and TopLink, were widely accepted because they allowed developers to strap their infrastructure to their code rather than forcing them to write their code to the infrastructure like EJB components did.
Thankfully, the latest EJB 3 specification contributors have learned to evolve and leverage the best practices of previous efforts, which have resulted in large number of necessary improvements that should assist developers in crafting purposeful applications for their enterprise deployments by co-locating data and the operations performed on that data, and eliminating superfluous interface components that had been previously required for implementation. Now, session beans are Plain Old Java Objects (POJOs) managed by the EJB container. Once the session bean is deployed into the EJB container, a stub object is created, and it is registered in the server’s Java Naming Directory Interface (JNDI) registry. Client code components now obtain a stub of the bean using the class name of the interface in the JNDI. This new concept called Inversion of Control allows developers to craft their application components independently of how they will be created.
This chapter focuses on high-level concepts that apply to the new features of the EJB 3 and Java Persistence API (JPA) specifications, but more importantly on the introduction and implementation of Interceptors, Resource Injection capabilities, JPA libraries, and EJB 3 annotations with relevant working applications and web components to facilitate user understandings and their deployment in enterprise applications.
Java is an ideal platform for server-side development. Many of the ongoing professional and open source Java development... more
Java is an ideal platform for server-side development. Many of the ongoing professional and open source Java development projects are for various server-side applications. Java EE (Enterprise Edition) dominates this Java server space, providing a strong open platform for many different types of server applications. One of the core principles and architectural themes in Java EE is the ability to segregate and distribute various components of the same software system to different machines. Remote communication between Java objects and components to other Java objects and components is at the heart of Java EE. Because Java EE is an open platform, it also defines how external objects and components in other applications (and other programming languages) communicate with Java EE components. In today’s heterogeneous Internet-centric computing world, this cross-platform communication is absolutely essential.
Component is an ambiguous term that can mean many different things to many different developers. In the context of this chapter, component refers to any software object or collection of objects that are network-aware, either sending information to other components or receiving it from the latter. For a high-level example, a web server could be considered a component. Web browsers and other client applications need to communicate with this component. More granular examples include Enterprise JavaBeans (EJBs; see Chapter 10 ), and Web Services.
In this chapter, you investigate the general high-level design of component-to-component communication as well as some concrete examples for coding the actual communication. The java.net package is looked at first for its sockets support, because sockets are the basic building block for all other communication technologies. Understanding protocols follows and an example partial implementation of HTTP is demonstrated. A brief discussion of Remote Method Invocation (RMI) and the Common Object Request Broker Architecture (CORBA) comes next. Concluding the chapter is information on how best to utilize the newest addition to JDK 6, Web Services.
java.net
The information regarding sockets and protocols will be trivial for the advanced developer but crucial for a developer with no distributed programming experience. If you are an advanced developer familiar with sockets, protocols, and understand the basic premises of RMI and CORBA, feel free to skip ahead to the “Web Services” sectionyou will probably find them too basic. Web Services are now a first-class citizen in the JDK and are rapidly becoming the cross-platform component technology of choice for new software projects.
The purpose of this chapter is to introduce you to a number of techniques and APIs for performing systems integration.... more
The purpose of this chapter is to introduce you to a number of techniques and APIs for performing systems integration. Building a new system from scratch is quite an undertaking, but it is not the norm todaymost companies have an extensive legacy IT investment. Their systems were developed over time to meet a specific need. Whether the need was customer service, order fulfillment, or finance, there was something that drove the tremendous cost and heartache associated with IT development.
Eventually the systems that represent the IT infrastructure of a corporation grow to the point where sharing data and collapsing stovepipes not only starts to make sense; it’s the only option.
This chapter differs from a number of the other chapters in this book because it is focused on specific solutions for software integration. Throughout this book you have learned a number of APIs, tools, and techniques for building software. This chapter, on the other hand, examines some specialized issues related to integrating and managing distributed applications.
Security becomes ever more important as people flock to the Web and a large number of sites (such as Amazon and online... more
Security becomes ever more important as people flock to the Web and a large number of sites (such as Amazon and online banks) store personal information about their customers, not to mention a wide variety of uses in custom enterprise solutions with multiple users. Java provides security in two major ways. Java Cryptography provides user identification/authentication and signing of digital messages. Java Authentication and Authorization Services provides programmatic access control and user authorization, granting access to various program features based on permissions and security policies. This chapter gives you a solid foundation in these APIs and shows you how to utilize them effectively. Additionally, the new digital signing of XML documents, introduced in JDK 6, is discussed.
The Java implementation of security addresses many standard facets of security such as access control, public/private key generation and management, signing of digital content, and management of digital certificates. This chapter looks at what Java provides in its various security packages and delves into the concepts of security.
This chapter describes how to package and deploy your Java applications including client-side and server-side applications.... more
This chapter describes how to package and deploy your Java applications including client-side and server-side applications. It discusses Java Web Start, JAR packaging, JAR signing, building WAR files, and CLASSPATH manipulation. You’ll walk through the different types of Java applications and get a brief introduction to each as well as information on a few useful utilities that you can use when creating, configuring, and deploying your own applications.
Purchase Before purchasing this product, please be sure you have met all software and system requirements, and that you understand any limits placed upon its use.
Return Policy Wrox Chapters on Demand are non-returnable and non-refundable.
Reader Software Wrox Chapters on Demand are offered as PDFs, and they must be viewed using the Adobe Reader. If you do not have the Reader installed, it can be downloaded for free at Adobe.com.
Test Download As Wrox Chapters on Demand purchases are non-returnable, it is advisable that you test your system and software configurations with a free sample download before you place an order.
Usage Rights for a Wrox Chapter on Demand File Any Wrox Chapter on Demand product you purchase from this site will come with certain restrictions that allow Wiley to protect the copyrights of its products. After you purchase and download this title, you:
If you have any questions about these restrictions, you may contact Customer Care at (877) 762-2974 (8 a.m. - 5 p.m. EST, Monday - Friday). If you have any issues related to Technical Support, please contact us at 800-762-2974 (United States only) or 317-572-3994 (International) 8 a.m. - 8 p.m. EST, Monday - Friday).
Related Books
Java Resources