Skip to content
Advertisement

Tag: java

How can I find the response time of a HTTP request through a Socket

I’m using a Java socket, connected to a server. If I send a HEADER http request, how can I measure the response time from the server? Must I use a provided java timer, or is there an easier way? I’m looking for a short answer, I don’t want to use other protocols etc. Obviously do I neither want to have

How to create a windows service from java app

I’ve just inherited a java application that needs to be installed as a service on XP and vista. It’s been about 8 years since I’ve used windows in any form and I’ve never had to create a service, let alone from something like a java app (I’ve got a jar for the app and a single dependency jar – log4j).

Does a finally block always get executed in Java?

Considering this code, can I be absolutely sure that the finally block always executes, no matter what something() is? Answer Yes, finally will be called after the execution of the try or catch code blocks. The only times finally won’t be called are: If you invoke System.exit() If you invoke Runtime.getRuntime().halt(exitStatus) If the JVM crashes first If the JVM reaches

How to convert a date String to a Date or Calendar object?

I have a String representation of a date that I need to create a Date or Calendar object from. I’ve looked through Date and Calendar APIs but haven’t found anything that can do this other than creating my own ugly parse method. I know there must be a way, does anyone know of a solution? Answer In brief: See SimpleDateFormat

How to generate a random alpha-numeric string

I’ve been looking for a simple Java algorithm to generate a pseudo-random alpha-numeric string. In my situation it would be used as a unique session/key identifier that would “likely” be unique over 500K+ generation (my needs don’t really require anything much more sophisticated). Ideally, I would be able to specify a length depending on my uniqueness needs. For example, a

Checking the results of a Factory in a unit test

I have developed some classes with similar behavior, they all implement the same interface. I implemented a factory that creates the appropriate object and returns the interface. I am writing a unit test for the factory. All you get back is an interface to the object. What is the best way to test that the factory has worked correctly? I

Advertisement