java

Why does HttpServlet throw an IOException?

I get why an HttpServlet would throw ServletException, but why IOException? What was the reasoning behind this? ...

Why choose an XSL-transformation?

For a current project the decision has to be made whether to use XML and an XSL-transformation to produce HTML or to directly use HTML-templates. I'd be interested in arguments for or against the XSL-approach. I understand that in cases where you have to support many different layouts, an XSL-solution has a lot of advantages, but why wo...

Algorithm for estimating text width based on contents

This is a long shot, but does anyone know of an algorithm for estimating and categorising text width (for a variable width font) based on its contents? For example, I'd like to know that iiiiiiii is not as wide as abcdefgh, which in turn is not as wide as WWWWWWWW, even though all three strings are eight characters in length. This is a...

I'm interviewing for a j2EE position using the Spring Framework; help me brush up

I'll be interviewing for a J2EE job using the Spring Framework next week. I've used Spring in my last couple of positions, but I probably want to brush up on it. What should I keep in mind, and what web sites should look at, to brush up? ...

implicit super-interface in Java?

So we all know that all classes implicitly extend Object. How about interfaces? Is there an implicit super-interface? I say there is. The following code compiles: java.io.Serializable s1 = null; java.io.Serializable s2 = null; s1.equals(s2); The equals method is not declared in Serializable, but in Object. Since interfaces can only e...

annotations in Spring MVC

Hi, I'd like to convert this SimpleFormController to use the annotation support introduced in Spring MVC 2.5 Java public class PriceIncreaseFormController extends SimpleFormController { ProductManager productManager = new ProductManager(); @Override public ModelAndView onSubmit(Object command) throws ServletE...

Setting the default SocketFactory

I recently migrated my web services from Axis to CXF (2.1). It appears that while Axis needed the "axis.socketSecureFactory" set, CXF grabs the default. How do I set the default SocketFactory in Java to my own implementation (such as a property)? What I am not looking to do is to set the default SocketFactory properties like setting t...

Java Generics and Infinity (Comparable)

With the type Integer you can do this: int lowest = Integer.MIN_VALUE; What can I do if I use generics? K lowest = <...>; I need this in order to implement something similar to a PriorityQueue. I have access to a node I want to remove from the queue, but it is not the min. 1. I need to make it the min by decreasing the key of that...

Selenium typeKeys strips out dot from the String being typed

The following instruction Selenium.typeKeys("location", "gmail.com"); types the string gmailcom instead of gmail.com. What's happening there? From the comments: I am trying to simulate autofill and the only way to do it currently on selenium is to combine type and typeKeys. eg: selenium.type("assigned_to", split[0]+"@"); selenium.t...

Is fine grained control of aspectj-autoproxy possible in spring ?

If I just add <aop:aspectj-autoproxy proxy-target-class="false"/> to the start of my spring context, every single bean that implements an interface gets a JDK proxy. I would really like to limit the proxying A) to classes that actually need proxies or B) classes that I specify as needing proxies. I tried using the aop:scoped-proxy stanz...

Cloning with generics

Once upon a time there was a class: public class Scope<C extends Cloneable & Comparable<C>> implements Comparable<Scope<C>>, Cloneable, Serializable { private C starts; private C ends; ... @SuppressWarnings("unchecked") @Override public Object clone() { Scope<C> scope; try { scope = (Scope<C>...

How do I simulate a modal dialog from within an Applet?

On setVisible(true), I call the following code to start a modal dialog: private synchronized void startModal () { try { if (SwingUtilities.isEventDispatchThread()) { EventQueue theQueue = getToolkit().getSystemEventQueue(); while (isVisible()) { AWTEvent event = theQueue.getNextEvent(); Object source = ...

Where is the Queue class in the Java Collections?

I only see a Queue interface, is there no Queue class in the Java Collections? ...

Implementation of a user managment dialog in Java

I need a window for my application that allows the user to: see currently existing users create new users change permissions delete users view users details While trying to find a perfect way to create a good user experience, I stumbled upon various different approaches: Dialog Based, Tree Based, etc... I've decided to go with that:...

ant compile doesn't copy the resources

Hello, I created my own build.xml which got: <target name="compile"> <mkdir dir="build"/> <javac destdir="build"> <src path="src"/> </javac> </target> <target name="build" depends="compile"> <mkdir dir="dist"/> <jar destfile="dist/app.jar" basedir="build" /> </target> <target name="run" depends="compile"> ...

Java: Cyclic generic type relation doesn't allow cast from supertype (javac bug).

Hello! I encounter a totally strange behavior of the Java compiler. I can't cast a supertype to a subtype when cyclic generic type relation is involved. JUnit test case to reproduce the problem: public class _SupertypeGenericTest { interface ISpace<S extends ISpace<S, A>, A extends IAtom<S, A>> { } interface IAtom<S extends ISpac...

Spring Web Flow - How can I set up unit test with values already in conversationScope?

I am working on a project using Spring Web Flow 2.0. I am trying to unit test a flow that begins with a decision state. The decision state checks the value of an object that is on the conversationScope. I cannot figure out how to insert a value into the conversationScope for the unit test. I have tried: getConversationScope().put("...

Blogging System which runs on the Google App Engine

Hey, what is a cool blogging engine for GAE? I really like wordpress, but PHP isn't available on the GAE. Which blogging systems do you use on GAE? Which experiences you have made with it? Thanks. ...

how to get users ip address in java

While this may seem simple, i have tried the usual request.getRemoteAddr(), request.getRemoteHost() but i keep getting my servers address. Something about my configuration, im getting my gateway ip. Does anyone know how to get the acutal users IP address? thanks ...

Whats is going on with memory allocation here?

While trying to discover the max size of a Java String array on my machine I ran into some interesting results, here is the code, String [] max; int i = 15444000; while(true){ try{ max = new String[i]; System.gc(); Thread.sleep(10); }catch(InterruptedException e){} i += 1; System.out...