java

How do I perform a Unit Test using threads?

Executive Summary: When assertion errors are thrown in the threads, the unit test doesn't die. This makes sense, since one thread shouldn't be allowed to crash another thread. The question is how do I either 1) make the whole test fail when the first of the helper threads crashes or 2) loop through and determine the state of each thread ...

Why doesn't this generic interface stack work?

I have a bunch of generic interfaces and classes public interface IElement { // omited } class Element implements IElement { // omited } public interface IElementList<E extends IElement> extends Iterable { public Iterator<E> iterator(); } class ElementList implements IElementList<Element> { public Iterator<Element> iterator(...

Static members need special synchronization blocks?

I have a class which looks something like this: public class Test { private static final Object someObject = new Object(); public void doSomething() { synchronized (someObject) { System.out.println(someObject.toString()); } } } Can I consider the object to be synchronized, or is there a problem since it is a static member? Edi...

How to inject a Jakarta enums in a Spring application context ?

I have a class which constructor takes a Jakarta enums. I'm trying to find how I can easily inject it via an Spring XML aplicationContext. For example : The enum : public class MyEnum extends org.apache.commons.lang.enums.Enum { public static final MyEnum MY_FIRST_VALUE = new MyEnum("MyFirstValue"); public static final MyEnum ...

Java ActiveMQ client fails to receive messages

I am trying to implement performance testing on ActiveMQ, so have setup a basic producer and consumer to send and receive messages across a queue. I have created a producer with no problems, getting it to write a specific number of messages to the queue: for(int i = 0; i < numberOfMessages; i++){ try{ String messag...

Best way to define true, false, unset state

If you have a situation where you need to know where a boolean value wasn't set (for example if that unset value should inherit from a parent value) the Java boolean primitive (and the equivalent in other languages) is clearly not adequate. What's the best practice to achieve this? Define a new simple class that is capable of expressin...

Java post-mortem debugging ?

Is it possible to have a post-mortem ( or post-exception ) debugging session in Java ? What would the workarounds be ( if there isn't a solution for this already ) ? ...

java - determining if a file is a link

Title says it all. How do you do it, or is it even possible? I suppose you could fiddle with getCanonicalWhatever and the original path, but that's messy and I don't like it. Please include a definitive reason if you suggest it. ...

JSF initialize application-scope bean when context initialized

I'm building a JSF+Facelets web app, one piece of which is a method that scans a directory every so often and indexes any changes. This method is part of a bean which is in application scope. I have built a subclass of TimerTask to call the method every X milliseconds. My problem is getting the bean initialized. I can reference the b...

java.lang.UnsupportedOperationException in JPA transaction

I'm pretty sure that I'm not understanding something about JPA (I'm using OpenJPA) and it's causing this problem. I want to make a copy of a Job entity. @Entity @Table(name="Job") public class Job implements Serializable { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private int id; @ManyToOne private Job ...

Java Beans: What am I missing?

I'm wondering if I'm missing something about Java Beans. I like my objects to do as much initialization in the constructor as possible and have a minimum number of mutators. Beans seem to go directly against this and generally feel clunky. What capabilities am I missing out on by not building my objects as Beans? ...

Java printing directly to a Postscript network printer

I've got Postscript code/data (?) in memory (in a Java Tomcat webapp) that I'd like to send directly to a networked PS printer. Is there an easy way (i.e. just popping open a port and sending the text) to print this, bypassing all of the O/S-specific drivers and stuff (and hopefully not even requiring extra jars)? A link to example cod...

Is there a more elegant way to convert an XML Document to a String in Java than this code?

Here is the code currently used. public String getStringFromDoc(org.w3c.dom.Document doc) { try { DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.ne...

How do I extract a tar file in Java?

How do I extract a tar (or tar.gz, or tar.bz2) file in Java? ...

Develop app to run natively or go cross platform?

What's your opinion on whether one should write an application for a specific platform or use a cross platform approach and reach more potential clients? It would be a GUI based application and I'm thinking of using Java. Most of the applications that I've used built on Java don't run as smooth as the native applications on the respect...

Learning C# from java POV

What books would you guys recommend if one has been a java developer for years and is now trying to take the c#/asp.net route? ...

Why null cast?

I saw this piece of code somewhere and wondered: when and why would somebody do the following: doSomething( (MyClass) null ); Have you ever done this? Could you please share your experience? ...

Which programming language to learn now?

Possible Duplicate: Which Programming Language Should I Learn? So I recently just finished a year of Java in my Computer Science class, and want to further pursue programming. I was not much thrilled about Java, I liked the OOP part but disliked its execution speed. I was thinking C++ but I keep hearing people complain (?) ab...

Do you "final"ize local variables and method parameters in Java?

In Java, you can qualify local variables and method parameters with the final keyword. public static void foo(final int x) { final String qwerty = "bar"; } Doing so results in not being able to reassign x and qwerty in the body of the method. This practice nudges your code in the direction of immutability which is generally consid...

Is there a good NumPy clone for Jython?

I'm a relatively new convert to Python. I've written some code to grab/graph data from various sources to automate some weekly reports and forecasts. I've been intrigued by the Jython concept, and would like to port some Python code that I've written to Jython. In order to do this quickly, I need a NumPy clone for Jython (or Java). I...