java

Open-source platform for academic collaboration

I'm planning a collaboration platform that will be used by academics from twenty different countries collaborating within the same field of research. Ideally I'd like to base my work on an existing open-source platform that can be extended to meet all the requirements. The final platform has the following requirements: Integrated mess...

Java Profiling: Private Property Getter has Large Base Time

I'm using TPTP to profile some slow running Java code an I came across something interesting. One of my private property getters has a large Base Time value in the Execution Time Analysis results. To be fair, this property is called many many times, but I never would have guessed a property like this would take very long: public class...

Build and Version Numbering for Java Projects (ant, cvs, hudson)

What are current best-practices for systematic build numbering and version number management in Java projects? Specifically: How to manage build numbers systematically in a distributed development environment How to maintain version numbers in source / available to the runtime application How to properly integrate with source reposito...

Any Java caches that can limit memory usage of in-memory cache, not just instance count?

I am looking for a simple in-memory (and in-process) cache for short-term caching of query data (but short-term meaning beyond request/response, i.e. session boundary). EhCache would probably work, but it looks as if it might not offer one thing that I need: limits not on number of objects cached, but (approximate) limit on amount of mem...

AffineTransform: scaling a Shape from its center.

Hi all, I'm trying to scale a rectangle from its center using AffineTransform. I'm sure the solution is obvious but I cannot make it work ! Here is what I've tested so far... import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.geom.AffineTrans...

Wrapper Factory in Java

I may have designed myself into a corner with this problem but I feel like there's a workable known solution to something like this that I'm not seeing. It may well be that I'm completely overcomplicating the problem and skipped over the obvious solution. Any advice would be greatly appreciated. I have a set of entities defined as inter...

Is this a correct implementation of quicksort?

I would like to check if this is a correct implementation of QuickSort, It seems to be doing the job, but Am I missing out anything? public class QuickSort implements Sorter { public void sort(Comparable[] items) { QuickSort(items, 0, items.length - 1); } static void QuickSort(Comparable[] items, int a, int b) { int lo = a; ...

Best practice for caching images read from an inputstream in Java

I have a servlet that acts as a proxy for fetching images by reading the images as bytes off a HttpURLConnection input stream and then writing the bytes to the response output stream. Here's the relevant code snippet: HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setConnectTimeout(CONNECT_TIMEOUT); ...

How to handle duplication between java enum and database table?

It is a quite common situation in our applications that some entity have to be represented by an enum: for example types, categories, status, and things like that. Often, there are conditions or flows in the code that use the values to decide between one action or another, so the values have to be "known" in some way for the applicatio...

Scanner vs. StringTokenizer vs. String.Split

I just learned about Java's Scanner class and now I'm wondering how it compares/competes with the StringTokenizer and String.Split. I know that the StringTokenizer and String.Split only work on Strings, so why would I want to use the Scanner for a String? Is Scanner just intended to be one-stop-shopping for spliting? ...

Java 1.5 Calendar#compareTo() confusion

Ok, I'm officially stumped on this one. I have a GregorianCalendar object that I would like to determine if it is in the past, present, or future. So far, the Calendar#compareTo docs are confusing to me, in that I am getting erratic results. A simple test class will illustrate my problem: import java.util.Calendar; import java.util.Greg...

Narrow a Java field type without making the enclosing class generic?

Is it possible to narrow the type of a field in a Java class without making the containing class itself generic? The generic example would be something like this: abstract class MyClass { //... } interface MyInterface { //... } class MyConcreteClass<T extends MyClass & MyInterface> { private T value; } Is there any way ...

Why does my XPath expression in Java return too many children?

Hello I have the following xml file: <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <config> <a> <b> <param>p1</param> <param>p2</param> </b> </a> </config> and the xpath code to get my node params: Document doc = ...; XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile("/c...

Beep library for Java?

In Java, is there any functions that can emit a (motherboard) beep with a given frequency and duration? In many languages I've worked with, you can; Beeps are useful for indicating certain types of errors, also for easily generating music. The standard way to beep would be either print the BEEP character (\007 or something) or to use To...

Spring validation, how to have PropertyEditor generate specific error message

I'm using Spring for form input and validation. The form controller's command contains the model that's being edited. Some of the model's attributes are a custom type. For example, Person's social security number is a custom SSN type. public class Person { public String getName() {...} public void setName(String name) {...} ...

An easy way (tool?) to compare images pixel for pixel in different formats?

Well I've written a basic lossless jpeg joiner thing in java now but I'd like to compare the files it produces with the original files. I can only compare so much in a hex editor, does anyone know of an easy way, software or java based (preferably software as I dont feel like any more coding for now!) that I can compare two images and p...

Is there a Null outputstream in Java?

I need to specify an OutputStream for an API I'm using, but I don't actually have a need for the output. Does Java have an OutputStream equivalent to > /dev/null ? ...

Reusing a JPanel in NetBeans GUI Designer

This is in NetBeans 6.5, Java 6. I have the following hierarchy in the NetBeans GUI Designer: JFrame JTabbedPane JPanel X <...> JPanel JButton JPanel Y <...> JButton Question: JPanel Y is identical to JPanel X, so I'd like to simply reuse JPanel X in both places, but how do I do this inside ...

Clojure nil vs Java null?

Forgive me if I'm being obtuse, but I'm a little bit confused by the documentation about nil in Clojure. It says: nil has the same value as Java null. Does this mean that they're the same thing or are they different somehow? And does a NullPointerException mean that a Java null was encountered or would I also get this if nil was ...

When did Java get a JIT compiler?

When did Java first get a JIT compiler for production code? ...