Advanced Programming for the Java(TM) Platform Training Index Advanced Programming for the Java Platform TM By Calvin Austin and Monica Pawlan November 1999 [CONTENTS] [NEXT>>] [DOWNLOAD] Requires login Early Access Downloads Bug Database Submit a Bug View Database Newsletters Back Issues Subscribe Learning Centers Articles Bookshelf Code Samples New to Java Question of the Week Quizzes Tech Tips Tutorials Forums As an experienced developer on the JavaTM platform, you undoubtedly know how fast moving and comprehensive the platform is Its many application programming interfaces (APIs) provide a wealth of functionality for all aspects of application and system-level programming Real-world developers never use one or two APIs to solve a problem, but bring together key functionality spanning a number of APIs Knowing which APIs you need, which parts of which APIs you need, and how the APIs work together to create the best solution can be a daunting task To help you navigate the Java APIs and fast-track your project development time, this book includes the design, development, test, and deployment phases for an enterprise-worthy auction application While the example application does not cover every possible programming scenario, it explores many common situations and the discussions leave you with a solid methodology for designing and building your own solutions This book is for developers with more than a beginning level of understanding of writing programs in the Java programming language The example application is written with the Java® platform APIs and explained in terms of functional hows and whys, so if you need help installing the Java platform, setting up your environment, or getting your first application to work, you should first read a more introductory book such as Essentials of the Java Programming Language: A Hands-On Guide or The Java Tutorial http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/ (1 of 4) [2001-6-13 8:07:37] Advanced Programming for the Java(TM) Platform Note: This tutorial is available as a book from online book sellers Also, send your comments and thoughts to jdcbook@sun.com Technology Centers SELECT Contents Chapter 1: Matching Project Requirements with Technology Project Requirements Choosing the Software Chapter 2: Auction House Application A Multi-Tiered Application with Enterprise Beans Entity and Session Beans Examining a Container-Managed Bean Container-Managed finder Methods Chapter 3: Data and Transaction Management Bean-Managed Persistence and the JDBCTM Platform Managing Transactions Bean-Managed finder Methods Chapter 4: Distributed Computing Lookup Services Remote Method Invocation (RMI) Common Object Request Broker Architecture (CORBA) JDBCTM Technology Servlets Chapter 5: Java Native Interface (JNI) Technology JNI Example Strings and Arrays http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/ (2 of 4) [2001-6-13 8:07:37] Advanced Programming for the Java(TM) Platform Other Programming Issues Chapter Project Swing: Building a User Interface Components and Data Models Printing API Advanced Printing Chapter 7: Debugging Applets, Applications, and Servlets Collecting Evidence Running Tests and Analyzing Servlet Debugging AWT Event Debugging Analyzing Stack Traces Version Issues Chapter 8: Performance Techniques Improving Performance by Design Connection Pooling Performance Features and Tools Performance Analysis Caching Client/Server Applications Chapter 9: Deploying the Auction Application Java Archive File Format SolarisTM Platform Win32 Platform Chapter 10: More Security Topics Signed Applets Writing a Security Manager Appendix A: Security and Permissions Appendix B: Classes, Methods, and Permissions Appendix C: SecurityManager Methods Epilogue Acknowledgements http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/ (3 of 4) [2001-6-13 8:07:37] Advanced Programming for the Java(TM) Platform Special thanks to experts Isaac Elias, Daniel Liu, and Mark Horwath for their contributions to the advanced examples in the book Reader Feedback Tell us what you think of this book [TOP] [ This page was updated: 4-Jun-2001 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary | Feedback | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2001 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/ (4 of 4) [2001-6-13 8:07:37] Writing Advanced Applications, Chapter 1: Matching Project Requirements with Technology Training Index Writing Advanced Applications Chapter 1: Matching Project Requirements with Technology [] One challenge in writing a book on advanced application development for the JavaTM platform is to find a project small enough to write about, while at the same time, complex enough to warrant advanced programming techniques Requires login Early Access Downloads Bug Database Submit a Bug View Database Newsletters Back Issues Subscribe Learning Centers Articles Bookshelf Code Samples New to Java Question of the Week Quizzes Tech Tips Tutorials The project presented in this book is a web-based auction house The application is initially written for the Enterprise JavaBeansTM platform Later chapters expand the core example described here by adding advanced functionality, improvements, and alternative solutions to some of the things you get for free when you use the Enterprise JavaBeans platform To keep the discussion simple, the example application has only a basic set of transactions for posting and bidding on auction items However, the application scales to handle multiple users, provides a three-tiered transaction-based environment, controls security, and integrates legacy-based systems This chapter covers how to determine project requirements and model the application—important steps that should always come before coding begins Project Requirements and Modeling Choosing the Software In a Rush? This table links you directly to specific topics Forums Topic Section Auction Demonstration Duke's Auction http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/proj.html (1 of 2) [2001-6-13 8:07:50] Writing Advanced Applications, Chapter 1: Matching Project Requirements with Technology Technology Centers Project Requirements SELECT Interview User Base Model the Project Modeling House Identifies Buyers and Sellers House Determines Highest Bidder House Notifies Buyers and Sellers Anyone Searches for an Item Anyone Views Items for Sale Anyone Views Item Details Seller Posts Items for Sale Buyer Bids on Items Activity Diagram Choosing Software JavaTM APIs [TOP] [ This page was updated: 4-Jun-2001 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary | Feedback | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2001 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/proj.html (2 of 2) [2001-6-13 8:07:50] Writing Advanced Applications, Chapter 1: Project Requirements and Modeling Training Index Writing Advanced Applications Chapter Continued: Project Requirements and Modeling [] The first step in determining project requirements is to interview the user base to find out what they want in an online auction This is an important step, and one that cannot be overrated because a solid base of user-oriented information helps you define your key application capabilities Requires login Early Access Downloads Bug Database Submit a Bug View Database Newsletters Back Issues Subscribe Learning Centers Articles Bookshelf Code Samples New to Java Question of the Week Quizzes Tech Tips Tutorials Forums Chapter walks through the application code, explains how the Enterprise JavaBeans platform works, and tells you how to run a live demonstration If you have never seen or used an online auction, here are mockups of the example auction application HTML pages Interview User Base Model the Project Interview User Base For the sake of discussion and to keep things simple, this discussion assumes interviews with the user base found auction house and user requirements, as follows: Auction House Requirements Require buyer and seller information Bill sellers for posting items Record and report the day's transactions User Requirements Bid on or sell an item Search or view items for sale Notify buyer and seller of sale Model the Project http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/proj2.html (1 of 6) [2001-6-13 8:08:07] Writing Advanced Applications, Chapter 1: Project Requirements and Modeling Technology Centers After analyzing the requirements, you can build a use case SELECT diagram for the application to gain a better understanding of the elements needed in the application and how they interact A use case diagram shows the relationships among actors and use cases within the system A use case is a unique function in a system, and an actor is the person or software that performs the action or use case For example, a buyer is the actor that performs the function (use case) of bidding on an auction item, and the seller is the actor that performs the use case of posting an item for auction Not all actors are people, though For example, the software is the actor that determines when an item has closed, finds the highest bidder, and notifies the buyer and seller of the sale The Unified Modeling Language (UML) is the tool of choice for creating use case diagrams The Use Case diagram below uses UML to describe the buyer and seller use cases for the online auction application In UML, systems are grouped into squares, actors are represented by stick figures, use cases are denoted by ovals, and the lines show how actors use the system http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/proj2.html (2 of 6) [2001-6-13 8:08:07] Writing Advanced Applications, Chapter 1: Project Requirements and Modeling The following descriptions further define the project These descriptions are not part of UML, but are a helpful tool in project definition House Identifies Buyers and Sellers An auction application is used by buyers and sellers A buyer needs to know who the seller is to pay him or her, and the seller needs to know who the buyers are to answer product questions and to finalize the sale So, to post or bid on an auction item, buyers and sellers are required to register Registration needs to get the following information from buyers and sellers: User ID and password for buying and selling Email address so highest bidder and seller can communicate when item closes http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/proj2.html (3 of 6) [2001-6-13 8:08:07] Writing Advanced Applications, Chapter 1: Project Requirements and Modeling Credit card information so auction can charge sellers for listing their items Once registered, a user can post or bid on an item for sale House Determines Highest Bidder Nightly, the auction application queries the database to record and report the day's transactions The application find items that have closed and determines the highest bidder House Notifies Buyers and Sellers The auction application uses email to notify the highest bidder and seller of the sale, and debit the seller's account Anyone Searches for an Item Sellers and buyers enter a search string to locate all auction items in the database Anyone Views Items for Sale To popularize the auction and encourage new buyers and sellers, the application allows anyone to view auction items without requiring user ID and password identification To keep things simple, the auction lets anyone view summarized lists of items in the following three ways: All items up for auction New items listed today Items due to close today Anyone Views Item Details The summarized lists link to the following detailed information on each item Detail information on auction items is available to anyone without identification Item Summary Auction Item number Current price Number of bids Date posted for auction Date item closes Seller ID Highest bid Item description http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/proj2.html (4 of 6) [2001-6-13 8:08:07] Writing Advanced Applications, Appendix B: Classes, Methods, & Permissions } ~~~~~~~~~ MulticastSocket( ) checkListen({port}) The access verification code for this method calls checkListen in the following case: if (port == 0) java.net.SocketPermission "localhost:1024-", "listen"; else java.net.SocketPermission "localhost:{port}","listen" java.net.ServerSocket ServerSocket( ) checkListen({port}) The access verification code for this method calls checkListen in the following case: if (port == 0) java.net.SocketPermission "localhost:1024-","listen"; else java.net.SocketPermission "localhost:{port}","listen" ~~~~~~~~~ public Socket accept() protected final void implAccept(Socket s) checkAccept({host}, {port}) java.net.SocketPermission "{host}:{port}", "accept" ~~~~~~~~~ public static synchronized void setSocketFactory( ) checkSetFactory java.lang.RuntimePermission "setFactory" java.net.Socket public static synchronized void setSocketImplFactory( ) checkSetFactory java.lang.RuntimePermission "setFactory" ~~~~~~~~~ http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/appB.html (15 of 20) [2001-6-13 8:14:18] Writing Advanced Applications, Appendix B: Classes, Methods, & Permissions Socket( ) checkConnect({host}, {port}) java.net.SocketPermission "{host}:{port}", "connect" java.net.URL public static synchronized void setURLStreamHandlerFactory( ) checkSetFactory java.lang.RuntimePermission "setFactory" ~~~~~~~~~ URL( ) checkPermission java.net.NetPermission "specifyStreamHandler" java.net.URLConnection public static synchronized void setContentHandlerFactory( ) public static void setFileNameMap( FileNameMap map) checkSetFactory java.lang.RuntimePermission "setFactory" java.net.URLClassLoader URLClassLoader( ) checkCreateClassLoader java.lang.RuntimePermission "createClassLoader" java.rmi.activation.ActivationGroup public static synchronized ActivationGroup createGroup( ) public static synchronized void setSystem( ActivationSystem system) checkSetFactory java.lang.RuntimePermission "setFactory" java.rmi.server.RMISocketFactory public synchronized static void setSocketFactory( ) checkSetFactory java.lang.RuntimePermission "setFactory" java.security.Identity http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/appB.html (16 of 20) [2001-6-13 8:14:18] Writing Advanced Applications, Appendix B: Classes, Methods, & Permissions public void addCertificate( ) checkSecurityAccess("addIdentityCertificate") java.security.SecurityPermission "addIdentityCertificate" ~~~~~~~~~ public void removeCertificate( ) checkSecurityAccess("removeIdentityCertificate") java.security.SecurityPermission "removeIdentityCertificate" ~~~~~~~~~ public void setInfo(String info) checkSecurityAccess("setIdentityInfo") java.security.SecurityPermission "setIdentityInfo" ~~~~~~~~~ public void setPublicKey(PublicKey key) checkSecurityAccess("setIdentityPublicKey") java.security.SecurityPermission "setIdentityPublicKey" ~~~~~~~~~ public String toString( ) checkSecurityAccess("printIdentity") java.security.SecurityPermission "printIdentity" java.security.IdentityScope protected static void setSystemScope() checkSecurityAccess("setSystemScope") java.security.SecurityPermission "setSystemScope" java.security.Permission public void checkGuard(Object object) checkPermission(this) This Permission object is the permission checked java.security.Policy public static Policy getPolicy() checkPermission java.security.SecurityPermission "getPolicy" ~~~~~~~~~ http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/appB.html (17 of 20) [2001-6-13 8:14:18] Writing Advanced Applications, Appendix B: Classes, Methods, & Permissions public static void setPolicy(Policy policy); checkPermission java.security.SecurityPermission "setPolicy" ~~~~~~~~~ java.security.Provider public synchronized void clear() checkSecurityAccess("clearProviderProperties." +{name}) java.security.SecurityPermission "clearProviderProperties.{name}" In this method name is the provider name ~~~~~~~~~ public synchronized Object put(Object key, Object value) checkSecurityAccess("putProviderProperty." +{name}) java.security.SecurityPermission "putProviderProperty.{name}" In this method name is the provider name ~~~~~~~~~ public synchronized Object remove(Object key) checkSecurityAccess("removeProviderProperty." +{name}) java.security.SecurityPermission "removeProviderProperty.{name}" In this method name is the provider name java.security.SecureClassLoader SecureClassLoader( ) checkCreateClassLoader java.lang.RuntimePermission "createClassLoader" java.security.Security public static void getProperty(String key) checkPermission java.security.SecurityPermission "getProperty.{key}" ~~~~~~~~~ public static int addProvider(Provider provider) public static int insertProviderAt( Provider provider, int position); http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/appB.html (18 of 20) [2001-6-13 8:14:18] Writing Advanced Applications, Appendix B: Classes, Methods, & Permissions checkSecurityAccess("insertProvider." +provider.getName()) java.security.SecurityPermission "insertProvider.{name}" ~~~~~~~~~ public static void removeProvider(String name) checkSecurityAccess("removeProvider."+name) java.security.SecurityPermission "removeProvider.{name}" ~~~~~~~~~ public static void setProperty( String key, String datum) checkSecurityAccess("setProperty."+key) java.security.SecurityPermission "setProperty.{key}" java.security.Signer public PrivateKey getPrivateKey() checkSecurityAccess("getSignerPrivateKey") java.security.SecurityPermission "getSignerPrivateKey" ~~~~~~~~~ public final void setKeyPair(KeyPair pair) checkSecurityAccess("setSignerKeypair") java.security.SecurityPermission "setSignerKeypair" java.util.Locale public static synchronized void setDefault( Locale newLocale) checkPermission java.util.PropertyPermission "user.language","write" java.util.zip.ZipFile ZipFile(String name) checkRead java.io.FilePermission "{name}","read" [TOP] [ This page was updated: 4-Jun-2001 ] http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/appB.html (19 of 20) [2001-6-13 8:14:18] Writing Advanced Applications, Appendix B: Classes, Methods, & Permissions Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary | Feedback | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2001 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/appB.html (20 of 20) [2001-6-13 8:14:18] Writing Advanced Applications, Appendix C: Security Manager Methods Training Index Writing Advanced Applications Appendix C: Security Manager Methods [] Requires login Early Access Downloads Bug Database Submit a Bug View Database Newsletters Back Issues Subscribe Learning Centers Articles Bookshelf Code Samples New to Java Question of the Week Quizzes Tech Tips Tutorials Forums This table shows which permissions are checked for by the default implementations of the java.lang.SecurityManager methods Each of the check methods calls the SecurityManager.checkPermission method with the indicated permission, except for the checkConnect and checkRead methods that take a context argument The checkConnect and checkRead methods expect the context to be an AccessControlContext and they call the context's checkPermission method with the specified permission public void checkAccept(String host, int port); java.net.SocketPermission "{host}:{port}", "accept"; public void checkAccess(Thread g); java.lang.RuntimePermission "modifyThread"); public void checkAccess(ThreadGroup g); java.lang.RuntimePermission "modifyThreadGroup"); public void checkAwtEventQueueAccess(); java.awt.AWTPermission "accessEventQueue"; public void checkConnect(String host, int port); if (port == -1) java.net.SocketPermission "{host}","resolve"; else java.net.SocketPermission "{host}:{port}","connect"; public void checkConnect(String host, int port, Object context); if (port == -1) java.net.SocketPermission "{host}","resolve"; else java.net.SocketPermission "{host}:{port}","connect"; public void checkCreateClassLoader(); java.lang.RuntimePermission "createClassLoader"; public void checkDelete(String file); java.io.FilePermission "{file}", "delete"; http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/appC.html (1 of 3) [2001-6-13 8:14:24] Writing Advanced Applications, Appendix C: Security Manager Methods Technology Centers SELECT public void checkExec(String cmd); if (cmd is an absolute path) java.io.FilePermission "{cmd}", "execute"; else java.io.FilePermission "-", "execute"; public void checkExit(int status); java.lang.RuntimePermission "exitVM"); public void checkLink(String lib); java.lang.RuntimePermission "loadLibrary.{lib}"; public void checkListen(int port); if (port == 0) java.net.SocketPermission "localhost:1024-","listen"; else java.net.SocketPermission "localhost:{port}","listen"; public void checkMemberAccess(Class clazz, int which); if (which != Member.PUBLIC) { if (currentClassLoader() != clazz.getClassLoader()) { checkPermission( new java.lang.RuntimePermission( "accessDeclaredMembers")); } } public void checkMulticast(InetAddress maddr); java.net.SocketPermission( maddr.getHostAddress(),"accept,connect"); public void checkMulticast(InetAddress maddr, byte ttl); java.net.SocketPermission( maddr.getHostAddress(),"accept,connect"); public void checkPackageAccess(String pkg); java.lang.RuntimePermission "accessClassInPackage.{pkg}"; public void checkPackageDefinition(String pkg); java.lang.RuntimePermission "defineClassInPackage.{pkg}"; public void checkPrintJobAccess(); java.lang.RuntimePermission "queuePrintJob"; public void checkPropertiesAccess(); java.util.PropertyPermission "*", "read,write"; public void checkPropertyAccess(String key); java.util.PropertyPermission "{key}", "read,write"; public void checkRead(FileDescriptor fd); java.lang.RuntimePermission "readFileDescriptor"; public void checkRead(String file); java.io.FilePermission "{file}", "read"; public void checkRead(String file, Object context); java.io.FilePermission "{file}", "read"; public void checkSecurityAccess(String action); http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/appC.html (2 of 3) [2001-6-13 8:14:24] Writing Advanced Applications, Appendix C: Security Manager Methods java.security.SecurityPermission "{action}"; public void checkSetFactory(); java.lang.RuntimePermission "setFactory"; public void checkSystemClipboardAccess(); java.awt.AWTPermission "accessClipboard"; public boolean checkTopLevelWindow(Object window); java.awt.AWTPermission "showWindowWithoutWarningBanner"; public void checkWrite(FileDescriptor fd); java.lang.RuntimePermission "writeFileDescriptor"; public void checkWrite(String file); java.io.FilePermission "{file}", "write"; public SecurityManager(); java.lang.RuntimePermission "createSecurityManager"; [TOP] [ This page was updated: 4-Jun-2001 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary | Feedback | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2001 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/appC.html (3 of 3) [2001-6-13 8:14:24] http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/end.html Training Index Writing Advanced Applications Epilogue [