Most of the articles that you'll find here are about programming with Java, simply because that's the language that I spend most of my time using. Some of the articles will be applicable to other languages, or programming in general. If an article title doesn't have a link, that means it's in-process; come back in a week or so, and it should be available.
Development Process and Other Vaguely Programming-Related Topics
Git is becoming the source control system of choice for many teams. It has some distinct advantages over centralized SCM tools such as Subversion, particularly for distributed teams and Agile processes. However, it also offers the opportunity for disaster, by giving developers the opportunity to live in their own little world, and will exacerbate any communication problems that a team already has. This article provides tips and techniques for working in a distributed, branchy world.
A blog post that looks at the Git object repository and how it changes when you commit, branch, and merge.
A blog post that I wrote about configuring a Subversion repository for access via SSH. This provides an easy and secure way to access a repository, especially for teams that do not want to manage an Apache server.
If you're using an unsecured wireless network, as in a coffeeshop or conference hall, anyone in range can listen to your network traffic. And if you connect to a site via unsecured HTTP, they can pull your password or access tokens out of that traffic. This article describes how to set up a remote proxy and an encrypted connection to that proxy, meaning that you only have to worry about network sniffers on the Internet backbone.
Amazon Web Services
Moving to the cloud makes logging more difficult: not only do you have multiple instances of the same application, but your virtual machines start up and shut down based on load, and locally-stored logs disappear when that happens. Centralized log aggregation is the answer, and this article shows an implementation based on AWS managed services.
A repository server, such as Sonatype Nexus, is incredibly useful if you use Maven (or any tool that uses Maven repositories, such as Gradle or Leiningen). However, you may have decided not to pursue this route due to the problem of credential management, and instead deploy directly to a bucket on Amazon S3. This article describes how to combine the two: publishing to S3, and then republishing to Nexus via an AWS Lambda process. It's also useful as a starter guide for Lambda.
An example of using Cognito Identity Pools from a web-app written in Java. Covers sign-up, sign-in, and checking the user's authentication token.
General Java Programming
OutOfMemoryError is a frustrating exception: usually it indicates a bug in your code, but sometimes it happens when your have plenty of free space in the Java heap. This article looks at the different causes of OutOfMemoryError, and what you can do about them.
Reference objects allow you to interact with the garbage collector, specifying levels of reachability between "in use" and "gone." This article is based on a presentation that I gave to the Philadelphia Java User's Group in December 2007, providing an overview of the Java object life-cycle and practical examples of when and why you'd use reference objects.
Most Java programs spend their time working with objects on the JVM heap, using getter and setter methods to retrieve or change the data in those objects. A few programs, however, need to do something different. Perhaps they're exchanging data with a program written in C. Or they need to manage large chunks of data without the risk of garbage collection pauses. Or maybe they need efficient random access to files. For all these programs, a java.nio.ByteBuffer provides an alternative to traditional Java objects.
A micro-benchmark is designed to evaluate the performance of a short piece of code, typically in comparison to other code that provides the same functionality. While they can be valuable, they're only valid within the context of a particular execution environment. This article discusses how to compensate for the environment and interpret results.
This article covers techniques to make logging more useful as a debugging tool, and less intrusive to the logical flow of your program code.
Parameterized types, aka Generics, have received a lot of negative press. In this article, I gloss over their bad features, and show how they can make our programs more concise and error-free.
The typesafe enum pattern was made part of the Java language with the 1.5 release. This article looks at programming techniques that exploit the fact that enums are in fact Java objects, not simply named constants.
Java's built-in serialization mechanism has a bad reputation; everybody seems to have a story of serialization gone wrong. But I don't think it deserves that reputation. This article shows how, with a little care, Java serialization can be a useful tool for short-term data persistence.
JUnit and Testing
Reflection proxies, introduced in JDK 1.3, allow you to write a class that implements only part of an interface. This can be very useful with unit tests, when you don't want to go to the time and trouble to implement a fully-functional collaborator, or where you need to stub out classes that aren't in a freely available mock objects package.
Unit tests are often used to support refactoring mainline code, but tests themselves are candidates for refactoring. This article examines techniques for doing just that.
Coverage tools are great for telling you about code that you haven't tested. They're not so good at telling you what tests to write or what mainline code needs to be written. This article looks at the limitations of these tools, and how you can work around them.
JSP, J2EE, and Web Development
A large, monolithic JSP is the same as a large, monolithic method; refactoring can make both easier to manage. This article describes a technique similar to "extract method", in which portions of the JSP are extracted into statically included fragments.
The traditional MVC implementation, where the controller creates a model containing all the data for a page, breaks down with complex pages where the markup changes depending on model data. This article looks at an alternative, in which a JSP tag creates a model that applies only to its body.
This article looks thread management in a Swing GUI. There's more to success than simply spinning up background threads for long-running operations: you need to get the results of these operations back to the user, control the sequencing of not-quite-independent operations, and provide feedback to the user while the operation is running.
Far too many Swing applications follow the anti-pattern of subclassing a JDK container class in order to add components. This article describes an alternative, in which a controller class builds the UI and manages external interaction with its components.
XML output is surprising tricky to get right. Between entity escape rules and incompatible encodings, it's a wonder that there's any well-formed XML in the real world. This article describes some of the pitfalls, shows how to use the APIs built into the JDK, and then presents a simpler alternative.
Describes how to use the JDK's DOM parser, including validation using both DTD and XML Schema.
XPath is a way to select portions of an XML document, modeled on the paths of a filesystem, with the addition of tests on the content and attributes of each node. This article describes how to work with XPath from Java, and work around the pitfalls you'll find there.
Copyright © Keith D Gregory, all rights reserved