java

How can I form an ordered list of values extracted from HashMap?

My problem is actually more nuanced than the question suggests, but wanted to keep the header brief. I have a HashMap<String, File> of File objects as values. The keys are String name fields which are part of the File instances. I need to iterate over the values in the HashMap and return them as a single String. This is what I have cu...

Using SVN with CruiseControl?

I'm trying to use CruiseControl 2.7.3, (the original), to build a Java project that is in an SVN repository. My cruise configuration is using the svn plugin for the modification set. When a modification is detected, a build is scheduled using Ant. That Ant build file then uses the svnant Ant Task to do a complete checkout of the pro...

Java: Design with Singletons and generics.

I am using an interface called Predicate which is used for sifting through Collections. For example, I can define public class BlackCatPredicate implements Predicate<Cat> { public boolean evaluate( Cat c ) { return c.isBlack(); } } and then use some utility findAll( Collection<T> coll, Predicate<T> pred) method to apply th...

Java 5 to Java 1.4 Source Code Backporting Tool

Is there a tool that, given a Java 5 level source code, will backport it to Java 1.4-compliant source code, by removing Generics declarations, transforming for eachs in simple fors or iteration fors, etc.? Please note that I am looking for a tool that translates source code to source code, not class binaries. ...

What's the motivation for properties?

I'm a bit confused as to why languages have these. I'm a Java programmer and at the start of my career so Java is the only language I've written in since I started to actually, you know, get it. So in Java of course we don't have properties and we write getThis() and setThat(...) methods. What would we gain by having properties? Than...

What is the difference between Hudson and CruiseControl for Java projects?

I think the title sums it up. I just want to know why one or the other is better for continous integration builds of Java projects from Svn. ...

Java enum converting string to enum

Say I have an enum which is just public enum Blah { A, B , C, D } and I would like to find the enum value of a string of for example "A" which would be Blah.A. How would it be possible to do this? Is the Enum.ValueOf() the method I need? If so, how would I use this? ...

Forcing FileNotFoundException

I'm writing a test for a piece of code that has an IOException catch in it that I'm trying to cover. The try/catch looks something like this: try { oos = new ObjectOutputStream(new FileOutputStream(cacheFileName)); } catch (IOException e) { LOGGER.error("Bad news!", e); } finally { The easiest way seems to make FileOutputStrea...

How do I avoid the implicit "^" and "$" in Java regular expression matching?

I've been struggling with doing some relatively straightforward regular expression matching in Java 1.4.2. I'm much more comfortable with the Perl way of doing things. Here's what's going on: I am attempting to match /^<foo>/ from "<foo><bar>" I try: Pattern myPattern= Pattern.compile("^<foo>"); Matcher myMatcher= myPattern.matcher(...

Tracking OS-level window events in Java

I have a requirement to be able to track how much a user interacts with the different applications running on their machine. What seemed logical to me was to keep a log of window focus events with timestamps which would tell you what applications were in focus over the course of the day. We have some other things to do in this applicati...

Another way to solve the Dining Philosopher problem (need a point in the right direction)

Hello, for a programming assignment I have been asked to implement a solution to the Dining Philosopher problem. I must do so in two ways: Use the wait() and notifyAll() mechanism Using an existing concurrent data structure provided in the Java API I have already complete the first implementation. Which concurrent data structure is m...

How to read Java properties file from a JAAS LoginModule

I'd like to read a properties file in my applications WEB-INF folder or my tomcat/apache server from a JAAS loginModule. But I'm not understanding how to properly refer to the location from the LoginModule, in a host name independent manner. ...

how to run the batch file from any folder

cd ../../jobs set CLASSPATH=.;../xyz.jar;../mysql-connector-java-5.1.6-bin.jar java folser.folder1 ../Files/MySQL.xml cd .. I need to run the batch file from any directory. I have set the paths for java. Can anybody help me? ...

How Can I Add the Apache POI Library in and Eclipse Project?

I download the Apache POI from apache.org but don't know how use it with one of my existing project in Eclipse. ...

Best Java IDE for Visual Studio fan?

As a C# programmer I want to increase the java knowledge and the only barrier is getting grip with the java IDEs like Eclipse. What can I do or use to get Visual-Studio-like experience from these IDEs. EDIT: I don't want visual studio drag and drop support specifically but I need the Resharper plugin functionalities and responsive inte...

Boolean[] vs. BitSet: Which is more efficient?

What is more efficient in terms of memory and CPU usage — an array of booleans or a BitSet? Specific BitSet methods are not used, only get/set/clear (==, =, Arrays.fill respectively for an array). ...

Should the context attributes in web application being made thread-safe?

Hi, I am creating a context (e.g. TestContext.java) as a singleton in the web application. Multi struts actions will access the context. Should I create the context attributes as thread-safe? Thanks. ...

What ec2 image (ami) do you recommend for working with java 5, jboss, mysql, apache?

What ec2 image (ami) do you recommend for working with java 5, jboss, mysql, apache? ...

Java EE security - application clients

Hi. I'm writing on a Java EE project which will have everything from 3-6 different clients. The project is open source, and I wonder what security mechanisms one could/should use. The problem is: Because it is open source, I would believe that it is possible for anyone with a user to write their own client (maybe not realistic, but trul...

Java and virtual memory handling

Is it possible tell the JVM to hint the OS that a certain object should preferably not get pushed out to swap space? ...