diaries, triumphs, failures, and rants
- All
- Animals
- Books
- Chess
- Cigars and the Man-Grill
- Collaboration
- Doctor Who
- General
- Internet
- iPhone
- Java
- LDAP
- mac
- oneLiners
- onThisDay
- slamd
- Star Trek
- Sun
- Travel
Mutability, class creation, singletons, and performance
An illustration of how much execution time can be saved when using immutable singleton classes.[Read More]Posted at 09:59AM Apr 30, 2009 by tgardner in Java | Comments[2]
A type-safe heterogeneous container for parameters that validates the parameter
A type-safe heterogeneous container for parameters with validation.[Read More]Posted at 07:46PM Apr 27, 2009 by tgardner in Java |
Regenerator G1
Some of us might associate G1 with "Regenerator G1" - if you don't know, that was something to do with Godzilla's DNA makeup in one of the great Godzilla movies. It turns out that G1 is "Garbage First", a new Garbage Collector for JDK7.
Technorati Tags: java
Posted at 06:15PM Nov 17, 2008 by tgardner in Java |
FindBugs
Check out FindBugs for locating bugs software defects in your code. Not that there are any, of course.
Posted at 02:46PM May 09, 2008 by tgardner in Java | Comments[0]
Servlet 3.0 (JSR 315) update
Servlet 3.0 (JSR 315) update:
Servlet 3.0 (JSR 315) update
Technorati Tags: java
Posted at 07:23AM May 01, 2008 by tgardner in Java | Comments[0]
Wal-Mart to Phase out HD DVD
Is the beginning of the end for the HD DVD - Blu-ray high-definition DVD wars? On Feb. 15th, 2008, Wal-Mart announced it would phase out HD DVD discs in favor of Blu-ray discs.
What does Java have to do with this development? It's my understanding that Java is used to implement interactive elements in Blu-ray discs.
Technorati Tags: dvd, java, blu-ray, software, video
Posted at 04:30AM Feb 16, 2008 by tgardner in Java | Comments[1]
Prime Twins in Java
From an algorithm by Shimrat, University of Alberta, Alberta, CA, published in "Collected Algorithms of the ACM, Volume II", this is my interpretation of the "PrimeTwins" in Java:
import java.util.Enumeration;
import java.util.Vector;
/**
* Models an event generated by the construction of
* prime twins
*/
class PrimeTwinsEvent {
/**
* creates a PrimeTwinsEvent object.
*
* @param serial the serial number (sequence) of twins
* @param twin1 the lower twin
* @param twin2 the higher twin
*/
public PrimeTwinsEvent(int serial,int twin1,int twin2) {
this.serial = serial;
this.twin1 = twin1;
this.twin2 = twin2;
}
// accessors
public int getSerial() { return this.serial; }
public int getTwin1() { return this.twin1; }
public int getTwin2() { return this.twin2; }
/**
* Prints an String interpretation of
* this object
*/
public String toString() {
return "serial: "
+ serial
+ " twin1: "
+ twin1
+ " twin2: "
+ twin2;
}
private int serial;
private int twin1;
private int twin2;
}
/**
* Classes wishing to be notifed of PrimeTwinsEvents
* must implement this interface
*/
interface PrimeTwinsListener {
public void action(PrimeTwinsEvent event);
}
/**
* From an algorithm by M. Shimrat, University of Alberta, Alberta, Canada,
* and published in the "Collected Algorithms of the ACM, Volume II", a
* PrimeTwins object has a generate method
* that generates successive prime numbers separated by two ("prime twins")
* and notifies listeners, if any, of the prime twins and a sequential
* serial number.
*
* The Java is original, but the algorithm is from the author named above.
*
* @author Terry J. Gardner
*/
public class PrimeTwins {
/**
* add a listener to be notfied. if l is null,
* then no action is taken, and no exception is thrown.
*
* @param l the listener to be notfied
*/
public void addPrimeTwinsListener(PrimeTwinsListener l) {
if(l == null) return;
listeners.add(l);
}
/**
* notify all configured listeners
*
* @param event the event
*/
public void notifyAllListeners(PrimeTwinsEvent event) {
Enumeration e = listeners.elements();
while(e.hasMoreElements()) {
PrimeTwinsListener l = e.nextElement();
l.action(event);
}
}
/**
* generates successive prime twins (primes differing by two)
* and notifies all PrimeTwinsListeners.
*
* @param MAX maximum number of twins
* @throws IllegalArgumentException if max is not positive
*/
public void generate(final int MAX) throws IllegalArgumentException {
if(MAX <= 0) {
throw new IllegalArgumentException("max must be positive");
}
int j,m,previous,current,t;
int[] p = new int[MAX+1];
p[1] = j = 2;
p[2] = previous = 3;
t = 0;
for(current = 5; current < p[j] * p[j]; current += 2) {
m = 1;
int mult = p[m] * p[m];
while(mult <= current) {
if(current == current/mult) return;
if(j < MAX) {
p[++j] = current;
}
if(current == previous + 2) {
++t;
notifyAllListeners(new PrimeTwinsEvent(t,previous,current));
}
previous = current;
++m;
mult = p[m] * p[m];
}
}
}
// listeners
private Vector listeners = new Vector();
}
No-one could claim that Java is perfect, but it is easy to use to realize algorithms.
Posted at 09:22AM Oct 19, 2007 by tgardner in Java | Comments[0]
Thursday Apr 30, 2009