java

JTable column spanning

I am trying to make a JTable that has column spans available. Specifically, I am looking to nest a JTable inside another JTable, and when the user clicks to view the nested table, it should expand to push down the rows below and fill the empty space. This is similar to what you see in MS Access where you can nest tables, and clicking the...

Why is the Java main method static?

The method signature of a Java main method is: public static void main(String[] args){ ... } Is there a reason for this method to be static? ...

Use the serialVersionUID or suppress warnings?

Dear all, first thing to note is the serialVersionUID of a class implementing Interface Serializable is not in question. What if we create a class that for example extends HttpServlet? It also should have a serialVersionUID. If someone knows that this object will never be serialized should he define it or add an annotation to suppress t...

C++ versus D

Is the D language a credible alternative to Java and C++? What will it take to become a credible alternative? Should I bother learning it? Does it deserve evangelizing? The main reason I ask is that with the new c++ standard (c++0x) almost here, its clear to me that the language has gone well past the point of no return with respect to ...

Tips for speeding up build time on Linux using ANT, Javacc, JUnit and compiling Java classes

We have a large codebase that takes approx 12 minutes on the developer machines to auto-generate some Java 5 classes using JavaCC and then compiles all the classes as well as running the units test. The project consists of multiple projects which can be built in groups, but we are aiming for a full a build in under 10 minutes What tips...

Should I not subclass by type of object if there are many types?

I am working with a log of events where there are about 60 different "types" of events. Each event shares about 10 properties, and then there are subcategories of events that share various extra properties. How I work with these events does depend on their type or what categorical interfaces they implement. But it seems to be leading t...

Style question: Writing "this." before instance variable and methods: good or bad idea?

One of my nasty (?) programming habits in C++ and Java is to always precede calls or accesses to members with a this. For example: this.process(this.event). A few of my students commented on this, and I'm wondering if I am teaching bad habits. My rationale is: 1) Makes code more readable — Easier to distinguish fields from local variab...

What is a good, simple way to compute ISO 8601 week number?

Suppose I have a date, i.e. year, month and day, as integers. What's a good (correct), concise and fairly readable algorithm for computing the ISO 8601 week number of the week the given date falls into? I have come across some truly horrendous code that makes me think surely there must be a better way. I'm looking to do this in Java but...

How can I convert my java program to an .exe file ?

If I have a java file or class file (*.class) how can I convert it to an .exe file? I also need an installer for my program. Is there is an open source program that can do that? ...

What is the best way to set-up authentication in a tomcat webapp?

I have a self built JSP webapp and at the moment I'm using tomcats built in admin pannel to manage user accounts (that are stored in tomcats config xml files) but this is limited because i can not create new accounts from within the web-app (eg. I can not have a sign up website) and need to manually create the accounts. What is the mos...

Why is using a wild card with a Java import statement bad?

It is much more convenient and cleaner to use a single statement like import java.awt.*; then to import a bunch of individual classes import java.awt.Panel; import java.awt.Graphics; import java.awt.Canvas; ... What is wrong with using a wild card in the import statement? ...

Why should the interface for a Java class be prefered?

PMD would report a violation for: ArrayList<Object> list = new ArrayList<Object>(); The violation was "Avoid using implementation types like 'ArrayList'; use the interface instead". The following line would correct the violation: List<Object> list = new ArrayList<Object>(); Why should the latter with List be used instead of ArrayL...

Why does Swing in my Java Applet flicker on fast mouse over?

I made a Java Applet with some Standard GUI Components on it. I used the MigLayout Manager. If I move the mouse slowly over the various GUI Components everything appears to be fine, but if I move the mouse fast, it flickers. What could make that nasty ugly redraw? (Core 2 Duo 6300, 2GB Ram, Windows XP) ...

What is the best "closable TabbedPane" Component in Java?

After solving my flicker issue, I wonder if there is a better closable Tabbed Pane, then the one that pops up on top by googling for closabletappedpane? (you recognize it by its processMouseEvents Method) I especially need one, that never flickers :-) Please post your experience, links with your own closable Tabbed Panes here. ...

When using ANT, how can I define a task only if I have some specific java version ?

I have the problem that an specific step in Ant can only be executed when we have Java 1.5 installed in the build computer. The task definition uses uses a jar file that was compiled using 1.5, so running with a 1.4 virtual machine will throw an IncompatibleClassVersion exception. I have to find a solution meanwhile to have this task ...

Customization of Hibernate sequence generation

I have one hibernate sequence, that generates all sequence-numbers in my app. When I generate the schemas from hibernate (target Oracle10), it genererates: create sequence hibernate_sequence; I would like to change the configuration of the sequence. I have to use something like: create sequence hibernate_sequence order nocache; I d...

Tomahawk and scrolling tabs

Hello, is there a tomahawk component, that enables "scrollable tabs"? What I mean is something for the following situation: If I have very many tabs, the tab-bar gets a little arrow on the side to scroll through all the open tabs (like in firefox). Is there a tomahawk component for creating something similar? ...

Is it OK to have object instantation 'hooks' in base classes?

I have created my own Tree implementation for various reasons and have come up with two classes, a 'base' class that is a generic tree node that is chock full of logic and another class that extends that one which is more specialised. In my base class certain methods involve instantiating new tree nodes (e.g. adding children). These ins...

How do I peek at the first two bytes in an InputStream?

Should be pretty simple: I have an InputStream where I want to peek at (not read) the first two bytes, i.e. I want the "current position" of the InputStream to stil be at 0 after my peeking. What is the best and safest way to do this? Answer - As I had suspected, the solution was to wrap it in a BufferedInputStream which offers markabil...

Java: print_r?

Hi guys, last time I asked how to populate a data structure here. Now I would like to know if there's something in Java, like the print_r I use in PHP, to represent what I have populated in the Maps and lists without having to do my own algorithm. Any ideas? ...