java

Do I need to free Swing components before letting them get garbage collected ?

Wnen I use external resources such as files or DB connection I need to close them before I let them go. Do I need to do the same thing with Swing components ? If yes then how ? ...

Java: Memory Allocation For Objects

Please enlighten me. public class SomeObject{ private String strSomeProperty; public SomeObject(String strSomeProperty){ this.strSomeProperty = strSomeProperty; } public void setSomeProperty(String strSomeProperty){ this.strSomeProperty = strSomeProperty; } public String getSomeProperty(){ retur...

Java GUI described in XML

My company currently evaluates the development of a Java FAT client. It should support a dynamic GUI and has as much logic as possible on the server side. Hence the idea came up to send the screen as XML to the FAT client, show it to the user and send the entered data similar to "html form" back in a structure like: <fields> <field ty...

How do I include a DTD in an XML file that will be loaded using getResourceAsStream()?

I have an xml file ('videofaq.xml') that defines a DTD using the following DOCTYPE <!DOCTYPE video-faq SYSTEM "videofaq.dtd"> I am loading the file from the classpath (from a JAR actually) at Servlet initialization time using: getClass().getResourceAsStream("videofaq.xml") The XML is found correctly, but for the DTD in the same pac...

Running Selenium from a Java process

How would you run the Selenium process (thread) from a Java process so I don't have to start Selenium by hand? ...

Putting JVM arguments in a file to be picked up at runtime

I'm building a jar of my current application, which required several JVM arguments to be set. Is there a way of setting these JVM arguments in a file rather than on the command line? I've done some hunting and it looks like I might be able to do something witha java.properties file, possibly by setting a java-args, but I can't find any...

Text file split libraries in Java

My program receives large CSV files and transforms them to XML files. In order to have better performance I would like to split this files in smaller segments of (for example) 500 lines. What are the available Java libraries for splitting text files? ...

Where to close java PreparedStatements and ResultSets?

Consider the code: PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.createStatement(myQueryString); rs = ps.executeQuery(); // process the results... } catch (java.sql.SQLException e) { log.error("an error!", e); throw new MyAppException("I'm sorry. Your query did not work."); } finally { ps.close(); rs.cl...

double to long conversion

In java, what is the best way to convert a double to a long? Just cast? or double d = 394.000; long l = (new Double(d)).longValue(); System.out.println("double=" + d + ", long=" + l); ...

Hibernate group by time interval

I have a table with a timestamp field of type datetime. I need to aggregate the data between a defined start and end time into x groups representing time intervals of equal length, where x is supplied as function parameter. What would be the best way to do this with Hibernate? EDIT: some explanations mysql Table: data_ts: datetime pk...

How to set DPI information in an image?

I have an application that I want to export high-resolution (or rather, high pixel density?) images for printing - for example, I want images that print at 250 dots per inch (DPI), instead of the default, which I understand to be 72 DPI. I'm using a BufferedImage with a Graphics2D object to draw the image, then ImageIO.write() to save t...

threadlocal variables in a servlet

Are the threadlocals variables global to all the requests made to the servlet that owns the variables? I am using resin for the server. Thanks for awnser. I think I can make my self more clear. The specific Case: I want to: initialize a static variable when the request starts the execution. be able to query the value of the vari...

JBoss Monitoring / Profiling

I have a legacy JBoss 4.0.4/EJB 2.1/PostgreSQL system with zillions of "transaction scripted" procedures as server EJB methods, and many of them have very slow and clumsy execution times due to bad programming practices (like creating temporary tables everytime, etc). Is there something I can plug in JBoss (Aspect-Like) to monitor the e...

Using java to encrypt integers

Hi all, I'm trying to encrypt some integers in java using java.security and javax.crypto. The problem seems to be that the Cipher class only encrypts byte arrays. I can't directly convert an integer to a byte string (or can I?). What is the best way to do this? Should I convert the integer to a string and the string to byte[]? Th...

Java dynamic binding and method overriding

Yesterday I had a two-hour technical phone interview (which I passed, woohoo!), but I completely muffed up the following question regarding dynamic binding in Java. And it's doubly puzzling because I use to teach this concept to undergraduates when I was a TA a few years ago, so the prospect that I gave them misinformation is a little d...

Does Java work with PCF fonts?

I am trying to make IBM jre to use PCF fonts from default X11 installation on my linux box. In particular adobe-helvetica font. I have toyed to modify fontconfig.properties in jre/lib folder but no matter what I do Java seams to use some other fonts. I guess there is some algorithm how java VM tries to link java logical fonts to actual p...

Compiling and Running java in Unix ( coming from Windows )

Ok, this is working on windows. My Java app is running and functioning normally javac -classpath .;ojdbc14.jar -g foo.java java -classpath .;ojdbc14.jar foo However, when I do the same thing on Unix I get this error: ojdbc14.jar: not found What am I doing wrong? I know the ";" is telling my shell that ojdbc14.jar is a new comma...

Vectors in Java, how to return multiple vectors in an object...

I'm working on a java program, and I have several vectors defined and filled (from a file) inside a method. I need to return the contents of all the vectors from the method. I have heard you can put them all in one object to return them. Is that possible, and if so, how? If not, do you have any possible solutions for me? Thanks in a...

Bogus eclipse warning for web.xml: "No grammar constraints (DTD or XML schema) detected for the document."

The top of my web.xml file looks like this: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd" version="2.5"> But I still get the wa...

Persisting Users using Hibernate

I've created a UserObject and RoleObject to represent users in my application. I'm trying to use hibernate for CRUD instead of raw JDBC. I've successfully retrieved the information from the data base, but I can not create new users. I get the following error. org.springframework.web.util.NestedServletException: Request processing fa...