java

Please share your experiences of DWR 3.0 M1 RC2 ?

Hi, I am planning to use DWR 3.0 M1 RC2 release candidate for my application. The primary reason of using this version is that it nicely integrates with Spring 2.5 framework and requires least possible level of configuration ! If you have using particularly this version of DWR, I would appreciate if you can share your experiences (bene...

Rotation matrix for direction vector

I've been playing with some algorithms on the internet for a while and I can't seem to get them to work, so I'm tossing the question out here; I am attempting to render a velocity vector line from a point. Drawing the line isn't difficult: just insert a line with length velocity.length into the graph. This puts the line centered at the ...

What is the best way to detect whether an application is launched by Webstart

As it was made clear in my recent question, Swing applications need to explicitly call System.exit() when they are ran using the Sun Webstart launcher (at least as of Java SE 6). I want to restrict this hack as much as possible and I am looking for a reliable way to detect whether the application is running under Webstart. Right now I a...

spring + tomcat + axis2 == jax-ws web service ?

I'm looking for a straightforward example / tutorial for implementing a JAX-WS (soap1.1 and soap1.2) web service based on wsdl definition using spring, axis2 and tomcat. hint anyone ? -- Yonatan ...

Log4j, configuring a Web App to use a relative path.

I have a java webapp that has to be deployed on either Win or Linux machines. I now want to add log4j for logging and I'd like to use a relative path for the log file as I don't want to change the file path on every deployment. The container will most likely be Tomcat but not necessarily. What's the best way of doing this? ...

What's the best way to get the last inserted id using sqlite from Java?

What's the best way to get the last inserted id using sqlite from Java? Google is giving me different answers--some say select the last-insert-rowid; others say call statement.getGeneratedKeys(). What's the best route to take? (I just want to return the id, not use it for other inserts or anything.) ...

Big O Notation Homework--Code Fragment Algorithm Analysis?

For homework, I was given the following 8 code fragments to analyze and give a Big-Oh notation for the running time. Can anybody please tell me if I'm on the right track? //Fragment 1 for(int i = 0; i < n; i++) sum++; I'm thinking O(N) for fragment 1 //Fragment 2 for(int i = 0; i < n; i+=2) sum++; O(N) for fragment 2 as ...

Repairing wrong encoding in XML files

One of our providers are sometimes sending XML feeds that are tagged as UTF-8 encoded documents but includes characters that are not included in the UTF-8 charset. This causes the parser to throw an exception and stop building the DOM object when these characters are encountered: DocumentBuilder.parse(ByteArrayInputStream bais) throws...

Get an OutputStream into a String

What's the best way to pipe the output from an java.io.OutputStream to a String in Java? Say I have the method: writeToStream(Object o, OutputStream out) Which writes certain data from the object to the given stream. However, I want to get this output into a String as easily as possible. I'm considering writing a class like this (...

Cannot create an array of LinkedLists in Java...?

I'm working on a sparse matrix class that needs to use an array of LinkedLists to store the values of a matrix. Each element of the array (i.e. each LinkedList) represents a row of the matrix. And, each element in the LinkedLists represents a column and the stored value. In my class, I have a declaration of the array as: private Linke...

How do I add query parameters to a GetMethod (using Java commons-httpclient)?

Using Apache's commons-httpclient for Java, what's the best way to add query parameters to a GetMethod instance? If I'm using PostMethod, it's very straightforward: PostMethod method = new PostMethod(); method.addParameter("key", "value"); GetMethod doesn't have an "addParameter" method, though. I've discovered that this works: GetMe...

Deadlock in Java

Long time ago, I saved a sentence from a Java reference book: "Java has no mechanism to handle deadlock. it won't even know deadlock occurred." (Head First Java 2nd Edition, p.516) So, what is about it? Is there a way to catch deadlock case in Java? I mean, is there a way that our code understands a deadlock case occurred? ...

Can I find out the return value before returning while debugging in Eclipse

Is it possible to see the return value of a method after the line has been run and before the instruction pointer returns to the calling function? I am debugging code I can't modify (read: don't want to re-compile a third party library), and sometimes it jumps to code I don't have source to or the return expression has side effects that...

Comparing references in Java

Let's say that you have overridden an object's equals() and hashCode() methods, so that they use the object's fields. How you do you check if two references are to the same object, ala the stock equals() method? ...

Newbie java memory management

I'm a c++ programmer and I'm playing around with java after finding JPA which for a few of my current applications is a god send. I haven't touched java since university and I'm having a problem running out of heap space. I'm using the code below as the main part of a not-very-serious test of jdbc/jpa/lucene but I keep on getting random ...

Integrating Captcha with Spring Security

What is appropriate way to integrate SpringSecurity with Capcha ? I have following use case : When user will tries to login, if we he failed to login N times, captcha will be displayed, so authentication will be using three parameters : username, password, captcha. But Spring Security doesn't support built in Captcha handling. I just...

How to create a string representing a Java long as though it were unsigned 64-bit value

My component is handed a long value that I later use as a key into a cache. The key itself is a string representation of the long value as if it were unsigned 64-bit value. That is, when my component is handed -2944827264075010823L, I need to convert that into the string key "15501916809634540793". I have a solution, but it seems brute ...

Are there any differences between Java's "synchronize" and C#'s "lock"?

I think the question is pretty self-explanatory. Do these two keywords have exactly the same effect, or is there something I should be aware of? ...

How do I inject a single property value into a string using spring 2.5.x ?

I would really like to annotate a method with a reference to a single property in a property file for injection. @Resource("${my.service.url"}} private String myServiceUrl; Of course, this syntax does not work ;) Thats why I'm asking here. I am aware that I can inject the full properties file, but that just seems excessive, I dont wa...

Check LDAP connection (Java)

I'm using javax naming to connect to an LDAP database. Is there a good way to check if a connection is still valid? I'm looking for something really efficient here because it may need to be done often. After some web searching all I have found is a suggestion to do a quick search, is there any more lightweight way? /mac ...