java

Is this code sample really returning the right parameterized types?

I've read the Beautiful code with Google Collections, Guava and static imports article about Java collections, and the following snippet got my attention: Map<String, Map<Long, List<String>>> map = Maps.newHashMap(); The thing is, I don't understand how it's possible that the newHashMap method can return a Map<String,Map<Long, List<St...

Synchronize on BlockedQueue.

Hello, I have a code piece that I am reviewing (using FindBug). public class MyClass{ ... private BlockedQueue q = new LinkedBlockingQueue<MyData>(1000); private static final batchSize = 1000; public boolean testMethod(){ boolean done = false; synchronized(q){ if(q.size == batchSize){ q.notify(); done...

Using JavaHelp with a web app

We have a system where our front end is either a Rich Client application or a web interface into the back end. We are working on adding context-sensitive help to our system, but we need to use the same base configuration files - i.e. the context-sensitive help files would need to be the same, and preferably use the same system. I was l...

Shortest path (fewest nodes) for unweighted graph

I'm trying build a method which returns the shortest path from one node to another in an unweighted graph. I considered the use of Dijkstra's but this seems a bit overkill since I only want one pair. Instead I have implemented a breadth-first search, but the trouble is that my returning list contains some of the nodes that I don't want...

Firefox cache path construction Mac OS X

I know the path for Firefox's cache is as follows on Mac OS X Leopard: ~/Library/Caches/Firefox/Profiles/COMPUTER_CODE.default/Cache How is the variable "COMPUTER_CODE" above created? I assume it is different from computer to computer. I want to be able to programmatically delete this cache if it exists. ...

What is the purpose of using a distinct class for each tab in Wicket?

The Wicket examples page for TabbedPanel (link) uses separate, distinct classes for each tab (TabPanel1, TabPanel2 and TabPanel3). Is there a reason to not just use three instances of the same class? If yes, what is it? I'm still fairly new to Wicket, but those classes look identical to me. EDIT: I ran a simple example, using three o...

Spring Explorer not showing beans from bean definition file

I just downloaded the Springsource Tool Suite, and I created a simple bean configuration file called myDefinition.xml and placed it in the root directory of the Spring Project. However, the Spring Explorer is not showing any data. I'm using eclipse 3.5 and the latest SpringSource all-in-one installation. Also, if I specify invalid prope...

Java - downsampling wav audio file

Hi I need to downsample a wav audio file's sample rate from 44.1kHz to 8kHz. I have to do all the work manually with a byte array...it's for academic purposes. I am currently using 2 classes, Sink and Source, to pop and push arrays of bytes. Everything goes well until I reach the part where I need to downsample the data chunk using a ...

Java recursive binary tree

Welcome! I have a recursive public static method named less that takes a tree node (an original binary tree, not really a search tree) and a int parameter that returns if all the values in the tree are less than the integer. So, I would use a public class TN { public int value; public TN left, right; public TN(int v, TN l, TN r) {v...

Apache HSSF POI excel doc to tab delimted file

went and got a file that already "works" from here: xls to csv Note, I wanted a tab delimited format, so I just went in and changed "," to "\t" and then removed a bunch of the extra formatting, such as naming the workbook. The problem is, however, that this code I found splits some Excel rows into 2+ lines. These are the rows where I h...

Rhino Javascript:

I am utilizing the javax.scripting with Rhino in this project. I have a Java method that returns a Java Object (Double, Long, Integer, etc). I want to call that method from javascript and reference the result as a Javascript primitive type. However, javacript recognizes the return type as an Object. How do I force it to convert...

Buffered Reader HTTP POST

Hello, Looking for a bit of help, I have currently written a HTTP server. It currently handles GET requests fine. However, whilst using POST the buffered reader seems to hang. When the request is stopped the rest of the input stream is read via the buffered reader. I have found a few things on google. I have tried changing the CRLF and ...

Benefits of Parallel programming

I have three similar questions: Which known applications have benefits of multicore processors? Which known applications use posix threads (pthreads)? What can pthreads do that Java threads cannot? ...

Can you lock on a local object in Java?

I have this snippet of code private Templates retrieveFromCache(String name) { TemplatesWrapper t = xlCache.get(name); synchronized(t){ if (!t.isValid()) { xlCache.remove(name); return null; } } return t.getTemplate(); } xlCache is a Concurrent...

How to know when there's too much logging messages?

I came across one very good library for parsing CUE files. But when I started to read its source code, I realized that it is almost unreadable: public void setParent(final CueSheet parent) { FileData.logger.entering(FileData.class.getCanonicalName(), "setParent(CueSheet)", parent); this.parent = parent; FileData.logger.exiti...

Using a PEM (X.509) private key to sign a message natively

I'm trying to use a PEM(X.509) certificate (stored in a privateKey.pem file on disk) to sign messages sent via sockets in Java, but am having a lot of trouble finding an example that's close. I'm normally a C++ guy who's just stepping in to help on this project, so it's been a little difficult for me to put it all together into code that...

Byte Array to Image File

I am given a byte[] array in Java which contains the bytes for an image, and I need to output it into an image. How would I go about doing this? Much thanks ...

Profiling a Java Application in Eclipse? (plug-in)

I'm looking to find bottlenecks in my Java application in Eclipse. I'm thinking this might be useful: http://www.eclipse.org/projects/project%5Fsummary.php?projectid=tptp.performance Any other good plug-ins to use? EDIT OK, it doesn't necessarily have to be an Eclipse plug-in. But it would be nice. And, I'm most interested in speed. ...

Sending messages to spam folder

I want to know what do I have to do in my mail application to move rest of the messages of marking any email address as spam into spam folder without restarting mail server. Actually I can move the messages into spam folder, but I have do some configuration in my mail server, then have to restart it before making it move to spam folder i...

Java-like Collections in PHP

I'm learning PHP5 (last time I checked PHP was in PHP4 days) and I'm glad to see that PHP5 OO is more Java-alike than the PHP4 one but there's still an issue that makes me feel quite unconfortable because of my Java background : ARRAYS. I'm reading "Proffesional PHP6" (Wrox) and It shows its own Collection implementation. I've found ot...