java

What are your thoughts on method scoped constants?

For example: public void doSomething() { final double MIN_INTEREST = 0.0; // ... } Personally, I would rather see these substitution constants declared statically at the class level. I suppose I'm looking for an "industry viewpoint" on the matter. ...

What causes duplicate requests to occur using spring,tomcat and hibernate

I'm working on a project in Java using the spring framework, hibernate and tomcat. Background: I have a form page which takes data, validates, processes it and ultimately persists the data using hibernate. In processing the data I do some special command (model) manipulation prior to persisting using hibernate. Problem: For some reas...

Jar security

I have a standalone Java app that has some licensing code that I want to secure, i.e., prevent users from changing my software to circumvent the licensing. What is the best way to do this? I've looked at obfuscation, but that entails all sorts of problems: reflection, serialization, messed-up stack traces, etc. Perhaps jar signing c...

Threading issues in a Java HashMap

Something happened that I'm not sure should be possible. Obviously it is, because I've seen it, but I need to find the root cause & I was hoping you all could help. We have a system that looks up latitude & longitude for a zipcode. Rather than access it every time, we cache the results in a cheap in-memory HashTable cache, since the l...

Playing small sounds in Java game

For the computer game I'm making, I obviously want to play sound. So far, I've been using AudioClip to play WAV files. While this approach works fine, the WAV files tend to be gigantic. A few seconds of sound end up being hundreds of kB. I'm faced with having a game download that's 95% audio! The obvious option here would be to use MP3 ...

Hibernate transaction problem

We are using Hibernate Spring MVC with OpenSessionInView filter. Here is a problem we are running into (pseudo code) transaction 1 load object foo transaction 1 end update foo's properties (not calling session.save or session.update but only foo's setters) validate foo (using hibernate validator) if validation fails ? go back to edi...

How to deal with LinkageErrors in Java?

Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux. My application, using the Java Plugin Framework, appears unable to convert a dom4j-created XML document to Batik's implementation of the SVG specification. On the console, I learn that an error occurs: Exception in thread "...

Homemade vs. Java Serialization

I have a certain POJO which needs to be persisted on a database, current design specifies its field as a single string column, and adding additional fields to the table is not an option. Meaning, the objects need to be serialized in some way. So just for the basic implementation I went and designed my own serialized form of the object w...

Duplicate spring configurations being loaded?

I'm looking at the output from spring being loaded up by tomcat and there's something very strange...Everything is duplicated. What would cause this? Whatever it is, it's causing my application to run in odd ways. Additional Info: The application is a web app. All the spring information is loaded using the context loader(?) defined i...

Jasper Reports

Hi, We have a CGI based web report framework written in C/C++. The CGI client connects with proprietery code which in turn connects to database. We are looking for a better Java based replacement for CGI due to performance, maintenance and probably security factors. Can Jasper connect with the proprietery code? Or will Servlet be e...

What's the difference between JavaScript and Java?

What's the difference between JavaScript and Java? ...

Retrieving records from MySQL in Java

I'm building an application in Java to retrieve data from MySQL database. After executing a query I get a ResultSet and do the following to extract records: while (rs.next()) { for (int column = 1; column <= rm.getColumnCount(); column++) { row.add(rs.getObject(column)); } resu...

Which library should I use to write an XLS from Linux / Python?

I'd love a good native Python library to write XLS, but it doesn't seem to exist. Happily, Jython does. So I'm trying to decide between jexcelapi and Apache HSSF: http://www.andykhan.com/jexcelapi/tutorial.html#writing http://poi.apache.org/hssf/quick-guide.html (I can't use COM automation because I'm not on Windows, and even if I was...

jsp:forward in Java without using JSP tag?

Is there a pure-Java equivalent to <jsp:forward page="..." /> that I can use within a <% ... %> block? For example, I currently have a JSP page something like this: <% String errorMessage = SomeClass.getInstance().doSomething(); if (errorMessage != null) { session.setAttribute("error", errorMessage); %> <jsp:forward pag...

Create file with given size in Java

Is there an efficient way to create a file with a given size in Java? In C it can be done like in that answer. Most people would just write n dummy bytes into the file, but there must be a faster way. I'm thinking of ftruncate and also of Sparse files… ...

Refactor this recursive method?

I'm pretty new to the idea of recursion and this is actually my first attempt at writing a recursive method. I tried to implement a recursive function Max that passes an array, along with a variable that holds the array's size in order to print the largest element. It works, but it just doesn't feel right! I have also noticed that I...

How JPA (Hibernate) deal with transaction when fetching Object from database

Hi all, I'm currently developping an application in java using Hibernate as a persistence manager and JPA as an abstraction of the persistence manage hibernate. I'd like to know the impact of wrapping a result query around a transaction. I know the entity manager must stay open for lazily fetched field bug what about transaction in al...

JVM terminates when launching Eclipse MAT on Mac OS with J2SE 6.0

I have recently discovered the incredibly useful Eclipse Memory Analysis Tool, which makes quick work of finding memory leaks in Java applications. Unfortunately, after switching my JDK to 1.6 (under Mac OS 10.5), the JVM terminates immediately upon startup. All that appears is a dialog stating "JVM terminated" with "Exit code = -1". ...

how to release a project which depends on a 3rd party SNAPSHOT project in maven

i would like to release a snapshot project 'foo-1.0-SNAPSHOT' using the maven release plugin. The project depends on a 3rd party module 'bar-1.0-SNAPSHOT' which is not released yet. I use the option 'allowTimestampedSnapshots' in my project's pom.xml to allow timestamped snapshots but i assume that the 3rd party module (bar) is not times...

Button text in JTable renderer not visible. Why ?

I have a custom cell renderer set in JTable and it works but instead an "x" visible on buttons being table cells I see "..." (three dots). What did I miss ?? /*************************************************************************** * Listener reagujący na dodanie nowej wartości ****************************************************...