java

Do containsAll() and retainAll() in the Collection interface address cardinality?

In Java, the containsAll and retainAll in the AbstractCollection class explicitly state that cardinality is not respected, so in other words it does not matter how many instances of a value are on each side. Since all Java collections in the standard library extend AbstractCollection, it is assumed that all of them work the same. Howev...

Java applets vs Silverlight vs Flash (Flex)

Everybody talks about Silverlight and Flash and Flex and how cool etc... Java applets are very similar to Silverlight and Flex, but Java applets exist since 1995. What is the reason we don't have any cool Java applet applications around? My guesses so far: start up time of Java applet, restricted network connectivity, lack of dev tool...

Simple iterator looping gives unexpected result

I am sure it's an obvious error with my logic, but I can't seem to work out what I am doing wrong. Quite simply I have an array list of security codes, I want to compute the correlation between each combination of security codes. My code is as follows: private void crossCorr(ArrayList<String> codes, HashMap<String, Stock> stockMap){ /...

file listener process on tomcat

Hi, I need a very simple process that listens on a directory and does some operation when a new file is created on that directory. I guess I need a thread pool that does that. This is very easy to implement using the spring framework, which I normally use but I can't use it now. I can only use tomcat, How can I implement it? what is ...

What is the best way to scale images in Java?

I have a web application written in Java (Spring, Hibernate/JPA, Struts2) where users can upload images and store them in the file system. I would like to scale those images so that they are of a consistent size for display on the site. What libraries or built in functions will offer the best results? I will consider the following criter...

C# --> Java code generator

I have a small (~2000 lines of code) class that I would like to use from both java & .NET. There are several approaches to do this - among them wrapping the class as a service, using some interop voodoo, or duplicating the code to both C# & java. Do you know an out-of-the-box tool that accomplishes the latter - takes a simple C# class w...

Which Java HTML templating technology works in a way that is closest to Ruby (erb/haml)?

Among the Java templating solutions such as Apache Velocity, Freemarker, Hamlets, Tapestry, StringTemplate, JSP, JSP Weaver (others?) which would most closely approximate the conciseness and simplicity of similar HTML templating solutions in Ruby - haml/erb. I'm concerned both with the syntax of the templating engine as well as how simpl...

Perform xml transformation and filtering in java

I'd like to filter a couple of nested xml elements, evaluation of their attributes. For this purposes I'm searching a efficient and lightweight java api or framework. The main requirements are: filtering of element bodies, based on some pattern or condition event based XML transformation My first idea was apache jelly, but jelly h...

How to use something other than the DefaultClosingOperation when closing a JFrame window?

Hi, I am working on a chat client using a socket, and I want a certain code to be executed before the window closes when the user clicks on "X" (like closing the connection properly). Can I do that without having to implement all the abstract methods in WindowListener? /Avin ...

Would it be wrong to use a static object instead of a database?

This is essentially a design patterns question: I was expecting to query a database to get a list of stocks(shares/securites whatever) that are most highly correlated for a given stock. Instead I thought maybe I should create an object which has a static HashMap and store my data in there. Then "query" it every time I need to. Would ...

XMLDecoder.readObject() returns null

Hi all, I'm trying to read an object from a XML file using XMLDecoder. The construction seems to be OK, but when I call the readObject() method i get null instead of the object I expected. The file exists and the created BufferedInputStream reads the file correctly. This code works OK on the original Vista laptop it was written on, but...

best way of replacing all tags in a string with java

I have a service method that takes a String and then replaces tags in the String with items from a tag library. As follows: for( MetaDataDTO tag : tagValues ) { message = message.replace( tag.getKey(), tag.getText1() ); } Obviously; this make heaps of new strings and is BAD. But the StringBuilder replace method is cumbersome to ...

Is there a way to release a saturated connection pool?

Hi, I'm working with open esb on a glassfish server. We have a connection pool that works with an as400 Database. Every couple of days we get this error: Error in allocating a connection. Cause: In-use connections equal max- pool-size and expired max-wait-time. Cannot allocate more connections The best way to relief the cp is to resta...

Selecting multiple files in Java

<input type="file"> helps to select one file at a time. I need to enable the users of my java-application to select more than one file in one go. The application needs the user to upload 50-100 files and it surely is not feasible to ask the user to upload those 50-100 files one by one. I tried searching on the net for some help rega...

Maven: remove a single transitive dependency

My project includes a jar file because it is listed as a transitive dependency. However, I have verified not only that I don't need it but it causes problems because a class inside the jar files shadows a class I need in another jar file. I do how leave out a single jar file from my transitive dependencies? ...

What non-free tools are popular amongst Java developers

The vast majority of developers I interact with are using Eclipse (I prefer NetBeans) and will leverage many of the free plugins that are available. However, many of them are using few if any tools that require monetary payment. Have developers ever considered that this may be unwise and that they are compromising their own productivity...

What is the best way to link your application to Swing GUI?

If I have Swing GUI class and application, how should I manage communication between these objects? Should I pass GUI object link to app or app link to GUI? Example: public class App{ public App() { GUI gui = new GUI(this) } } or public GUI{ public GUI() { App gui = new App(this) } } ...

monitoring & alerts for a j2se application

I am designing a J2SE application, and looking for a solution for monitoring and alerts. The requirements are: Objects can report their status and issue alerts when they have problems. Calling some pre-defined methods on specific objects (e.g. to dump their state). Monitoring JVM health, especially memory usage. Preferably access all o...

Extending JPA entity mapping

I'm looking for an easy way to extend existing JPA mapping. The idea is as follows: I have an EAR project with EJB3+JPA module which has ClassA annotated and mapped to table class_a. But I want some other module (another EJB module) to have ClassB which adds more properties to ClassA (extend?). One way that I though about, is just to a...

Is DirectX on Java possible?

Is there an easy way to use DirectX in Java? In particular, DirectX's video APIs. I know that C# might be a more natural choice, but I have my devious reasons for wanting to do something so perverse. ...