Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button


Topic: Best Practices

Java best practices includes all aspects of Java software design, performance, and optimization. Any of these use Java threads, design patterns and more.

O'Reilly Network articles about this topic:

Reshaping IT Project Delivery Through Extreme Prototyping (ONJava.com)
Why should the benefits of short iterations and a tight feedback loop be limited to the agile methodologies like Extreme Programming? In this article, Satya Komatineni explores the idea of Extreme Prototyping--the staged, ongoing development of a web app prototype that emerges into a final product. He shows how it can eliminate common design and project management errors.

Implementing Mutual Exclusion for AJAX (ONJava.com)
AJAX programmers who come from the Java world can, or at least should, be concerned with JavaScript's non-support for safely managing data structures in a concurrent fashion. If one thread is changing the DOM while another is reading it, problems are likely. Java developers can attack this with tools from the synchronized keyword and the old Object wait()/release() to the modern java.util.concurrent package introduced in J2SE 5.0. Bruce Wallace addresses the problem by introducing protection for critical blocks of JavaScript code.

An Exception Handling Framework for J2EE Applications (ONJava.com)
One common hassle in J2EE development is exception handling: many apps devolve into a mess of inconsistent and unreliable handling of errors. In this article, ShriKant Vashishtha introduces a strategy for predictably collecting your exception handling in one place.

Taking JUnit Out of the Box (ONJava.com)
JUnit is practically ubiquitous among Java developers as a way to test code, but it's somewhat limited by the fact that it's only meant to run in one JVM on one box, hampering its usefulness when developing distributed applications. In this article, Amir Shevat shows how the open source JUnit extension Pisces helps JUnit overcome this limitation.

An Ant Modular Build Environment for Enterprise Applications (ONJava.com)
Most Java developers already use Ant for their builds, but are you getting everything you could out of this tool? With a complex enterprise application, in which classes may be used in several tiers, it's important to control where the code lives and how it gets built, so you can build .jars with just the code needed for each tier. Les Hazlewood shows how this approach leads to faster builds and downloads, and even catches errant dependencies.

Constructing Services with J2EE (ONJava.com)
Web services are a popular means of deploying service-oriented applications, and the standards in J2EE 1.4 make it easier to develop services that are portable and interoperable. Debu Panda shows you how, and takes a look at how things will get easier in J2EE 5.0.

Java Component Development: A Conceptual Framework (ONJava.com)
In general terms, a component is one or more classes with an external API that satisfy some requirement. But how do you build components that are really practical--that handle configuration changes or third-party integration well? Palash Ghosh has some ideas about the concepts behind components.

Mock Objects in Unit Tests (ONJava.com)
Unit testing your code against a service or process that's either too expensive (commercial databases) or just not done yet is something you can deal with by simulating the other piece with a mock object. EasyMock can suffice in some cases, but it can only create mock objects for interfaces. Mocquer, based on the Dunamis project, can create mocks for classes, too. Lu Jian shows how it works.

Advertisement

Towards Bug-Free Code (ONJava.com)
Test-driven development sometimes sounds better than it turns out to be. Early decisions to tightly couple functional parts of your system can make it a lot less amenable to testing than it ought to be. As Ashwin Jayaprakash shows, J2SE 5.0's generics make working with abstract classes and interfaces easier than it used to be, which encourages loose coupling and facilitates testing.

The Singleton as a Network Management Pattern (ONJava.com)
Patterns aren't for the local memory space any more. As Stephen B. Morris points out, patterns are also useful for network management problems. In this installment, he shows how the Singleton pattern can be used to manage access to functionality in a networked system.

Using the ASM Toolkit for Bytecode Manipulation (ONJava.com)
ASM is making inroads in the Java bytecode manipulation community--it's used by Groovy, AspectWerkz, BeanShell, and others--because of its light weight and good performance. Eugene Kuleshov shows how to get started with ASM.

Unit Test Your Struts Application (ONJava.com)
Consistent unit testing is an essential part of development, but web applications aren't necessarily well-suited to unit testing--how to you validate the "correctness" of a returned stream of text or HTML? Lu Jian has an answer in the form of StrutsUT, a Cactus-based library for unit testing Struts web apps.

Understanding the Interplay Between Utility Classes and Static Initialization (ONJava.com)
Using static initializers is a common practice for setting up fields that need to be accessed from distantly related classes. However, without a firm understanding of how statics work with relation to subclassing, and a careful establishment of initialization expectations, difficult problems can arise. Satya Komatineni offers a new pattern that can reduce these problems.

Java Patterns and Network Management (ONJava.com)
Patterns are often used to solve common problems in software developments, but this approach is also applicable to deploying and managing networks. Stephen B. Morris shows how this approach can help solve problems in this complex field.

Better, Faster, Lighter Programming in .NET and Java (ONJava.com)
In Better, Faster, Lighter Java, authors Bruce Tate and Justin Gehtland lay out five basic principles to combat the "bloat" that has built up over time in modern Java programming. In this article, Justin shows how programmers developing .NET apps can apply the same principles, and along the way, cultivate still more ideas that make programming more simple and fun again.

Designing J2EE Applications for Real-Life Clustered Environments (ONJava.com)
What works on a single server can crash and burn in a cluster. In this article, the authors draw from their practical experience to list and discuss some critical considerations when building J2EE applications so that they can be deployed in a clustered environment without requiring any code changes.

Code Improvement Through Cyclomatic Complexity (ONJava.com)
Overly complex code is dangerous, hard to maintain if not already buggy. But what do we mean by "complex"? The metric of cyclomatic complexity helps show where the most complex code is. As Andrew Glover illustrates, finding the complex code is also the first step to refactoring it.

Nested Classes, Part 1 (ONJava.com)
One aspect of the Java language that is not widely understood is the concept of nested classes. But because you're bound to encounter one or more of them in other people's code, it's important to understand how they work. Chapter six of Hardcore Java covers the various nested classes. In this first excerpt in a three-part series of excerpts from the chapter, author Robert Simmons covers the first of the three basic categories of nested classes: inner classes.

Do As They Need, Not As They Say (ONJava.com)
Replacing an existing system with a new and improved one should make end users happy, but that's often not the case. What goes wrong? Jeff Lowery calls on his experience to look at the process of developing new systems and why developers need to be advocates for the end users.

Seven Low-Cost Ways to Improve Legacy Code (ONJava.com)
Robert Simmons, Jr. presents seven techniques developed and used in his consulting work that are designed to improve legacy code, without a major investment in man hours or cash. Robert is the author of the recently released Hardcore Java.

Migrating to Velocity (ONJava.com)
Velocity offers a compelling way to develop web applications, but converting an existing JSP-based project is no simple task. Jason Briggs shows how he used Velocity servlets to ease the transition.

Lazy Loading with Aspects (ONJava.com)
AspectJ allows the Java community to apply modular crosscutting concerns, or aspects, to their applications. Lazy loading is one such crosscutting concern that can benefit from an Aspect-Oriented, rather than traditional Object-Oriented, implementation approach. This article presents an implementation of lazy loading using AspectJ.

Approaches to Mocking (ONJava.com)
Conceptually, you know what mock objects are, but practically speaking, how do you create and use them? Do you write mocks by hand or generate them automatically? Simon Stewart considers these possibilities and others, such as AOP-based mocking.

Managing Your Dependencies with JDepend (ONJava.com)
Attributes like scalability and maintainability are qualitative in nature and hard to quantify, even hard to know until your code fails. But by analyzing dependencies between packages, JDepend gives you a way to measure how well-architected your code is.

Top 15 Ant Best Practices (ONJava.com)
Nearly every open source Java project now uses Ant. The widespread use of Ant in these projects has naturally led to an increased need for a set of well-established best practices. Eric M. Burke, coauthor of Java Extreme Programming Cookbook and Ant: The Definitive Guide, offers his 15 best practices for using Ant and for writing well-crafted Ant buildfiles. These tips were inspired by his own mistakes on previous projects, or from horror stories relayed to him from other developers.

Best Practices for Exception Handling (ONJava.com)
Java's concept of exceptions and how they're used has led to controversy and, in some cases, bad programming practices. Gunjan Doshi seeks to lay down some best practices for using exceptions in Java.

Developing with Maven (ONJava.com)
By knowing what developers want in a build tool, Maven hopes to unseat Ant as the favorite build tool of Java developers. Rob Herbst looks at Maven's most compelling features.

Managing Complexity: Keeping a Large Java Project on Track (ONJava.com)
Delivering a software project successfully requires much more than just writing good code. Issue tracking, bug fixing, packaging, deployment, and testing all help solve your customer's actual problem. Tom Copeland explains Dashboard, the continual integration infrastructure behind DARPA's UltraLog, a large Java project distributed among several vendors.

Memoization in Java Using Dynamic Proxy Classes (ONJava.com)
Memoization, or caching previously computed values of functions, can speed up certain classes of problems. Java 1.3's dynamic proxy classes make it possible to write generic memoization routines. Tom White explores this technique and explains when and how it can improve your performance.

A Java Programmer Looks at C# Delegates (ONJava.com)
While C# has taken many features from Java, it's added other interesting ideas. One is delegation; C# treats methods as first-class objects. Steven Lewis and Wilhelm Fitzpatrick explain delegates and provide a working Java implementation.

Black Box Web Testing with HttpUnit (ONJava.com)
No matter how much unit testing you do, how do you know your web site meets your customers' real needs? Giora Katz-Lichtenstein introduces HttpUnit, a Java framework for Black Box web testing, and demonstrates how it can improve your sites.

Surviving Abrupt Shutdown (ONJava.com)
Sometimes letting users save their data isn't enough--you want to make prevent data loss. Java provides an elegant way for programmers to execute code in the middle of the shutdown process, thus making sure your clean-up code is always executed. In this article, Budi Kurniawan shows how to use a shutdown hook to guarantee that clean-up code is always run, regardless of how the user terminates the application.

Java Swing: Menus and Toolbars, Part 7 (ONJava.com)
In the final excerpt from Java Swing, learn how to use toolbars.

Java Swing: Menus and Toolbars, Part 6 (ONJava.com)
In this sixth excerpt from Java Swing, learn how to use complex menu items like radio buttons and checkbox menus.

Advanced Text Indexing with Lucene (ONJava.com)
Lucene is a free text-indexing and -searching API written in Java. In the second of a series of articles, Otis Gospodnetic explains the structure of Lucene indices and introduces several advanced techniques to improve the performance of text-indexing applications.

Java Swing: Menus and Toolbars, Part 5 (ONJava.com)
In this fifth excerpt from Java Swing, learn how to attach menus to menu bars with the JMenu class.

Static Analysis with PMD (ONJava.com)
Code review is good, but who has time to run through every line of a large project every night? If only that were automatable. Thankfully, there's PMD. Tom Copeland demonstrates how to analyze your Java code for deleterious constructs and how to add rules to catch more.

Java Swing: Menus and Toolbars, Part 4 (ONJava.com)
In the fourth excerpt from Java Swing, learn how to create context-sensitive menus with the JPopupMenu class.

Java Swing: Menus and Toolbars, Part 3 (ONJava.com)
In this third excerpt from Java Swing, learn how to add strings and icons to menus with the JMenuItem class.

Java Swing: Menus and Toolbars, Part 2 (ONJava.com)
In this excerpt from Java Swing, 2nd Edition, learn about menu selections and the JMenuBar class.

Java Swing: Menus and Toolbars, Part 1 (ONJava.com)
In this excerpt from Java Swing, 2nd Edition, learn how to use Swing menus.

Servlet Best Practices, Part 3 (ONJava.com)
In this final excerpt on servlets from Java Enterprise Best Practices, we present how to effectively send files for download. Getting it right across Web browsers takes a bit of work, but with this tip you'll have it right in no time.

Servlet Best Practices, Part 2 (ONJava.com)
In part two of three in this series of book excerpts on servlet best practices from Java Enterprise Best Practices, learn about caching with servlets.

Servlet Best Practices, Part 1 (ONJava.com)
Servlets have dominated the recent server-side Java landscape and have become the standard way to interface Java to the Web. This chapter, the first of three book excerpts from Java Enterprise Best Practices, discusses effective servlet-based development and deployment.

Enhance Collection Performance with this Treasure Trove (ONJava.com)
Trove is an open source Collection implementations. You can use these instead of the standard collections to get increased performance.

J2EE Design Patterns: CMP-to-BMP Pattern (ONJava.com)
In EJB 2.0, Sun delivered a revamped container-based persistence model. This article explains how to write a CMP in EJB 2.0 and how to go from CMP to BMP when needed.

Micro-Tuning Step-by-Step (ONJava.com)
Java Performance Tuning author Jack Shirazi offers a step-by-step guide for micro-tuning your Java methods.

Java API Map (ONJava.com)
Is the world of Java getting a little unweildy for you? Use our Java API map and directory to track all significant Java platforms and respective Java APIs. Includes the JAX Pack and MIDlets.

Business Logic, Part 2 (ONJava.com)
In Part 2 of our excerpt from Chapter 8 of Building Java Enterprise Applications, Vol I: Architecture, Brett McLaughlin builds a UserManager component, and illustrates why managers are a good thing.

The Java Platform (ONJava.com)
In this excerpt from O'Reilly & Associates' Java in a Nutshell, 4th Edition, David Flanagan shows you a number of the Java 2SE platform packages, using examples of the most useful classes in these packages.

Expiring Data with Hashbelts (ONJava.com)
The final installment in this series on automatic data expiration shows that hashbelts are a new data structure that satisfies all of the requirements for data expiration.

Java Programming with Oracle JDBC: Performance (ONJava.com)
When it comes to JDBC performance issues, there are two major factors to consider: performance of the database structure and the SQL statements used against it and relative efficiency of the different ways you can use the JDBC interfaces to manipulate a database. This excerpt from Java Programming with Oracle JDBC explores these.

The Hashbelt Data Structure (ONJava.com)
William Grosso continues his Data Expiration series by focusing on the 'hashbelt' algorithm, which is a generic data structure adaptable to a wide variety of time-sensitive data problems.

J2EE Design Patterns (ONJava.com)
Design patterns are a way of bringing clarity to a system architecture; they allow for the possibility of better systems being built. This article covers how to identify and use design patterns in J2EE apps, specifically for the presentation layer.

Tuning JDBC: Measuring JDBC performance (ONJava.com)
Many Java apps are dependent on Java Database Connectivity, but how do you measure JDBC's performance, and which subsystems need optimizing?

Java RMI: Serialization (ONJava.com)
In this excerpt from Java RMI, William Grosso drills down on the serialization mechanism; by the end of it, you will understand exactly how serialization works and how to use it efficiently within your applications.

Generics and Method Objects (ONJava.com)
O'Reilly's Java RMI author William Grosso introduces you to the new Generics Specification and rebuilds his command object framework using it.

Seamlessly Caching Stubs for Improved Performance (ONJava.com)
In Part 2 of this RMI series, William Grosso addresses a common problem with RMI apps -- too many remote method calls to a naming service. In this article he extends the framework introduced in Part 1 to provide seamless caching of stubs.

Faster List Iteration with RandomAccess Interface (ONJava.com)
Merlin's new RandomAccess interface identifies whether a java.util.List class has fast random access. This article tests the impact of RandomAccess in several different loops and shows you how to take full advantage of this interface.

Load Balancing Web Applications (ONJava.com)
This overview of load-balancing schemes compares the relative advantages of DNS round robin, hardware load balancers, and Web server proxies.

Multiprocess JVMs (ONJava.com)
Combining multiple Java processes into a single JVM reduces memory overhead, says Jack Shirazi, author of Java Performance Tuning.

Catching OutOfMemoryErrors to Preserve Monitoring and Server Processes (ONJava.com)
Why would you want to catch an OutOfMemoryError? In some cases, doing so can help you carry on some monitoring and server processes beyond such a fatal error.

Embedded Java (ONJava.com)
Java's strong appeal for embedded applications is sometimes offset by concerns about its speed and its memory requirements. However, Vincent shows you techniques to use for boosting Java performance and reduce memory needs.

The WeakHashMap Class (ONJava.com)
WeakHashMap is a type of Map which differs from other Maps in more than just having a different implementation. WeakHashMap uses weak references to hold its keys, making it one of the few classes able to respond to the fluctuating memory requirements of the JVM.

The Performance of Java's Lists (ONJava.com)
Jack Shirazi examines the performance issues for the three primary java.util.List implementations: Vector, ArrayList and LinkedList.

Java Internationalization and Localization (ONJava.com)
Jaric Sng explains Internationalization and the different issues encountered for displaying Chinese, Japanese and Korean characters on Navigator and IE.

Learning Polymorphism and Object Serialization (ONJava.com)
Learn to use polymorphism and object serialization by playing with Brainy Draw.

Performance Planning for Managers (ONJava.com)
Jack Shirazi presents a ten-point plan for managing adequate Java application performance.

Optimizing Hash Functions For a Perfect Map (ONJava.com)
O'Reilly's Java Performance and Tuning author Jack Shirazi describes and tests an implementation of a perfect hash map using a perfect hash function.

UML Modeling for Java with Rhapsody (ONJava.com)
Rhapsody in J generates Java code from UML diagrams, allowing programmers to focus on Java design rather than writing code in Java.

Java Performance: Efficiently Formatting Doubles (ONJava.com)
O'Reilly's Java Performance Tuning author, Jack Shirazi, examines the formatting of doubles and shows that the conversion of numbers with formatting can be faster than the original unformatted conversion.


Other documents about this topic:

Below are other references available on the web for this topic. Since other sites may change their links, please if you find any that may need to be updated.

Java Performance and Scalability Forum
This is a useful forum for learning and applying various Java performance issues, fine tuning and scalability. Also, see Jack Shirazi's series of Java performance articles on ONJava.com [Source: theserverside.com]

Sybase White Papers/Tech Papers
Sybase White Papers, containing info on projects related to Java, JDBC, SQLJ and development for their Web Application Server. [Source: Sybase]

EJB Observer Pattern
This article explains how to implement the observer pattern in a suite of integrated EJB apps. The suite has a shared repository and each EJB application has it own repository. Every application in the suite runs on a separate host. Each application needs to observe changes in the shared repository as they occur -- and within the transaction in which they occur. If a proposed change to the shared data is unacceptable to any given application then the transaction must be aborted before the change is made permanent. [Source: theserverside.com]

J2EE Component Patterns Tutorial
Liou presents J2EE component design patterns in a tutorial session at the 2001 O'Reilly Enterprise Java Conference. [Source: O'Reilly & Associates]

Multithreaded Swing Applications
Swing components are not inherently thread safe, and as a general rule, after Swing components have been made visible on the screen, you can only safely modify their data from the event thread. If you modify Swing component data from any thread other than the event dispatching thread, you must take precautions to ensure data integrity. An exception to this rule is the setText method on a JTextComponent or any of its subclasses, or any Swing component method whose documentation explicitly states it is thread safe. Sometimes, you cannot avoid modifying Swing component data from outside the event dispatching thread after it has been made visible. An example is spawning a thread to handle a long operation such as reading or writing a large file over the net. The advantage to spawning a new thread is that the user interface is made available to the user for other operations during the long file operation. The spawned thread is a new thread, and therefore, not on the event dispatching thread even if it is spawned by an event dispatching thread method. This article explains how to use the InvokeLater method and synchronize keyword to ensure data integrity when modifying data in Swing components. If you are new to multi-threaded programming, see Creating a Threaded Slide Show Applet for an introduction to the threaded applications. [Source: java.sun.com]