I got a AsyncTask that is supposed to check the network access to a host name. But the doInBackground() is never timed out. Anyone have a clue? public class HostAvailabilityTask extends AsyncTask<…
Tag: java
JUnit: @Before only for some test methods?
I have some common set up code that I’ve factored out to a method marked with @Before. However, it is not necessary for all this code to run for every single test. Is there a way to mark it so the @Before method only runs before certain tests? Answer Just move out the tests that don’t need the set…
How is Eclipse Mylyn useful?
In my Eclipse Preferences -> Java -> Editor -> Content Assist -> Advanced settings, I see the following: Java Non-Type Proposals Java Proposals Java Proposals (Task-focused) Java Type Proposals JPA Proposals (is always empty for me) PDE API Tools Proposals (gets skipped when checked in the Content…
How to find the index of an element in an array in Java?
I am looking to find the index of a given element, knowing its contents, in Java. I tried the following example, which does not work: Can anyone please explain what is wrong with this and what I need to do to fix it? Answer In this case, you could create e new String from your array of chars and then
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 …
How to obtain CURDATE() / NOW() on a JPA named query?
I want to do a select from table where date = TODAY, on mysql that would be where date > CURDATE(), how do I do this on a JPA named query? Answer That depends on your JPA provider. Hibernate, for example, supports current_date function:
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…
Encoding/decoding REST path parameters
I am trying to find the best way of getting round a design flaw in a web app I’m helping to support. One part of the service passes a parameter (“myparam”) to a .jsp page, which in turn calls a REST service including our myparam as a path parameter. The design flaw bit is that myparam should…