java

Java memory puzzle

Suppose I have following code package memoryleak; public class MemoryLeak { public static int size; static { size = (int) (Runtime.getRuntime().maxMemory()*0.6); } public static void main(String[] args) throws InterruptedException { { byte[] data1 = new byte[size]; } byte[...

Is there a way to specify data-sources.xml file to be included in EAR using maven?

First some background information: We have three environments for our EJB3 application: test, development and production. All require database settings of their own. We use maven2. Data source settings are placed in ear project, directory /src/main/application/META-INF/data-sources.xml. File contains attributes for three different conn...

Convert a String to Number - Java

Hi, What is the easiest and correct way to convert a String number with commas (for example: 835,111.2) to a Double instance. Thanks, Rod ...

Print text File to specific printer in java

Hi, My need is terribly simple and yet I can' figure out a simple way to do it. I have a text file, and I need to print it to a specific network printer. I know the name of the printer. Until now I have made a Printable class to print my file (ticket). public class TicketPrintPage implements Printable { private File ticket; ...

Java Swing revalidate() vs repaint()

I'm putting together a Swing application where I often want to replace the contents of a JPanel. To do this, I'm calling removeall(), then adding my new content, then calling revalidate(). However I'm finding that the old content is still actually visible (though obscured by the the new content). If I add a call to repaint() in addition...

Best practices for catching Throwable in Java

Sometimes, you just have to catch Throwable, e.g. when writing a dispatcher queue that dispatches generic items and needs to recover from any errors (said dispatcher logs all caught exceptions, but silently, and then execution is continued on other items). One best practice I can think of is to always rethrow the exception if it's Inter...

java print api - printing JComponent at 300dpi

please tell me if I am doing something wrong. I want to print barcodes onto labels, so I need high quality printout for these barcodes so I am pushing printer to print in 300dpi. What I've done: made a big JFrame; width: 2490px, height: 3515px so it represents A4 paper in 1:1 measure (this is A4 paper resolution if print is to be 300...

Rethrowing exceptions in Java

In C#, I can use the throw; statement to rethrow an exception while preserving the stack trace: try { ... } catch (Exception e) { if (e is FooException) throw; } Is there something like this in Java (that doesn't lose the original stack trace)? ...

AutoIt for Java

I need to automate UI testing of a software that my module is plugged in. I do not have an access to code of the host so I need something like AutoIt. Since AutoIt does not work with Swing, is there any AutoIt like GUI automation tool for JAVA based applications? ...

Eclipse 3.5 is generating a "method not applicable for the arguments" error for no reason at all.

The error is this: The method add(String, int) in the type DataNode is not applicable for the arguments (String, String) However, in the DataNode class, I have a number of overloaded add() methods, including one that takes a String and an int and one that takes two Strings. It appears that Eclipse isn't "seeing" the right add() met...

Where do I download a Java 6 JDK for Linux?

May be I am getting old, but I can't find it... ...

IllegalArgumentException... no ':' in url exception

no ':' in url exception am getting that exception when am trying to execute this fragment of code... FileConnection conn; try{ conn =(FileConnection)Connector.open("/NewFile.xml"); if(!conn.exists()) conn.create(); _screen.add(new RichTextField("Connection Established...")); _screen.add(new SeparatorField()); }...

"Not enough storage is avaliable to process this command"

Hello; When my program runs, following error was taken: Excepiton in theard "AWT -EventQueue -1" java.lang.UnsatisfiedLinkError: program.dll: Not enough storage is avaliable to process this command [java] at java.lang.ClassLoader$NativeLibrary.load<Native Method> [java] at java.lang.ClassLoader.loadLibrary0<ClassLoader.java:1751> [jav...

string to hex value

Is there any java utility to convert string to hex value (integer) ? ...

Java reflection: Is the order of class fields and methods standardized?

Hello! Using reflection on Java classes to access all field, methods, and so on: Is there a standardized order of these elements (which is specified in some standard)? Of course, I could check it empirically, but I need to know if it's always the same. EDIT: I waited for the question: What I need the order for ;) Long story short: I h...

Using a variable instead of a parameter index with a JDBC prepared statement.

Hi. In many programming languages something like this is possible for prepared statements: PreparedStatement statement = connection.prepareStatement( "SELECT id FROM Company WHERE name LIKE ${name}"); statement.setString("name", "IBM"); But not with java.sql.PreparedStatement. In Java one has to use parameter indices: PreparedSt...

Issue with IE security on page opened from javascript

I have a Java web application running in JBOSS with Tomcat with two web applications (contexts) running on it. A button press on one of the applications opens runs a javascript command to open a new window with a page from the other. The problem I seem to be having is that this raises a security alert in IE. with the following message:...

How can I assign 2 bytes to a variable in Java?

How can I assign 2 bytes to a variable in Java? I know I can do this: byte val = 2; // this is one byte with 0000 0010 But I need to assign 2 bytes to val. How can I do this? ...

Can one do a for each loop in java in reverse order?

I need to run through a List in reverse order using Java. So where this does it forwards: for(String string: stringList){ //...do something } Is there some way to iterate the stringList in reverse order using the for each syntax? For clarity: I know how to iterate a list in reverse order but would like to know (for curiosity's sake...

Java implementation for Min-Max Heap?

Do you know of a popular library (apache collections, google collections, etc...) which has a reliable Java implementation for a Min-Max heap? I.e. a heap which allows to peek at its minimum and maximum value in O(1) and to remove at O(logn). I did a quick search and couldn't find one. Anyone know better? ...