background preloader

Java - General

Facebook Twitter


Defensive Programming: Being Just-Enough Paranoid. Hey, let’s be careful out there.Sergeant Esterhaus, daily briefing to the force of Hill Street Blues When developers run into an unexpected bug and can’t fix it, they’ll “add some defensive code” to make the code safer and to make it easier to find the problem.

Defensive Programming: Being Just-Enough Paranoid

Sometimes just doing this will make the problem go away. They’ll tighten up data validation – making sure to check input and output fields and return values. Review and improve error handling – maybe add some checking around “impossible” conditions. Add some helpful logging and diagnostics. Expect the Unexpected The whole point of defensive programming is guarding against errors you don’t expect.Steve McConnell, Code Complete The few basic rules of defensive programming are explained in a short chapter in Steve McConnell’s classic book on programming, Code Complete:Protect your code from invalid data coming from “outside”, wherever you decide “outside” is.

I would add a couple of other rules. Don't Waste Time on Code Reviews. Less than half of development teams do code reviews and the other half are probably not getting as much out of code reviews as they should.

Don't Waste Time on Code Reviews

Here’s how to not waste time on code reviews. Keep it Simple Many people still think of code reviews as expensive formal code inspection meetings, with lots of prep work required before a room full of reviewers can slowly walk through the code together around a table with the help of a moderator and a secretary. Lots of hassles and delays and paperwork. But you don’t have to do code reviews this way – and you shouldn’t. There are several recent studies which prove that setting up and holding formal code review meetings add to development delays and costs without adding value.

Design Patterns. In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Uses of Design Patterns Design patterns can speed up the development process by providing tested, proven development paradigms.

Effective software design requires considering issues that may not become visible until later in the implementation. Often, people only understand how to apply certain software design techniques to certain problems. In addition, patterns allow developers to communicate using well-known, well understood names for software interactions. FriendPackages - APIDesign. From APIDesign Common object oriented languages offer some kind of encapsulation, which often takes form of having public, protected and private access modifiers.

FriendPackages - APIDesign

Indeed, designers soon found that this is not enough and as such C++ has friend keyword and Java adds additional package private access type. The problem with the Java approach is that it generally dictates the files layout of your friends. Their sources need to be placed in the same directory. Many people do not like that, as this mixes the classes representing the API with the classes that provide their implementation. Java Generics FAQs - Frequently Asked Questions. All text and content found at URLs starting with (collectively, "the Java Generics FAQ") are the sole property of Angelika Langer.

Java Generics FAQs - Frequently Asked Questions

Copyright @ 2004-2019 by Angelika Langer . All rights reserved. Except as specifically granted below, you may not modify, copy, publish, sell, display, transmit (in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise), adapt, distribute, store in a retrieval system, create derivative works, or in any other way use or exploit the contents of the Java Generics FAQ, without the prior consent of the author. Java theory and practice: Hashing it out. While the Java language does not provide direct support for associative arrays -- arrays that can take any object as an index -- the presence of the hashCode() method in the root Object class clearly anticipates the ubiquitous use of HashMap (and its predecessor, Hashtable).

Java theory and practice: Hashing it out

Under ideal conditions, hash-based containers offer both efficient insertion and efficient retrieval; supporting hashing directly in the object model facilitates the development and use of hash-based containers. Defining equality The Object class has two methods for making inferences about an object's identity: equals() and hashCode(). In general, if you override one of these methods, you must override both, as there are important relationships between them that must be maintained. In particular, if two objects are equal according to the equals() method, they must have the same hashCode() value (although the reverse is not generally true). public boolean equals(Object obj) { return (this == obj); }

Ropes For Java. The Java HotSpot Performance Engine Architecture. Table of Contents Back to Top Chapter 1.

The Java HotSpot Performance Engine Architecture

Introduction and Overview The Java HotSpot™ virtual machine implementation (Java HotSpot™ VM) is Sun Microsystems, Inc.'s high-performance VM for the Java platform. The Java platform has become a mainstream vehicle for software development and deployment. The Java HotSpot VM builds upon Java technology's cross-platform support and robust security model with new features and capabilities for scalability, quality, and performance.