java

How to determine the order of listeners in web.xml

Hi, I got a bunch of servlet context listeners in my Java webapp, each of them gathering some information about the environment. Some of them depend on information which is gathered by another listener. But I can't determine the order in which the listeners are registered and called, so I have to duplicate code. I understand that the ...

Does JEditorPane have Charset problems when showing HTML?

I have the following code: import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.ScrollPaneConstants; public class ScratchPad { public static void main(String args[]) throws Exception { String html ="<html>"+ "<head>"+ "<meta http-equiv=\"Content-Type\" content=\"tex...

Generic, annotation-driven event notification frameworks

While simple, interface-driven event notification frameworks in Java have been around since pre-Cambrian times (e.g. java.beans.PropertyChangeSupport), it is becoming increasingly popular for frameworks to use annotation-driven event notification instead. For an example, see JBossCache 2.2. The listener class has its listener methods ...

Object-to-Triple mapping using AllegroGraph RDF store?

My project is building a Java web application on top of the AllegroGraph RDF store. I would like to find a good solution to map between the triples that come out of the store and our domain objects. I have looked into Topaz, an Object/Triple mapping API being developed in the spirit of Hibernate. The trouble is that they don't current...

Should new projects use logback instead of log4j ?

Should new projects use logback instead of log4j as a logging framework ? Or with other words :'Is logback better than log4j (leaving the SLF4J-'feature' of logback beside)?' ...

Java2D: Is it always safe to cast Graphics into Graphics2D

Assuming we always use a Sun JVM (say, 1.5+), is it always safe to cast a Graphics reference to Graphics2D? I haven't seen it cause any problems yet and, to my understanding, the Graphics class is legacy code but the Java designers didn't want to change the interfaces for Swing and AWT classes in order to preserver backwards compatibi...

How to resolve a Java Rounding Double issue

Seems like the subtraction is triggering some kind of issue and the resulting value is wrong. double tempCommission = targetPremium.doubleValue()*rate.doubleValue()/100d; 78.75 = 787.5 * 10.0/100d double netToCompany = targetPremium.doubleValue() - tempCommission; 708.75 = 787.5 - 78.75 double dCommission = request.getPremium().do...

How to change an Eclipse default project to a java project?

I checked out a project from SVN and did not specify the project type, so it checked out as a "default" project. What is the easiest way to quickly convert this to a "Java" project? I'm using Eclipse version: 3.3.2 ...

Correct behavior for interface methods that can't be implemented

If I have a class that needs to implement an interface but one or more of the methods on that interface don't make sense in the context of this particular class, what should I do? For example, lets say I'm implementing an adapter pattern where I want to create a wrapper class that implements java.util.Map by wrapping some immutable obje...

What is the proper size for a sequence-generated primary key?

Currently, primary keys in our system are 10 digits longs, just over the limit for Java Integers. I want to avoid any maintenance problems down the road caused by numeric overflow in these keys, but at the same time I do not want to sacrifice much system performance to store infinitely large numbers that I will never need. How do you ha...

Strange Hibernate Cache Issue

Hello We are using Hibernate 3.1 with Spring MVC 2.0. Our problem occurs when data is updated on the database directly (not in the application). We use a Filter to filter a collection of results by whether the orders are opened or closed. If we change an order on the DB to be closed, the filter returns the correct list, however, the ...

Why does HttpServlet implement Serializable?

In my understanding of Servlet, the Servlet will be instantiated by the Container, his init() method will be called once, and the servlet will live like a singleton until the jvm is shut down. i do not expect my servlet to be serialized, since it will be constructed new when the app server recovers or is starting up normally. the servle...

Speeding Up Java

This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together: Firstly: Given an established Java project, what are some decent ways to speed it up beyond just plain in-code optimization? Secondly: When writing a program from scratch in Java, what are some good ways to greatly impr...

Can I specify a JPA compliant persistence.xml file on the java command line?

I've got an UberJar with all my java classes, but want to execute this jar with an external persistence.xml file. Per the specification, Hibernate (or any other JPA provider) looks for the persistence.xml file in any META-INF folder that's on the classpath, but I haven't been able to make this work with an UberJar. Any ideas? Is the U...

Java RMI Tutorial - AccessControlException: access denied (java.io.FilePermission ...

Yesterday I tried to get started with Java RMI. I found this sun tutorial (http://java.sun.com/docs/books/tutorial/rmi/index.html) and started with the server implemantation. But everytime I start the pogram (the rmiregistry is running) I get an AccessControlException with the following StackTrace: LoginImpl exception: java.security.Acc...

Bulk Row Transfer between Oracle Databases with a Select Filter

Basically, I'm trying to selectively copy a table from one database to another. I have two different [Oracle] databases (e.g., running on different hosts) with the same schema. I'm interested in a efficient way to load Table A in DB1 with the result of running a select on Table A in DB2. I'm using JDBC, if that's relevant. ...

Best solution for migration from Oracle Forms 6i to the web?

I work in an Oracle shop. There's a toolset that consists of roughly 1000 Oracle Forms (using the Forms builder from 6i, early 90's software) with Oracle 10g on the back end. It's serving roughly 500 unique people a month, with 200 concurrent connections at any given time during the work day. Obviously this is something that needs to ...

How do you enable anti aliasing in arbitrary Java apps?

Many Java Apps don't use anti-aliased fonts by default, despite the capability of Swing to provide them. How can you coerce an arbitrary java application to use AA fonts? (both for applications I'm running, and applications I'm developing) ...

Dynamically find the class that represents a primitive Java type

I need to make some reflective method calls in Java. Those calls will include methods that have arguments that are primitive types (int, double, etc.). The way to specify such types when looking up the method reflectively is int.class, double.class, etc. The challenge is that I am accepting input from an outside source that will specify...

How do I time a method's execution in Java?

It seems like it should be simpler than it is to get a method's execution time. Is there a Timer utility class for things like timing how long a task takes, etc? Most of the searches on Google return results for timers that schedule threads and tasks, which is not what I want. ...