java

Why doesn't more Java code use PipedInputStream / PipedOutputStream ?

I've "discovered" this idiom recently, and I am wondering if there is something I am missing. I've never seen it used. Nearly all Java code I've worked with "in the wild" favors slurping data into a string or buffer, rather than something like this example (using HttpClient and XML APIs for example): final LSOutput output; // XML st...

Do we need a Java++?

It seems to me that, in some ways, Java is where C was a while back. Both are fairly minimalist languages for their time, with relatively clean, simple cores to build on. (I'm referring to the core language here, not the libraries.) Both are/were extremely popular. Both are/were lingua francas, with tons of legacy code. Both are/wer...

How to lock a file on different application levels?

Here's the scenario: I have a multi threaded java web application which is running inside a servlet container. The application is deployed multiple times inside the servlet container. There are multiple servlet containers running on different servers. Perhaps this graph makes it clear: server1 +- servlet container +- application1 ...

UML Class Diagram Resources

Does anyone have any good resources for refining my skills in developing class diagrams? Would like any strong tutorials in UML 2.0 ideally, but searches seem to be returning poor results. Also currently revising for a final year exam and really want to try and get my teeth into a practice paper with a model answer, I've searched high a...

Does it make sense to rewrite Perl and shell scripts in java?

I have a bunch of scripts - some in perl and some in bash - which are used for: Creating a database (tables, indexes, constraints, views) Parsing spreadsheets and loading the data into the database Getting info about a bunch of files and loading that into the database. These scripts are used in conjunction with a much larger applicat...

How do I read text from a serial port?

I am trying to read data off of a Windows serial port through Java. I have the javax.comm libraries and am able to get some data but not correct data. When I read the port into a byte array and convert it to text I get a series of characters but no real text string. I have tried to specify the byte array as being both "UTF-8" and "US-...

Image rotation algorithm

I'm looking for an algorithm that rotates an image by some degrees (input). public Image rotateImage(Image image, int degrees) (Image instances could be replaced with int[] containing each pixel RGB values, My problem is that i need to implement it for a JavaME MIDP 2.0 project so i must use code runnable on JVM prior to version 1.5 C...

Wrapping a checked exception into an unchecked exception in Java?

I have this factory method in java: public static Properties getConfigFactory() throws ClassNotFoundException, IOException { if (config == null) { InputStream in = Class.forName(PACKAGE_NAME).getResourceAsStream(CONFIG_PROP); config = new Properties(); config.load(in); } return config; } And I want ...

Does closing the BufferedReader/PrintWriter close the socket connection?

I have an application that uses simple sockets to pass some characters between two systems. I have my java application running as a server. I establish a connection fine, and even pass one message. However, after one message has been sent my connection closes. From what I can tell it appears as if on closing the printWriter and buffe...

Hibernate: Transitive persistance of set of objects in an @ManyToMany relationship

I am trying to map the following: public class Person{ ... @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }) @JoinTable(name = "person_categories", joinColumns = @JoinColumn(name = "personId"), inverseJoinColumns = @JoinColumn(name = "categoryId")) private Set<Category> categories ... } public class Category ...

Java/DOM: Get the XML content of a node

Hi there! I am parsing a XML file in Java using the W3C DOM. I am stuck at a specific problem, I can't figure out how to get the whole inner XML of a node. The node looks like that: <td><b>this</b> is a <b>test</b></td> What function do I have to use to get that: "<b>this</b> is a <b>test</b>" ...

Ways to prevent SQL Injection Attack & XSS in Java Web Application

I'm writing a java class which would be invoked by a servlet filter and which checks for injection attack attempts and XSS for a java web application based on Struts. The InjectionAttackChecker class uses regex & java.util.regex.Pattern class to validate the input against the patterns specified in regex. With that said, I have following...

MySQL internationalization with DCM4CHEE

I'm attempting to internationalize dcm4chee (a Java based open source medical imaging storage with system) with MySQL, and have a number of questions. Here's what I know so far 1. I need to change the character set from latin1 to utf8 (to support all the international characters) in the MySQL 2. I'm pretty sure I want to set the collati...

How could I implement autocompletion using Swing?

I'm interested in providing an autocompletion box in a JFrame. The triggering mechanism will be based on mnemonics (I think), but I'm not really sure what to use for the "autocompletion box" (I would like results to be filtered as the user presses keys). How would you implement this? Some sort of JFrame, or a JPopupMenu? I would like ...

Java applet using web services over ssl

I need to have my java applet use a soap based web service over ssl. I know that you can have a servlet act as a go-between/proxy, but I want to have the applet use the web service directly over SSL. The problem is supplying the certs to the web server hosting the web services. I supplied these Java Applet Runtime Settings via the Java C...

Why would my java program send multicast packets with a TTL of 1?

I have a java client program that uses mdns with service discovery to find its associated server. After much testing on a single network with Windows, Fedora 10, and Ubuntu 8.10, we delivered a test build to a customer. They report that the client and server never connect. They sent us a wireshark capture that shows the mdns packets h...

How do you handle Socket Disconnecting in Java?

Hey all. I have a server written in java using the ServerSocket and Socket classes. I want to be able to detect and handle disconnects, and then reconnect a new client if necessary. What is the proper procedure to detect client disconnections, close the socket, and then accept new clients? ...

JDBC Connection Issue

I have create a getDBConnection method in my Java application. This returns a connection object, and hence I haven't closed this connection in this method itself. Now, I am invoking this method from various methods in my application at regular intervals, and closing them inside a try - finally block. I thought this should free up the c...

Building a data layer using Spring JdbcTemplate

Do you know of any resources that describe building a data access layer using Spring's JdbcTemplate classes? I'm looking for something beyond the basics described in the Spring framework documentation. ...

Is jdbc by itself compatible with mysql.

I'd like to know if jdbc by itself is compatible with mysql or do I have to intsall something extra? I was told it is not compatible and that I'd have to use a different database. ...