Tài liệu More Java Pitfalls: 50 New Time-Saving Solutions and Workarounds docx

476 547 0
Tài liệu More Java Pitfalls: 50 New Time-Saving Solutions and Workarounds docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... nonintuitive application programming interfaces (APIs), and better alternatives Here are some highlights of pitfalls in each area Performance has long been the bane of client-side Java The first book, Java Pitfalls: Time-Saving Solutions and Workarounds to Improve Programs, had numerous pitfalls on performance, and many other books and Web sites have come out on Java performance tuning This part has two pitfalls... focused on the lang, util, io, and GUI packages, whereas this book covers the J2ME, J2SE, and J2EE platforms New Features This book covers the majority of new features like regular expressions, NIO, assertions, JAXR, JAXM, JAX-RPC, and many more Better Coverage The authors followed the “pitfall dissection” model more consistently and thoroughly, producing pitfalls with more detail and analysis In general,... Henry, John and Andy Zhang, Swati Gupta, Chi Vuong, Prabakhar Ramakrishnan, and Yuanlin Shi Special thanks goes to my beloved wife Van and her support and assistance during the writing of this book and the three coauthors of this book who are really progressive thinkers and great guys to hang with Donald Avondolio First, I would like to thank my wife Alicia for all of her patience and understanding while... expectations and the capability of an incomplete API Avoiding Granularity Pitfalls in java. util.logging (Item 5) The new java. util.logging API has some hidden complexities and relationships that affect the level of reporting granularity You must understand the relationship between loggers and handlers to effectively use this API The Wrong Way to Search a DOM (Item 8) With JDK 1.4, the Java platform... } } } Listing 1.1 BadExecJavac .java A run of BadExecJavac produces the following: E:\classes\org\javapitfalls\item1 >java org.javapitfalls.item1.BadExecJavac java. lang.IllegalThreadStateException: process has not exited at java. lang.Win32Process.exitValue(Native Method) at BadExecJavac.main(BadExecJavac .java: 13) Æ The program failed to work because the exitValue() method will throw an IllegalThreadStateException... the directory command is part of the window command interpreter and not a separate executable To run the window command interpreter, you execute either command.com or cmd.exe depending on the windows operating system you are using Listing 1.4 runs a copy of the Windows Command Interpreter and then executes the user-supplied command (like dir) When Runtime.exec() Won’t 01: package org.javapitfalls.item1;... dir command produces: E:\classes\org\javapitfalls\item1 >java org.javapitfalls.item1.GoodWindowsExec “dir * .java Execing cmd.exe /C dir * .java OUTPUT> Volume in drive E has no label OUTPUT> Volume Serial Number is 5C5F-0CC9 OUTPUT> OUTPUT> Directory of E:\classes\com\javaworld\jpitfalls\article2 OUTPUT> OUTPUT>10/23/00 09:01p 805 BadExecBrowser .java OUTPUT>10/22/00 09:35a 770 BadExecBrowser1 .java (some... MediocreExecJavac; it is only a mediocre solution A better solution would empty both the standard error stream and the standard output stream And the best solution would empty these streams simultaneously (this is demonstrated later) 01: 02: 03: 04: 05: 06: 07: 08: 09: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: package org.javapitfalls.item1; import java. util.*; import java. io.*;... System.out.println(“Process exitValue: “ + exitVal); } catch (Throwable t) { t.printStackTrace(); } } } Listing 1.3 MediocreExecJavac .java 7 8 Item 1 A run of MediocreExecJavac produces the following: E:\classes\org\javapitfalls\item1 >java Æ org.javapitfalls.item1.MediocreExecJavac Usage: javac where includes -g Generate all debugging info -g:none Generate no debugging... BadExecWinDir, which when run produces the following: E:\classes\org\javapitfalls\item1 >java org.javapitfalls.item1.BadExecWinDir java. io.IOException: CreateProcess: dir error=2 at java. lang.Win32Process.create(Native Method) at java. lang.Win32Process.(Unknown Source) at java. lang.Runtime.execInternal(Native Method) at BadExecWinDir.main(BadExecWinDir .java: 12) Æ As stated earlier, the error value of 2 means . alt="" More Java ™ Pitfalls 50 New Time-Saving Solutions and Workarounds Michael C. Daconta Kevin T. Smith Donald Avondolio W. Clay Richardson More Java ™ Pitfalls 50. Smith Donald Avondolio W. Clay Richardson More Java ™ Pitfalls 50 New Time-Saving Solutions and Workarounds Publisher: Joe Wikert Executive Editor: Robert

Ngày đăng: 24/01/2014, 14:20

Từ khóa liên quan

Mục lục

  • @Team LiB

  • Cover

  • Contents

  • Introduction

  • Acknowledgments

  • Item 1: When Runtime.exec() Won’t

  • Item 2: NIO Performance and Pitfalls

    • Canonical File Copy

    • Little-Endian Byte Operations

    • Non-Blocking Server IO

    • Item 3: I Prefer Not to Use Properties

    • Item 4: When Information Hiding Hides Too Much

    • Item 7: My Assertions Are Not Gratuitous!

      • How to Use Assertions

      • Item 8: The Wrong Way to Search a DOM

      • Item 9: The Saving-a-DOM Dilemma

      • Item 10: Mouse Button Portability

      • Item 11: Apache Ant and Lifecycle Management

      • Item 12: JUnit: Unit Testing Made Simple

      • Item 13: The Failure to Execute

        • Deploying Java Applications

        • The Java Extension Mechanism

        • Sealed Packages

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan