java

Handling Multiple Exceptions within a Method

I am currently working on the maintenance of a piece of code that is a little bit "Exception Happy." Basically, ever method or anything throws Exception. I'm going to work to take care of that, but, in the meantime, I am wondering what is the best way to handle individual exceptions within a smaller block of code, such as a method. Is...

Send Ctrl-C to process open by java

Under Windows OS. I start a sub-process via a Runtime.getRuntime().exec(); I want to send a "ctrl-c" to the process. I did a small example , with Runtime.getRuntime().exec("ping google.com -n 100000"); The code can be found there : http://pastebin.com/f6315063f So far, I tried to send the char 3 (ctrl-C character) via Process outputSt...

What is a sensible prime for hashcode calculation?

Eclipse 3.5 has a very nice feature to generate Java hashCode() functions. It would generate for example (slightly shortened:) class HashTest { int i; int j; public int hashCode() { final int prime = 31; int result = prime + i; result = prime * result + j; return result; } } (If ...

Simple formatting question in Java using printf

I have an array of 12 numbers int ary2[] = {3,5,9,11,15,18,22,23,30,31,35,39}; I want to print the numbers out with 2 places for the number and a space between the numbers. Example print out would be : 3 5 9 11 15 18 22 23 30 31 35 39 This is how far I got. for(int i = 0; i < ary2.length; i++) { System.out.printf("%-3s"...

Override fillInStackTrace for control flow / performance.

Note: although seemingly similar, this is not a duplicate of http://stackoverflow.com/questions/1520859/overriding-fillinstacktrace-for-a-standard-jvm-exceptions What are your thoughts on overriding fillInStackTrace on checked exceptions to return null? The advantages are: you can use said exception for control flow without the perfo...

Is there an easy way to reduce the number of colors in an IndexedColorModel?

I have a large 8-bit PNG image. I am using Java to slice the image into smaller 32x32 images. I use Java's ImageIO to load the PNG into a BufferedImage and then call it's getSubimage(x, y, 32, 32). I then use ImageIO to write each tile out as a PNG. The problem is that the resulting image has the same IndexColorModel as the original ...

Resizing a JFrame.

Ok, this will be rather noobish - I'm making a GUI with the Eclipse Visual Editor (a JFrame with stuff in it), basically on the left side there are some buttons and textfields etc. and the right side contains 4 JPanels (with some graphics in them). The problem is, when I resize the gui (the JFrame) during runtime the components inside s...

What is the future of GlassFish ESB / Open ESB

With the merger of SUN and Oracle: What is the future of Open ESB a.k.a. GlassFish ESB? Is this a product which will be discontinued as Oracle has Oracle Service Bus (was BEA AquaLogic Service Bus)? ...

Java no name static method

What is this? public class ABC { public ABC() { System.out.println("world"); } static { System.out.println("hello"); } } Will print: hello world I don't really understand this, or what kind of method that static code is. ...

Watij Replacement

Does anyone know of a good replacement to Watij which will allow automated tests to be written in Java? It looks like the Watij library isn't being developed anymore. ...

Generics Question

Can anyone explain the problem with this? The 'foo' class fails to compile with an 'incompatible types' error. If you replace 'UniqueList' with 'ArrayList', it works correctly, even though UniqueList is an unmodified subclass of 'ArrayList'. 'Column' is a class defined in the app, and I don't see how its details would matter. public cla...

Which Maven Glassfish plugin to use?

I've been trying to integrate deploying java .war's in Glassfish V3 through Maven. While I have found a few plugins, none of them look to be very active: Maven Glassfish Plugin Eskato's Wordpress Blog on Maven And I got the most information out of Eskato's Blog, it was written March 2008, so I don't know what the state of Glassfish ...

Bad form for JUnit test to throw exception?

Hi. I'm pretty new to JUnit, and I don't really know what best practices are for exceptions and exception handling. For example, let's say I'm writing tests for an IPAddress class. It has a constructor IPAddress(String addr) that will throw an InvalidIPAddressException if addr is null. As far as I can tell from googling around, the test...

gwt hosted mode hangs on connecting to 127.0.0.1

hi all, i am using gwt for a while (pretty nice and useful thing) when i run the hosted mode i am getting the hosted browser window, and it hangs on "connecting to 127.0.0.1", only after few tires it works well. anyone encountered this behavior? please advise oops forgot to mention that i am using windows XP, GWT 3.5, and eclipse ...

How to draw circle on JPanel? Java 2D

I have a JPanel for which I set some image as the background. I need to draw a bunch of circles on top of the image. Now the circles will be positioned based on some coordinate x,y, and the size will be based on some integer size. This is what I have as my class. import java.awt.Dimension; import java.awt.Graphics; import java.awt.Imag...

Obtaining clients IP address in GWT and Google App Engine

I have a need to capture IP address of the client in my GWT/GAE (Java) application. Since GAE does not support full set of java.net APIs I cannot do code such as snippet below. Can anyone suggest reliable way of achieving the same? for (final Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(...

xpath not recognized in selenium, but is recognized in XPather

I have the following code in my script: System.out.println(selenium.getAttribute("xpath=//div[@class='guest clearfix'][1]/@id")); When I try to run the script, it says the element is not found. If I enter the xpath into XPather (addon for firefox) //div[@class='guest clearfix'][1]/@id, it will correctly give me the id. I am stumped ...

Possible to sit on the network and receive a TCP stream/UDP datagrams?

Has anyone out there done the work of sitting on top of a packet capture interface (like jpcap) with an implementation of UDPSocket (for UDP datagrams) and InputStream (for TCP streams)? I suppose it wouldn't be too hard to do given the callback API in jpcap, but has anyone out there already done it? Are there any issues with doing this...

Is there a way to get raw http request stream from Java servlet handler?

I am trying to put some logging to capture the raw http request coming to my application. My Java code is inside a SpringMVC controller. I have access to the "HttpServletRequest" object. But I could not find a way to get the raw http request stream out of it. There is a reader but only reads the post content. What I want is the whole she...

Machine learning challenge: diagnosing program in java/groovy (datamining, machine learning)

Hi All! I'm planning to develop program in Java which will provide diagnosis. The data set is divided into two parts one for training and the other for testing. My program should learn to classify from the training data (BTW which contain answer for 30 questions each in new column, each record in new line the last column will be diagnos...