java

Making a personal programming toolbox

Lately I've been considering creating a sort of "toolbox" for myself in java. It would consist of standard algorithms and data structures that are frequently used, but a pain to implement. (I'm thinking graphs, trees, etc) What would be the best way to do this? I was thinking about either using generics or using an abstract class. This ...

Using Different Hibernate User Types in Different Situations

I am using Hibernate + JPA as my ORM solution. I am using HSQL for unit testing and PostgreSQL as the real database. I want to be able to use Postgres's native UUID type with Hibernate, and use the UUID in its String representation with HSQL for unit testing (since HSQL does not have a UUID type). I am using a persistence XML with dif...

IN java, how a commons-Digester process an input XML file?

I am new to java and I came across a statement in a java project which says: Digester digester = DigesterLoader.createDigester(getClass() .getClassLoader().getResource("rules.xml")); rules.xml file contains various patterns and every pattern has different attributes like classname ,methodname and some another properties. i goog...

What is the difference between '==' and '=' ?

I know that one of them is bitwise and the other is logical but I can not figure this out: Scanner sc = new Scanner(System.in); System.out.println("Enter ur integer"); int x=sc.nextInt(); if(x=0)//Error...it can not be converted from int to boolean System.out.println("..."); The error means that x cannot be converted to boolean or the...

How do I find out the calling class?

how can i find out which class/method has called the actual method? ...

How can I create a war file of my project in NetBeans?

How can I create a war file of my project in NetBeans? ...

Retrieve an image from the web in java

Hi i am trying to read an image that resides somewhere on the web from my Java program. So far i have successfully loaded an image by using the following code. URL url = new URL("http://www.google.com/images/nav_logo4.png"); Image img = Toolkit.getDefaultToolkit().getImage(url); What i want to know is why this code (which is the first...

Communication problem between Java and C++ app on stdin

I have a java app here that starts a C++ app via the java.lang.Process API and then tries to send commands to it via the stdin pipe: process.getOutputStream().write("foo\n"); process.getOutputStream().flush(); On the C++ side there's a loop running that checks for input in stdin and if there is some it reads it. Unfortunately the che...

What do these three special floating-point values mean: positive infinity, negative infinity, NaN?

How can we use them in our codes, and what will cause NaN(not a number)? ...

Using UNINSTALL_SHORTCUT Intent

I am trying to use the following intent action, but i get an ActivityNotFoundException in the fisrt case. And nothing at all in the second case. "com.android.launcher.action.UNINSTALL_SHORTCUT" I try to use it with the following code: Intent i = new Intent ("com.android.launcher.action.UNINSTALL_SHORTCUT"); startActivity(i); Also wi...

Floating Rectangle on Screen

I know how to draw a rectangle onto a JPanel, but how can I paint a rectangle to the screen so that the rectangle appears to be floating? More specifically, a non-filled rectangle. My thought is to use a transparent JFrame with a rectangle drawn on it; however, this makes all of the content in the JFrame transparent. My Solution S...

Java date format to JavaScript date format

Hi, I would like to be able to convert a Java date format string, e.g. dd/MM/yyyy (07/06/2009) to a JavaScript date format string, e.g. dd/mm/yy (07/06/2009). Has anyone done this before, or got any idea where I might find some code that already does this? Thanks in advance. Edit: Thanks for all the replies but now I realise my mis...

How to set height of SWT List in rows?

I have a class based on Composite that embeds an SWT List instance. Using the default settings, the list is five rows high on my WinXP system. Without relying on hard-coded pixel values or DPI settings and the like, how can I set the height of the list (and the surrounding composite) to a fixed number of rows, say 3, without any added in...

AspectJ - Compile Java source with precompiled aspects

Let's say I have few aspects, which I have already compiled, and now I just want to compile single source file, but without recompiling the aspects, since it takes a lot of time. Is there any way to do so? For example, I have the following: Trace.aj Log.aj Test.java All of them were compiled during my "build-all", and now I've chang...

XAResource.end called without calling start

Saw this in our logs on an internal test cluster: "java.lang.RuntimeException: Got exception during XAResource.end : org.postgresql.xa.PGXAException: tried to call end without corresponding start call" I've had some previous issues with getting XA transactions running smoothly under Glassfish 2.1 in a clustered deployment. Those arose...

Image not displaying in JTable (Java Swing)

Hi I have created the following code. The problem is the image is not displaying in the JTable column. I extend the DefaultTableModel and override the method getColumnClass. It was suggested this was one way to do it. Any clues? the code is below. //package javaapplication12; import javax.swing.*; public class NewJFrame2 extends...

How to serialize static data members of a Java class?

When we serialize objects, static members are not serialized, but if we need to do so, is there any way out? ...

Different log4j layout for debug and error?

In log4j, is there a way to have logger.error("") and logger.debug("") include different output layouts? I'd like errors to include method names and line numbers, both of which slow down application performance. EDIT: After adding apache-log4j-extras, the following config file works. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE...

JPA/Hibernate Query Returns Stale Results

I am using an EXTENDED Persistent Context because it will allow me to Lazily Load a one-many relationship on an object and it also won't require a SELECT before I "merge" an object with the persistent context. I have an DummyObject with: A "Last Updated" Date Field A One-Many Relationship This Object is being updated every 5 seconds...

SwingWorker cancellation with ThreadPoolExecutor

Hi, i am using a ThreadPoolExecutor with a thread pool size of one to sequentially execute swing workers. I got a special case where an event arrives that creates a swing worker that does some client-server communication and after that updates the ui (in the done() method). This works fine when the user fires (clicks on an item) some ev...