Skip to content

Java: for loop, incompatible types

I’m trying to run this for loop; However every time I try to compile I get an error stating ‘incompatible types – found int but expected boolean’ I can’t work out what I’m doing wrong! Answer the second statement: grid[0].length is an integer. The second statement in a for …

Excluding classes in Maven Checkstyle plugin reports

I have a Maven 2 project and I want to configure my Checkstyle report plugin so that only some of my classes are analysed. I have found the maven.checkstyle.excludes property, but despite passing this as a command line parameter (using -D=maven.checkstyle.excludes=…) I can’t get it to work. I can&…

Java SFTP Transfer Library [closed]

I’m looking for a dead simple Java Library to use for SFTP file transfers. I don’t need any other features beyond that. I’ve tried Zehon’s, but it’s incredible naggy, and I think 8 jar files is a bit …

Should Enterprise Java entities be dumb?

In our legacy Java EE application, there are loads of value object (VO) classes which typically contain only getters and setters, maybe equals() and hashCode(). These are (typically) the entities to be saved in persistence storage. (For the record, our app has no EJBs – although that might change in the…

java thread reuse

I have always read that creating threads is expensive. I also know that you cannot rerun a thread. I see in the doc of Executors class: Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available. Mind the word ‘reuse’. How do thr…

Changing font-size at runtime in a Swing application

A lot of web sites these days have an option to let the user increase or decrease the size of the font that appears on the site. I’d like to add similar functionality to my Java Swing app, with an option to change the font to either a larger size or revert to standard size. The user would be able

Why doesn’t String’s hashCode() cache 0?

I noticed in the Java 6 source code for String that hashCode only caches values other than 0. The difference in performance is exhibited by the following snippet: Running this in ideone.com gives the following output: So my questions are: Why doesn’t String’s hashCode() cache 0? What is the probab…

Window resize event?

I’m writing a simple painting program using Java, and I want some method to be called whenever the JFrame component is resized. However I can’t find any method like windowResizedListener or an event like windowResizedEvent. What can I do?! Answer Implement a ComponentAdapter with componentResized(…

Obtain real Class object for Spring bean

I am using Spring to inject beans. And I am using some annotations to annotate bean methods (Security, TransactionManagement, ExceptionHanling, Logging). The problem is: I want to create JUnit test …