Skip to content

Tag: java

JUnit: testing helper class with only static methods

I am testing a helper class with only static methods with JUnit4 and Cobertura. Testing methods was easy task and is done already. However, cobertura shows that the class is not covered by tests completely, as it is not instantiated anywhere. I don’t want to create an instance of this class (it is a hel…

android – How to detect application being activated

When the app is launched, Application onCreate is called. How to detect when the app is brought to front from running in background? Answer Look for onResume() method. Its is always called when your app comes foreground. As per google docs: The foreground lifetime of an activity happens between a call to onRe…

Get domain name from given url

Given a URL, I want to extract domain name(It should not include ‘www’ part). Url can contain http/https. Here is the java code that I wrote. Though It seems to work fine, is there any better approach or are there some edge cases, that could fail. Input: http://google.com/blah Output: google.com A…

Setting socket read timeout with javax.xml.soap.SOAPConnection

I am using the javax.xml.soap API (javax.xml.soap.SOAPConnectionFactory, javax.xml.soap.SOAPConnection, and friends) to make a web service call to a remote server, for the most part with great success. However, sometimes there is a problem and the program gets stuck reading forever. To address this, I’d…

Trouble understanding Java threads

I learned about multiprocessing from Python and I’m having a bit of trouble understanding Java’s approach. In Python, I can say I want a pool of 4 processes and then send a bunch of work to my program and it’ll work on 4 items at a time. I realized, with Java, I need to use threads to achiev…