java

Configure a Java Socket to fail-fast on disconnect?

Hi, I have a listening port on my server that I'm connecting to using a Java class and the Socket interface, i.e. Socket mySocket = new Socket(host,port); I then grab an OutputStream, decorate with a PrintWriter in autoflush mode and I'm laughing - except if the listening port closes. Then I get tcp4 0 0 *.9999 ...

Drag and Drop an Email from MS Outlook to Eclipse RCP

Has anyone got a working solution without some Java/COM-bridge? E.g. process the Email as a file (.msg) rather than locating the data that is referenced in the Clipboard? ...

Libraries for pretty charts in SWT?

I know the following libraries for drawing charts in an SWT/Eclipse RCP application: Eclipse BIRT Chart Engine (Links to an article on how to use it) JFreeChart Which other libraries are there for drawing pretty charts with SWT? Or charts in Java generally? After all, you can always display an image... ...

Best method to parse various custom XML documents in Java

What is the best method to parse multiple, discrete, custom XML documents with Java? ...

Painting javax.microedition.lcdui.Graphics on LWUIT Component

What would be the best method for getting a custom element (that is using J2ME native Graphics) painted on LWUIT elements? The custom element is an implementation from mapping library, that paints it's content (for example Google map) to Graphics object. How would it be possible to paint the result directly on LWUIT elements (at the mom...

Are there any alternatives to Gigaspaces?

Anything thats as good and as stable and as feature-rich as gigaspaces? ...

How Best to Compare Two Collections in Java and Act on Them?

I have two collections of the same object, Collection<Foo> oldSet and Collection<Foo> newSet. The required logic is as follow: if foo is in(*) oldSet but not newSet, call doRemove(foo) else if foo is not in oldSet but in newSet, call doAdd(foo) else if foo is in both collections but modified, call doUpdate(oldFoo, newFoo) else if !foo...

Colorizing images in Java

I'm working on some code to colorize an image in Java. Basically what I'd like to do is something along the lines of GIMP's colorize command, so that if I have a BufferedImage and a Color, I can colorize the Image with the given color. Anyone got any ideas? My current best guess at doing something like this is to get the rgb value of eac...

How I hide empty Velocity variable names ?

I am using Struts + Velocity in a Java application, but after I submit a form, the confirmation page (Velocity template) shows the variable names instead an empty label, like the Age in following example: Name: Fernando Age: {person.age} Sex: Male I would like to know how to hide it! ...

Best method to get objects from a BlockingQueue in a concurrent program?

What is the best method to get objects out of a BlockingQueue, in a concurrent program, without hitting a race condition? I'm currently doing the following and I'm not convinced it is the best method: BlockingQueue<Violation> vQueue; /* in the constructor I pass in a BlockingQueue object full of violations that need to be processed -...

Java Annotations

What is the purpose of annotations in Java? I have this fuzzy idea of them as somewhere in between a comment and actual code. Do they effect the running of a program?? What are typical usages for them? Also, are they unique to Java, is there a C++ equivalent? ...

Reading model objects mapped in Velocity Templates

Hello, I have a Struts + Velocity structure like for example, a Person class, whose one property is a Car object (with its own getter/setter methods) and it is mapped to a Velocity form that submits to an Action, using ModelDriven and getModel structure. I what to put a button on the form that shows "View Car" if car property is not nu...

Best Practice: Initialize class fields in constructor or at declaration?

I've been programming in C# and Java recently and I am curious what people would consider the best practice concerning when you should initialize your classes fields? Should you do it at declaration?: public class Die { private int topFace = 1; private Random myRand = new Random(); public void Roll() { // .... ...

What Web Application Framework for Java is Recommended?

I am considering creating my own website using Java and am trying to decide what framework to use. However, doing a quick search for Java frameworks returns more than 50 to choose from! My website is just going to be for my own enjoyment of building it in the beginning, but if it becomes popular it would be good for it to have some scala...

J2EE - DAO DVO

I have seen two ways of implementing DAO-DVO design. 1) DVO are objects and DAOs are instantiated using factories i.e DAOs are also objects 2) DVOs are again objects but in this case, DAOs are classes which contain only static methods which accept DVOs to perform tasks. I was wondering which way is better and more scalable thanx in ad...

Best regex to catch XSS (Cross-site Scripting) attack (in Java)?

Jeff actually posted about this in Sanitize HTML. But his example is in C# and I'm actually more interested in a Java version. Does anyone has a better version for Java? Does his example is good enough that I could just convert it directly from C# to Java? [Update] I have put a bounty on this question because SO wasn't as popular as to...

Is it essential that I use libraries to manipulate xml?

I am using java back end for creating an xml string which is passed to the browser. Currently I am using simple string manipulation to produce this xml. Is it essential that I use some xml library in java to produce the xml string? I find the libraries very difficult to use compared to what I need. ...

Why can't I explicitly pass the type argument to a generic Java method?

I have defined a Java function: static <T> List<T> createEmptyList() { return new ArrayList<T>(); } One way to call it is like so: List<Integer> myList = createEmptyList(); // Compiles Why can't I call it by explicitly passing the generic type argument? : Object myObject = createEmtpyList<Integer>(); // Doesn't compile. Why? ...

I Am Not Getting the Result I Expect Using readLine() in Java

I am using the code snippet below, however it's not working quite as I understand it should. public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; try { line = br.readLine(); while(line != null) { System.out.println(line); line = br.readLine(); ...

Java SWIFT Library

I'm looking for a Java library for SWIFT messages. I want to parse SWIFT messages into an object model validate SWIFT messages (including SWIFT network validation rules) build / change SWIFT messages by using an object model Theoretically, I need to support all SWIFT message types. But at the moment I need MT103+, MT199, MT502, MT509...