java

Maven: Java classes don't compile after Ant task

My project generates source code using the Rats! parser generator. Rats! doesn't have a Maven plugin that I'm aware of, so I'm trying to build the parser using an Ant Java task, like so: <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>generate-sources</phase> <configuration...

HashMap profiling

Are there any HashMap implementations that expose hook methods for profiling the performance of the Map (average chain length, best / worst / average access time, #rehashes, etc.). It seems quite common to use HashMap and "hope for the best" with regards to ~O(1) access time, without analysing whether this is really the case but I'd lik...

Efficient hashCode() implementation

I often auto-generate an class's hashCode() method using IntelliJ IDEA and typically the method takes the form: result = 31 * result + ... My question is what is the purpose of multiplying by 31? I know this is a prime number but why pick 31 specifically? Also, if implementing a hashCode() for a particularly small / large dataset wo...

Restarting Log4J logging via JMX

It seems a Log4j rolling appender stopped logging because it hit the MaxBackupIndex limit. I've moved the old log files out of the way but Log4j doesn't seem to start logging again. Is there a way to restart Log4J logging via JMX? I'd like to leverage this insteaed of restarting a Tomcat instance. Thanks. ...

Create ticket in BMC Remedy via Java

I need a Java class to submit tickets to BMC Remedy's Helpdesk product. Wondering if anyone has done this already and is willing to share either code, or experience. ...

Hash Code Implementation

Hi all, In relation to this question (http://stackoverflow.com/questions/1074530/efficient-hashcode-implementation) I have one more question. I have a "value" class which instances are persisted in a database. Thus this class's instances all have a unique ID. As a consequence I implemented the hash code method (and related equals meth...

Generating excel documents programmatically

Has anyone used a Java based library for generating excel documents? Preferably support for 2003? ...

Double in HashMap

I was thinking of using a Double as the key to a HashMap but I know floating point comparisons are unsafe, that got me thinking. Is the equals method on the Double class also unsafe? If it is then that would mean the hashCode method is probably also incorrect. This would mean that using Double as the key to a HashMap would lead to unpred...

Is there a tool that checks GWT JRE emulation library violations?

I'm trying to port a Swing application to GWT. However lots of this application classes use things that are not supported by GWT JRE emulation library such as java.util.Locale, java.text.SimpleDateFormat and much more. Is there a tool that scans a project and spots such problems? ...

XML-RPC PHP Java

Hi, I'm having a problem with the XML-RPC communication. I have a XML-RPC Client made in Java with Apache XmlRpc and a XML-RPC Server made in PHP with PEAR's XML_RPC. The problem is that i get a "HTTP server returned unexpected status: Not Found" error. I tested the server with a PEAR XML-RPC Client and it works. I don't know what is th...

Should the JUnit message state the condition of success or failure?

I can write an assertion message one of two ways. Stating success: assertEquals( "objects should be identical", expected, actual ); Or stating the condition of being broken: assertEquals( "objects aren't identical", expected, actual ); Is there a standard for this in JUnit specifically? If not, what are the arguments for each sid...

NoClassDefFound when running a jar

I built a jar using IntelliJ, setting the main class properly. When I run "java -jar foo.jar" from the command line (Windows), I get an exception that claims the main file is missing. The main class looks something like: package mypackage; public class LockUtil { public static void main(String[] args) { ... I'm getting the follo...

How to debug java depenendency failure on version of DOMImplementation

I've a chunk of code that works fine in isolation, but used a dependency in a clients project fails. A call to Document doc = impl.createDocument(null,null,null); fails (looks like the problem at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4913257). The instance of 'impl' in my unit tests is an instance of com.sun.org.apache.x...

XML using Java

I have to write an XML file using java.The contents should be written from a map.The map contains items as key and their market share as value.I need to build an XML file withe two tags.I will use this XML to build a piechart using amcharts.Can anyone help with an existing code? <xml> <pie> <slice title="<Map key1>"><Map Value1></sl...

java command line execution

C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\Welcome>javac Welcome.java C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\Welcome>java Welcome.class Exception in thread "main" java.lang.NoClassDefFoundError: Welcome/class Caused by: java.lang.ClassNotFoundException: Welcome.class at java.net.URLClassLoader$1.run(Unknown...

Password encryption with Spring/Hibernate - Jasypt or something else?

In a Java application stack with Spring & Hibernate (JPA) in the Data Access Layer, what are good methods of applying the password encryption (hopefully using annotations), and where can you find out more about getting it done (tutorial, etc)? It's understood that I would use a JCA supported algorithm for encrypting the passwords, but I...

what are the $1 in class file?

C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet>dir Volume in drive C has no label. Volume Serial Number is 2041-64E7 Directory of C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet 2009-07-02 23:54 . 2009-07-02 23:54 .. 2004-09-06 14:57 582 WelcomeApplet.ht...

handling Java custom serialization with multiple versions of serializer classes?

I have a custom data storage format I'm implementing on top of either HDF5 or NetCDF. My data format evolves occasionally (but rarely), and it is important to be able to read "old" files later. I had been using C++ and Microsoft COM but have abandoned those toolkits in favor of Java. In my COM days, I could put the CLSID of the data for...

Type order with overloaded methods in Java

Hi Given two methods on the same class in Java : public void doSomething( Person person ); public void doSomething( Employee employee ); where Employee extends Person If I call : doSomething( employee ) I find that doSomething( Person ) get's invoked. I'd have expected the overload with the closest matching contract be invoked...

Is it ok to use same file writer for writing different files

There's a loop where we get certain data. Depending on the data, file writer needs to write to different files. Is it a good practice? ...