I was wrote a little scratch program to check the time of looping through a 2 dimensional array by rows or columns, since I remembered that one way was much faster for large data sets, but I couldn’t remember which way. I ran into an interesting error when I ran my program though. Now in my test I am us…
Tag: java
How to iterate a HashMap using the natural entrySet() order?
My Map contains keys sorted in alphabetical order. When I display it, I’m using entrySet().iterator(), but my results are not in the alphabetical order. How can I get my results in order?
How to efficiently predict if data is compressible
I want to write a storage backend to store larger chunks of data. The data can be anything, but it is mainly binary files (images, pdfs, jar files) or text files (xml, jsp, js, html, java…). I found most of the data is already compressed. If everything is compressed, about 15% disk space can be saved. I…
Interrupting looped threads in Java
I’m trying to understand how threads work in Java and currently investigating how to implement looped threads that can be cancelled. Here’s the code: The thread I create is indended to be interrupted sooner or later. So, I check isInterrupted() flag to decide whether I need to go on and also catch…
Convert pixel location to latitude/longitude & vise versa
I need to convert latitude longitude values into pixel positions as well as do the opposite. I’ve found many solutions to go from lat/lng->pixel, but can’t find anything on the reverse. A couple of notes: The map is a fixed size, no zooming, no tiles. I don’t need anything super accurate,…
where is array saved in memory in java?
If I have a function that in that function I declare: Where are arr and the whole array stored? heap? stack? Does it matter if the declaration is in some function or in main()? and let’s say I also have these command lines: where are arr[0] and arr[1] stored? Answer Memory diagram: Boxes are memory loca…
Setting the Bounce Address in Apache Commons Mail
Using the Apache Commons to send email there is the following code. But the bounce will not work. It sends the bounce to the party that authenticated the message, which in this example is SMTP_AUTH_USER. So How can I get it to bounce properly? Answer Did you check with a packet sniffer what is actually going …
How to specifically suppress “Comparing identical expressions” in Eclipse-Helios JDT
I tried annotating the enclosing method with but this does not work (worse yet, the annotation results in its own Unsupported @SuppressWarnings(“compareIdentical”) warning!) I know that I can always use but that’d be more warning-suppression than I want. FWIW, I got the “compareIdentic…
Jackson JSON do not wrap attributes of nested object
I’ve got following classes: When I serialize Container class using Jackson I get But I need the result to be: Is it possible (without adding Container.getDataId() method)? If so, how to do it? update I’ve tried to create custom JsonSerializer<Data> but the result was same as before I’v…
Read a Environment Variable in Java with Websphere
I’ve a little problem with Websphere application server 7.0 (WAS7) and the reading of Environment Varaibles. With TomCat, I’ve defined a variable as and I read it with a lookup on the initialContext : and it works! But with Websphere, I define a environment variable on the GUI but I can’t re…