java

Classpath including JAR within a JAR

Is it possible to specify a Java classpath that includes a JAR file contained within another JAR file? ...

Monitoring Windows directory size

I'm looking for something that will monitor Windows directories for size and file count over time. I'm talking about a handful of servers and a few thousand folders (millions of files). Requirements: Notification on X increase in size over Y time Notification on X increase in file count over Y time Historical graphing (or at least sav...

Where (which layer) to put Entity query methods, "persist" methods etc. ?

Hi, I have a SEAM app with some JPA/Hibernate entities. And I now wonder where to put my query, persistence methods. The default choice seems to put them in a session bean layer with injected @PersistenceContext(...) @Inject EntityManager entityManager; But I think I would rather have the methods on the entities themselves. What ar...

HTTP 1.1 Persistent Connections using Sockets in Java

Let's say I have a java program that makes an HTTP request on a server using HTTP 1.1 and doesn't close the connection. I make one request, and read all data returned from the input stream I have bound to the socket. However, upon making a second request, I get no response from the server (or there's a problem with the stream - it doesn...

what is a good cross-platform css compressor?

i need to compress my css as part of my ant build. i noticed that csstidy does this, but it would not be easy to include this in my ant build because i would need to use a different binary on different platforms. so, is there a java css compressor that people use? ...

Is there a preference for nested try/catch blocks?

One of the things that always bugs me about using Readers and Streams in Java is that the close() method can throw an exception. Since it's a good idea to put the close method in a finally block, that necessitates a bit of an awkward situation. I usually use this construction: FileReader fr = new FileReader("SomeFile.txt"); try { tr...

What is the best practice for JPA/Hibernate entity classes and synchronization?

It seems like most examples of JPA/Hibernate entity bean classes I've seen do no explicit synchronization. Yet, it is possible to call getters/setters on those objects in the context of building up a transaction. And it's possible for those methods to be called across multiple threads (although maybe that's unusual and weird). It se...

Organization of JUnit tests in projects

What would you consider best practice for organizing JUnit tests in a project, and why? For example, do you keep your tests next to the classes they test? Do you put them in a separate but parallel package structure? Do you use a different organization strategy entirely? ...

How to tell if a URL parameter needs to be encoded in Java

I'm writing a Java app that is accepting URL parameter values that may or may not be encoded. I need an easy way to tell whether or not I need to encode the parameter string. In other words, I want a function boolean needsEncoding(String param), which will return true if I pass in the String "[email protected]", and false if I pass in "foo%...

Serialization of objects: no thread state can be involved, right?

I am looking hard at the basic principles of storing the state of an executing program to disk, and bringing it back in again. In the current design that we have, each object (which is a C-level thingy with function pointer lists, kind of low-level home-made object-orientation -- and there are very good reasons for doing it this way) wi...

Java Application Installers

I'm not looking for java-web-start, I'm looking for a thick-client application installation toolkit. I've got a stand-alone application that consists of several files (jar files, data files, etc) and would need to do some pretty standard installation tasks, like asking the user for target directories, have them locate some parts of thei...

CountDownLatch vs. Semaphore

Is there an advantage to using java.util.concurrent.CountdownLatch instead of java.util.concurrent.Semaphore? As far as I can tell the following fragments are almost equivalent: 1: final Semaphore sem = new Semaphore(0); for (int i = 0; i < num_threads; ++ i) { Thread t = new Thread() { public void run() { try { ...

Switching on a string/implementing button actions

Full disclaimer: I'm a CS student, and this question is related to a recently assigned Java program for Object-Oriented Programming. Although we've done some console stuff, this is the first time we've worked with a GUI and Swing or Awt. We were given some code that created a window with some text and a button that rotated through differ...

How to make Jetty dynamically load "static" pages.

I am building Java web applications, and I hate the traditional "code-compile-deploy-test" cycle. I want to type in one tiny change, then see the result INSTANTLY, without having to compile and deploy. Fortunately, Jetty is great for this. It is a pure-java web server. It comes with a really nice maven plugin which lets you launch Jetty...

Java Applet, AWT Refresh problem Mac OS X 10.4

We have a Java Applet built using AWT. This applet lets you select pictures from your hard drive and upload them to a server. The applet includes a scrollable list of pictures, which works fine in Windows, Linux and Mac OS X 10.5. We launch this applet via Java Web Start or within a web page. Our applet does not behave properly in Mac ...

Checkstyle vs. PMD

We are introducing static analysis tools into the build system for our Java product. We are using Maven2 so Checkstyle and PMD integration come for free. However it looks like there is a large overlap in functionality between these two tools, in terms of enforcing basic style rules. Is there a benefit from utilizing both of these? I don...

Will reassigning a variable in every iteration of a loop affect performance?

Consider the following two ways of writing a loop in Java to see if a list contains a given value: Style 1 boolean found = false; for(int i = 0; i < list.length && !found; i++) { if(list[i] == testVal) found = true; } Style 2 boolean found = false; for(int i = 0; i < list.length && !found; i++) { found = (list[i] == testV...

why does parsing this date string throw an unparseable date exception?

I'm using SimpleDateFormat with the pattern "EEE MM/dd hh:mma", passing in the date String "Thu 10/9 08:15PM" and it's throwing an Unparseable date exception. Why? I've used various patterns with SimpleDateFormat before so I'm fairly familiar with its usage. Maybe I'm missing something obvious from staring at it too long. The other po...

Is it possible to detect if an exception occurred before I entered a finally block?

In Java, is there an elegant way to detect if an exception occured prior to running the finally block? When dealing with "close()" statements, it's common to need exception handling within the finally block. Ideally, we'd want to maintain both exceptions and propogate them up (as both of them may contain useful information). The only way...

Monitoring memory usage for a C DLL called with Java via JNI?

How can I monitor the memory being used by a native C DLL that is being called from Java via JNI? Using standard Java monitoring tools and options I can see the Java memory space, but I cannot view any memory used by the C DLL. Java is using ~70MB, but the task in the Task Manager shows 200Mb+, and I'd like to see what's in that 130MB...