![]() |
261263 263 264 264 267 268 269 11.6.1 11.6.2 Monday Morning, 10 A.M. ...................................................... Back at His Desk .................................................................... 269 272 11.7 Documenting, Prototyping, and Stakeholder Buy-In ........................... 272 11.7.1 11.7.2 11.7.3 Documenting .......................................................................... Stakeholder Buy-In ................................................................ Prototyping ............................................................................. 272 274 275 11.8 11.9 Review ................................................................................................ What You Still Don’t Know .................................................................. 276 276 11.10 Resources .......................................................................................... 11.11 Exercises ............................................................................................ 276 277 Chapter 12 12.1 12.2 12.3 12.4 12.5 12.6 12.7 12.8 12.9 Analysis and Design: Seeking the Objects ................................ What You Will Learn ........................................................................... Facing the Blank Page ....................................................................... Using CRC Cards ............................................................................... Finding the Objects ............................................................................. Finding the Methods and Attributes .................................................... Essential and Nonessential ................................................................ Analysis Paralysis ............................................................................... Real Software Engineering ................................................................. Core Classes ...................................................................................... 279 279 280 280 280 283 284 287 288 289 12.10 Review ................................................................................................ 12.11 What You Still Don’t Know .................................................................. 12.12 Resources .......................................................................................... 12.13 Exercises ............................................................................................ 289 289 289 292 Chapter 13 13.1 13.2 13.3 13.4 JUnit: Automating Unit Testing ................................................... What You Will Learn ........................................................................... JUnit: Why All the Fuss? .................................................................... Design Then Test Then Code ............................................................ Installing and Running JUnit ............................................................... 295 295 296 296 297 13.4.1 13.4.2 Downloading and Unzipping .................................................. Using JUnit ............................................................................. 299 301 13.5 Writing Test Cases ............................................................................. 303 13.5.1 13.5.2 JUnit Assertions ..................................................................... Running a Test Case ............................................................. 306 308 13.6 13.7 13.8 13.9 Running Test Suites ........................................................................... Review ................................................................................................ What You Still Don’t Know .................................................................. Resources .......................................................................................... 309 312 312 313 13.10 Exercises 313 Chapter 14 14.1 14.2 14.3 14.4 14.5 Storing the Data ............................................................................ What You Will Learn ........................................................................... Follow the Objects .............................................................................. Of Persistence .................................................................................... Thinking of the Future, or Painting in Corners .................................... Oracle, PostgreSQL, MySQL ............................................................. 315 315 316 316 316 316 14.5.1 14.5.2 14.5.3 14.5.4 MySQL ................................................................................... PostgreSQL ........................................................................... Oracle .................................................................................... Selection Criteria .................................................................... 317 317 318 318 14.6 14.7 14.8 14.9 Being Self-Contained .......................................................................... Beyond the Basics .............................................................................. Persistence Is Not the Whole Story .................................................... Setting Up PostgreSQL for BudgetPro ............................................... 318 319 322 322 14.9.1 14.9.2 14.9.3 14.9.4 Installing PostgreSQL ............................................................ Creating a postgres User ................................................. Creating Our Database .......................................................... Straight JDBC ........................................................................ 322 323 324 325 14.10 Review 325
Chapter 17 17.1 17.2 Other Ways: Alternatives to Swing ............................................. What You Will Learn ........................................................................... The IBM SWT Toolkit ......................................................................... 377 377 378
17.4 17.5 17.6 17.7 17.8 SWT and gcj ...................................................................................... Review ................................................................................................ What You Still Don’t Know .................................................................. Resources .......................................................................................... Exercises ............................................................................................ 396 398 398 398 399
18.7.1 18.7.2 Prototype ................................................................................ Design .................................................................................... 416 417 18.8 18.9 Review ................................................................................................ What You Still Don’t Know .................................................................. 420 420 18.10 Resources .......................................................................................... 18.11 Exercises ............................................................................................ 421 421 Chapter 19 19.1 19.2 19.3 JSP: Servlets Turned Inside Out ................................................. What You Will Learn ........................................................................... Servlets Turned Inside Out: JSP ........................................................ How to Write a JSP Application .......................................................... 423 424 424 426 19.3.1 19.3.2 19.3.3 19.3.4 19.3.5 19.3.6 19.3.7 Scriptlet .................................................................................. Declaration ............................................................................. Expression ............................................................................. Directive ................................................................................. New Syntax ............................................................................ JavaBeans in JSP .................................................................. Tag Libraries .......................................................................... 427 429 430 431 434 434 437 19.4 19.5 19.6 19.7 19.8 Chapter 20 20.1 20.2 20.3 Using JSP with BudgetPro ................................................................. Review ................................................................................................ What You Still Don’t Know .................................................................. Resources .......................................................................................... Exercises ............................................................................................ Open Source Web Application Servers ...................................... What You Will Learn ........................................................................... Downloading JBoss ............................................................................ Be an Enabler, or “Let’s Be Codependent!” ........................................ 438 439 440 440 441 443 443 444 444 20.3.1 20.3.2 Nonroot-Installed Software .................................................... Finer Grained Control ............................................................ 445 450 20.4 20.5 Installing JBoss ................................................................................... Things That Make It Go ...................................................................... 450 451 20.5.1 20.5.2 20.5.3 20.5.4 System V Init System ............................................................. RedHat/Fedora chkconfig .................................................... Other Distributions ................................................................. IDE Integration ....................................................................... 451 458 463 464 xviii Contents 20.6 20.7 20.8 20.9 Disposition of Forces .......................................................................... Apache Geronimo ............................................................................... Installing Geronimo ............................................................................. Running the Geronimo Server ............................................................ 464 464 467 468 20.10 Review ................................................................................................ 20.11 What You Still Don’t Know .................................................................. 20.12 Resources .......................................................................................... 468 469 469
Index 549 PrefaceJAVA AND LINUXWhy another book on Java? Why a book on Java and Linux? Isn’t Java a plat- form-independent system? Aren’t there enough books on Java? Can’t I learn everything I need to know from the Web? No doubt, there are a host of Java books on the market. We didn’t wake up one morning and say, “You know what the world really needs? Another book about Java!” No. What we realized was that there are a couple of “holes” in the Java book market. First, Linux as a development platform and deployment platform for Java applications has been largely ignored. This is despite the fact that the *nix platform (meaning all UNIX and UNIX-like systems, Linux included) has long been recognized as one of the most programmer-friendly platforms in existence. Those few resources for Java on Linux that exist emphasize tools to the exclu- sion of the Java language and APIs. Second, books on the Java language and APIs have focused on pedagogical examples that serve to illustrate the details of the language and its libraries, but very few of these examples are in themselves practically useful, and they tend xxi to deal only with the issues of writing programs, and not at all with deploying and maintaining them. Anyone who has worked on a major software project, especially a software project that is developed and deployed in a business for a business, knows that designing and coding are only about half of the work in- volved. Yes, writing Java code is only slightly affected by the development and the deployment platform, but the process of releasing and maintaining such applications is significantly different between platforms. To address these missing pieces, we decided to cover development and deployment of a Java application that has command-line, GUI, servlet, and enterprise components on a Linux platform. We’re writing the guide book we wish we had had when we started writing and deploying Java applications on Linux. We’re going to show you a simplistic enterprise application, “from cradle to grave,” but along the way cover issues of design process, production environ- ment, setup, administration, and maintenance that few books bother to cover.1 If you are considering buying this book and you are wondering if there is any information in here that you can’t get for free on the Web, then, no. There is not. In fact, there is little information in any Java or Linux book that is not available for free on the Internet. In fact, in each of our chapters we will tell you where on the Web to find virtually all of the information we present, and then some. And yet books continue to sell, and we have the chutzpah to ask you to buy the book. The reason is that Web information is scattered, unorga- nized, and of highly variable quality. We will be trying to bring all the relevant information together in this book, in a clearly organized manner (and, we would like to believe, at an acceptably high level of quality). We think that has value. Also, this book is part of the Bruce Perens’ Open Source Series. This book is part of the Web literature. And you may freely read it and use it on the Web. We hope this book will be one of those you use on the Web and buy on paper. We don’t know about you, but we like to use Web books for reference, but for reading, we like books. We own at least three books that are available for free on the Web: Thinking in C++, Thinking in Java, and O’Reilly’s Docbook: The Definitive Guide. We hope that open publishing will be the new model. 1. This is not to say this book is without purely pedagogical examples. Especially in Part I we make use of your typical “throwaway” examples and single classes. To try to illustrate the basics with a complete application would obscure and confuse the points being illustrated. FREE SOFTWARE AND JAVAGNU/Linux2 is Free Software. It is Open Source. I don’t even want to start the debate on what each term means and which one is “right.” One of the two authors of this book is a Free Software advocate, and the other is of a purely laissez-faire attitude towards the question (we won’t tell you which, although we invite you to guess). But even with a deliberate decision to cease-fire, the question remains: Is Java Open Source or Free Software? The answer is mixed. Neither Sun’s nor IBM’s Java implementations are Open Source or Free Software. You may download and use them for free, but you do not have the source code to them, nor do you have the right to make modifications to them.3 This book will cover the GNU Compiler for Java, which compiles Java source code to native machine code. The GNU Compiler for Java (gcj) is both Open Source and Free Software. It is, however, supporting differing levels of the Java APIs (some packages are current, some are back at 1.1.x levels) and does not fully support the AWT or Swing GUIs. However, none of this means that you cannot write your own Java pro- grams and release them under a Free Software or Open Source license. So you can certainly develop Free Software in Java. Staunch Free Software partisans (such as Richard Stallman and the Free Software Foundation) would question the wisdom of doing so. Their argument would be that a Free Software product that depends on non-Free tools isn’t really Free Software, since to compile, use, or modify it, you need to make use of a proprietary tool. There is more than one effort to produce a Free Software Java runtime implementation. None of them is “ready for prime time.” It would, in our opinion, be a very good thing for Sun to release their SDK and Java Virtual Machine as Free Software. But so far, they have steadily resisted calls to do so. 2. This is the only time we will refer to it as “GNU/Linux.” See Section 7.3 for the story of why GNU/Linux is the preferred name of some. We understand Stallman and the FSF’s posi- tion, but “Linux” is much easier on the eyes and ears than “GNU/Linux.” And that, not prin- ciple, is how names and words go into the language. For better or for worse, “Linux” is the name of the operating system. 3. As we write this, a very public discussion is taking place between Sun, IBM, and Eric Ray- mond, founder of the Open Source Initiative, about opening Java under some sort of open source license. At this time, no one knows how this will turn out, but it is possible that Java will be Free Software in the future. The fact, however, that two distinct vendors (Sun and IBM) produce ef- fectively interchangeable development and runtime environments reduces some of the risk that you face when you select a platform available only from a single vendor who does not provide source code. So, to put the case firmly: Java is free for use, but it is certainly not Free Software as defined in The GNU Manifesto 4 or the GNU General Public Li- cense.5 This is a political and philosophical issue of interest only to those aforementioned Free Software partisans. For the rest of us, this has no bearing on Java’s technical or business merits. As for us, obviously we like the language or we wouldn’t be writing about it. YOU CAN HELP!This book is part of the Bruce Perens’ Open Source Series. Shortly after this book is published in dead-tree form, it will be on the Web,6 free for use, redis- tribution, and modification in compliance with the terms of the Open Publica- tion License,7 with no options taken. You can immediately create your own version as permitted in that license. Naturally enough, we plan to maintain our “official” version of the online book, so we encourage you to send suggestions, corrections, extensions, com- ments, and ideas to us. Please send any such to javalinux@multitool.net and we will try to keep our little tome up-to-date so it continues to serve the needs of the Java and Linux development communities. ACKNOWLEDGMENTSFirst off, we naturally wish to thank Mark L. Taub, our acquisitions editor at Prentice Hall PTR, for believing in the book and in open publishing as the way to put it out there. We also want to thank Bruce Perens for lending his name and powers of persuasion to open-content publishing through the Prentice Hall PTR Bruce Peren’s Open Source Series. Thanks, too, to Patrick Cash-Peterson 4. http://www.gnu.org/gnu/manifesto.php 5. http://www.gnu.org/copyleft/gpl.php 6. http://www.javalinuxbook.com/ 7. http://www.opencontent.org/openpub/ and Tyrrell Albaugh, who worked as our in-house production contacts, for all the behind-the-scenes work they did, including overseeing the cover. In more direct terms of content, we owe major thanks to Kirk Vogen of IBM Consulting in Minneapolis for his article on using SWT with gcj, and for his kind help in allowing us to use the ideas he first presented in his IBM developerWorks articles. In more direct terms of content, we owe major thanks to: Kirk Vogen of IBM Consulting in Minneapolis for his article on using SWT with gcj, and for his kind help in allowing us to use ideas he first presented in his IBM developerWorks articles; and to Deepak Kumar8 for graciously allow- ing us to base our build.xml file for EJBs off of a version that he wrote. Thanks, too, to Andrew Albing for his help in drawing some of our dia- grams, and to George Logajan and to Andy Miller for sharing their insights on the more intricate details of Swing. We also wish to express our great indebtedness to our technical reviewers, especially Andrew Hayes, Steve Huseth, and Dan Moore. A very large thank- you is also due to Alina Kirsanova whose eye for detail, endless patience, and tenacity, and overall talent with proofing, layout, and more added so much refinement and improvement to the book. We are greatful for all their contri- butions. Any errors or omissions in this text are our fault and certainly not theirs. The book is much stronger for all their efforts. There are likely many more people we ought to thank, especially those at Prentice Hall PTR, whose names and contributions we may never know, but we do know that this was an effort of many more people than just the authors, and we are grateful to them all.
|