java

Good reasons to prohibit inheritance in Java?

What are good reasons to prohibit inheritance in Java, for example by using final classes or classes using a single, private parameterless constructor? What are good reasons of making a method final? ...

jmock mocking a static method

Hello all. I have a static method in my code that I would like somehow to mock. I am using jmock. One way I suppose I could do this is to have "wrapper class" around the static method and mock this but I was hoping for a better solution. I am going about this the wrong way? FEEDBACK: I was going to have a interface and class that h...

How to reduce space between JCheckboxes in GridLayout

Hi everyone, I have three Java JCheckboxes in a column, arranged by setting the layout of the container JPanel to GridLayout(3, 1, 1, 1). When I run the program, there is too much vertical space between the JCheckBoxes; it looks like more than 1 pixel. Since I've already set the vertical space between the JCheckboxes in the layout to ...

Returning a PDF file from a Java Bean to a JSP

EDIT: See my working code in the answers below. In brief: I have a JSP file which calls a method in a Java Bean. This method creates a PDF file and in theory, returns it to the JSP so that the user can download it. However, upon loading the PDF, Adobe Reader gives the error: File does not begin with '%PDF-'. In detail: So far, the JS...

How to determine build architecture (32bit / 64bit) with ant?

We have inherited an ant build file but now need to deploy to both 32bit and 64bit systems. The non-Java bits are done with GNUMakefiles where we just call "uname" to get the info. Is there a similar or even easier way to mimic this with ant? ...

Detecting Virus Scanners

We've had problems with a virus scanner murdering the performance of our app by slowing down writes to an H2 db. So we'd like to be able to detect the presence of any virus scanner and alert the user of the potential problem. It would be part of a problem detection retue that would alert users to known performance factors specific to the...

Jasper report generating bad HTML

Hi, If I view the HTML generated by one of my Jasper reports in IE7 I see the following: <BR /><BR /> <A name="JR_PAGE_ANCHOR_0_1"> <TABLE style="WIDTH: 1000px" cellSpacing="0" cellPadding="0" bgColor="#ffffff" border="0"> <-- table body omitted --> </TABLE> The two BR tags are added via the JRHtmlExporterParameter.HTML_HEADER param...

JSON RPC: java method never called, any ideas?

Hi all, I'm trying to get some code working that a previous developer has written. Yep, his now left the company. :-( I have a JSON RPC call being made from the JS code. The JS all runs fine & the callback method gets an object back (not an error object). But the method on the Java class never gets hit. The smd method does get hit tho...

Generics in legacy code

We've got a fairly large amount of code that just made the jump to Java 5. We've been using generics in those components targeted at being released in the Java 5 version, but the remaining code is, of course, full of raw types. I've set the compiler to generate an error for raw types and started manually clearing them, but at the present...

Is implementing java.io.Serializable even in simple POJO Java classes a best practice?

In general, is it a best practice to have simple POJO Java classes implement java.io.Serializable? ...

Get UID for message from GMail using javax.mail with IMAP

I'm using javax.mail to retrieve mails from GMail using IMAP. I want to also obtain the tags being applied to each mail, so I'm iterating over all the folders in the store (which actually are tags) and downloading mails for each other. I was using the method getUID of ImapFolder to obtain the UID for each message, and then compare them ...

Is it really a best practice to use jstl out tag?

I remember working on a project with a group of developers and they always wanted static html text to be inside of an out tag (<c:out value="words" />). I don't remember why this was the case. Is this really a best practice when building jsp pages? What are the advantages/disadvantages of such an approach? ...

Large Inner classes and private variables

One thing I've run into a few times is a service class (like a JBoss service) that has gotten overly large due to helper inner classes. I've yet to find a good way to break the class out. These helpers are usually threads. Here's an example: /** Asset service keeps track of the metadata about assets that live on other systems. Compl...

Setting multiple jars in java classpath

Is there a way to include all the jar files within a directory in the classpath? I'm trying java -classpath lib/*.jar:. my.package.Program and it is not able to find class files that are certainly in those jars. Do I need to add each jar file to the classpath separately? ...

Encapsulating Java Preferences API

I used to have a custom preferences class for my applications. For my next hobby project i wanted to switch to the Preferences API. But the put and get functions require a default value and i do not want to spread default values all over the source files. Even though my project is small i can not imagine changing default values all over ...

Java array reflection: isArray vs. instanceof

Is there a preference or behavior difference between using: if(obj.getClass().isArray()) {} and if(obj instanceof Object[]) {} ? ...

A good Java library for network math

I'm looking for a Java library that is geared towards network math and already tested. Nothing particularly fancy, just something to hold ips and subnets, and do things like print a subnet mask or calculate whether an IP is within a given subnet. Should I roll my own, or is there already a robust library for this? ...

Java Instantiation.

When an object is instantiated in Java, what is really going into memory? Are copies of parent constructors included? Why do hidden data members behave differently than overridden methods when casting? I understand the abstract explanations that are typically given to get you use this stuff correctly, but how does the JVM really do it...

What xml/xslt library(ies) currently work well for java?

I need to apply some xml templates to various streams of xml data (and files, on occasion) and there seem to be a large number of xml libraries for java out there -- enough that it's difficult to quickly determine which libraries are still active, how they differ from the other options that are also active, and what criteria should be co...

Do I have to close() every EntityManager?

I have just started migrating my homegrown persistence framework to JPA. Given that the persistence frameworks hide a lot of the plumbing, I'm interested in knowing if NOT closing EntityManagers will create a resource leak, or if the frameworks will collect and close them for me. I intend in all places to close them, but do I HAVE to? ...