java

Java vs C#: Are there any studies that compare their execution speed?

Taken out all the obvious caveats related to benchmarks and benchmark comparison, is there any study (an array of well documented and not biased tests) that compares the average execution speed of the two mentioned languages? Thanks ...

Cause for memory leaks in websphere ValueHandlerPool (Suspected)

We encounter an OutofMemory error. I analyzed the *.phd file, that websphere dumps, using Eclipse Memory Analyzer. The Leak Suspect Report of MAT, provides the following information The class "com.ibm.rmi.io.ValueHandlerPool", loaded by "com.ibm.oti.vm.BootstrapClassLoader @ 0x466578", occupies 68,734,136 (50.25%) bytes. The memory is ...

How Do I Eject a Volume in Java?

How can I "eject" a volume with Java, cross platform? I have a program that does some operations on a removable drive (USB memory card reader), and once it's done, I want the program to eject/unmount/remove (depending which os lingo we're talking in) the memory card. Is there a reliable cross-platform method of doing this? ...

Java exec on Unix

I have the Java code below running on Unix (both AIX and Linux), but it doesn't work. If I run this code the file q1.01 is not compressed, and I don't get any exceptions thrown (The file q1.01 exists, and I expect to find the file q1.01.Z after the command runs.) At the command prompt if I type "which compress" it reports back with "/usr...

Replace \\ with \ in java

I have to replace '\\' with '\' in Java. The code i am using is System.out.println( (MyConstants.LOCATION_PATH + File.separator + myObject.getStLocation() ).replaceAll("\\\\", "\\") ); But i don't know why it is throwing 'StringIndexOutOfBoundsException'. It says 'String index out of range: 1' What could be the reason? I guess it i...

Trying to use tomcat with eclipse.

Hey, I am trying to use tomcat with eclipse. I have installed it all and got the tomcat plugin installed. I have put a .war file in the webapps folder of tomcat and have made sure autodeploy is set to true. The problem I am having is that I can't get tomcat to run this .war file. The tomcat server is started and running as it tells me u...

Auth (digest) request from Servlet

Hi guys, I'm creating a small servlet. It's hosted at root, "/", and whatever comes after "/" is a resource, like "/myanim.swf". Most of the files are public, but some are private. For public files, they are just served, but for private files, I wish the browser to present an authentication box and have a Digest authentication sent back ...

How to get dependency with Ivy

I am in the process of reviewing the use of Ivy in our application. I have set up a simple configuration to pull down cobertura. <ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"&gt; <info organisation="com" modul...

CharSequence VS String in Java ?

Programming in Android, most of the text values are expected in CharSequence. Why is that ? What is the benefit and what are the main impacts of using CharSequence over String ? What are the main differences, and what issues are expected, while using them, and converting from one to another ? ...

How to determine when an application started using java reflection has completed

Hello developers! I have a Java program that uses reflection to find and invoke the main(String[] args) method of another Java program. This other program is usually a Swing App that tends to spawn its own threads. I was wondering if there was a way to determine when this other 'program' terminates. I'm not sure if there is anyway to de...

Struts 1 not user-friendly with the browser back button: any solutions?

I have inherited a Java website that uses Struts 1. Currently if the brosers back button is pressed midway through a journey they get a 'Webpage has expired' error. From my limited understanding, this seems to be a flaw in the design of Struts - every page is a form. Is there anyway to get around the problem, or would the only way be mi...

Is there a neater way of testing calls to mocked methods for each item in a list

This is an example of a pattern I've encountered a lot recently. I have a method to be tested that takes a List and may invoke some other method(s) for each item in the list. To test this I define an Iterator with the expected call parameters and a loop in the JMock expectations to check the call is made against each item of the iterator...

Why does the Java List interface not support getLast()?

I'm trying to understand the API inconsistency in the Java standard collections library. There is no method in List or in AbstractList to get the last item, although one can simulate that with size and getIndex(). However, LinkedList supports that function. Any idea why it was decided not to support this method in the interface? ...

Java Deployment Toolkit - beforeRedirect hook?

I'm using the Java Deployment Toolkit to deploy a java applet in an iframe. javaDeploy.js automatically redirects the iframe to the java download page if the users browser does not have the plugin installed however I'd like to give some kind of notice to the user before this happens as its a little weird just to see the java download p...

What needs to be Serializable in this Java situation?

I've got a class Thing: public abstract class Thing { // prevent instantiation outside package. Indeed, no Things will // ever actually have a runtime class of Thing Thing(){}; public static Thing create() { return new SpecialThing1(); } public static Thing createSpecial() { return new Speci...

How can I configure Spring to save as much memory as possible?

We're deploying an application on a semi-embedded device that has memory constraints. Looking to save whatever we can we are analysing heap dumps of the app and attacking the biggest consumers. We use Spring 2.5 together with Spring DM 1.1 and we notice that some of our bundles with more complex Spring contexts are using up quite a bit...

Are tasks parallelized when executed via an ExecutorCompletionService ?

I submitted 5 jobs to an ExecutorCompletionService, but it seems like the jobs are executed in sequence. The ExecutorService that is passed to the constructor of ExecutorCompletionService is created using newCacheThreadPool form. Am I doing anything wrong ? UPDATE Each job is basically doing a database query & some calculation. The code...

What's wrong with using System.err in Java?

I'm using the Enerjy (http://www.enerjy.com/) static code analyzer tool on my Java code. It tells me that the following line: System.err.println("Ignored that database"); is bad because it uses System.err. The exact error is: "JAVA0267 Use of System.err" What is wrong with using System.err? ...

Hibernate: Specifying columns in a one-to-many relationship

I'm trying to build a Hibernate layer for a database schema I have essentially no control over. Simplified, there are two tables. Table parent has two important columns: parent_id, integer, primary key, autoincremented parent_code, string, unique key, generated by a black box somewhere (let's say this is a UUID for sanity's sake) Plu...

Multi-valued hashtable in Java

Is it possible to have multiple values for the same key in a hash table? If not, can you suggest any such class or interface which could be used? ...