Skip to content

Where to store application data (non-user specific) on Linux

In my OSGi-based Java application I am developing a bundle to provide the rest of the system with access to the file system. In addition to providing access to the user home directory, I also wish to provide access to a non-user specific area. Exactly what this area will be used for is as yet undetermined, bu…

Why is list.size()>0 slower than list.isEmpty() in Java?

Why is list.size()>0 slower than list.isEmpty() in Java? On other words why isEmpty() is preferable over size()>0? When I look at the implementation in ArrayList, then it looks like the speed should be the same: ArrayList.size() ArrayList.isEmpty() If we just write a simple program to get the time take …

Easy way of running the same junit test over and over?

Like the title says, I’m looking for some simple way to run JUnit 4.x tests several times in a row automatically using Eclipse. An example would be running the same test 10 times in a row and reporting back the result. We already have a complex way of doing this but I’m looking for a simple way of…

UTF-16 to ASCII conversion in Java

Having ignored it all this time, I am currently forcing myself to learn more about unicode in Java. There is an exercise I need to do about converting a UTF-16 string to 8-bit ASCII. Can someone please enlighten me how to do this in Java? I understand that you can’t represent all possible unicode values…

Write a binary downloaded file to disk in Java

I have a software that allow to write add-on in javascript files (.js) that allow to use Java function (I don’t know if this is common, I never saw java call in javascript file before) I need to download a binary file from a webserver and write it to the hard drive. I tried the following code: The resul…

Singleton Design Pattern: Pitfalls [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago. Improve this question Not sure of downfalls using strict global state implementation. When is si…

Java double initialization

In what way are these statements different? double dummy = 0; double dummy = 0.0; double dummy = 0.0d; double dummy = 0.0D; Answer Having tried a simple program (using both 0 and 100, to show the difference between “special” constants and general ones) the Sun Java 6 compiler will output the same …

How do I make HttpURLConnection use a proxy?

If I do this… it prints The problem is, I am behind a proxy. Where does the JVM get its proxy information from on Windows? How do I set this up? All my other apps seem perfectly happy with my proxy. Answer Since java 1.5 you can also pass a java.net.Proxy instance to the openConnection(proxy) method: If…