java

Regex look-behind without obvious maximum length in Java

I always thought that a look-behind assertion in Java's regex-API (and many other languages for that matter) must have an obvious length. So, STAR and PLUS quantifiers are not allowed inside look-behinds. The excellent online resource regular-expressions.info seems to confirm (some of) my assumptions: "[...] Java takes things a step...

How to perform a method on each object of a multi-dimensional array, directly on the array?

I'm writing a simple Java 2D game, displaying a grid. The grid is (for the moment) a simple 2 dimensional array of specific game cells: int height = 10; int width = 10; MyObject[][] table = new MyObject[height][width]; Often, I have to perform a specific method of my object over the full table: for(int y = 0; y < height; y++) { f...

SynchronousQueue fairness

Hi I'm using a 1producer-1consumer design in my app using a SynchronousQueue. By now, I'm using it with the default constructor (fair=true). And I'm wondering about how "fair=false" would affect to the system (performance and specially concurrency behaviour). Here what the docs tell: SynchronousQueue public SynchronousQueu...

Recommend a fast & scalable persistent Map - Java

I need a disk backed Map structure to use in a Java app. It must have the following criteria: Capable of storing millions of records (even billions) Fast lookup - the majority of operations on the Map will simply to see if a key already exists. This, and 1 above are the most important criteria. There should be an effective in memory ca...

displaying large SQLite tables in SWT

I am trying to display a large SQLite table in SWT. The problem is that SQLite's ResultSet does not support TYPE_SCROLL_INSENSITIVE which is needed when using the Listener approach. Is there a different approach for creating a virtual SWT table from an SQLite ResultSet? ...

OutOfMemoryError in a separate Java thread

Consider that I have a main Thread which executes a new Runnable in a new Thread. Now, while the new Thread is executing, the Java VM runs out of memory and throws an OutOfMemoryError. What happens? Does the target thread stop? Will the main thread continue? When the new Thread crashes, will the VM reclaim the memory from it and let exe...

Q: Convert an image form j2me to PCL3 command

Hi all I have spent 1 week of my life trying to print image that i take from graphic object to HP Officejet H470 which support PCL3. I try multi ways but nothing till now. My problem was to print arabic character to this printer but i couldn't becuase the don't support arabic font as i know, so i write arabic character to the graphic of ...

File is not saved in UTF-8 encoding even when I set encoding to UTF-8

When I check my file with Notepad++ it's in ANSI encoding. What I am doing wrong here? OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), "UTF8"); try { out.write(text); out.flush(); } finally { out.close(); } UPDATE: This is solved now, reason for jboss not understand...

IllegalMonitorStateException on wait() call

I am using multi-threading in java for my program. I have run thread successfully but when I am using Thread.wait(), it is throwing java.lang.IllegalMonitorStateException. How can I make a thread wait until it will be notified? ...

What pattern should I use for using a SAX parser?

<xml> <Office prop1="prop1" prop2="prop2"> <Version major="1" minor="0"/> <Label>MyObjectA</Label> <Active>No</Active> </Office> <Vehicle prop="prop"> <Wheels>4</Wheels> <Brand>Honda</Brand> <Bought>No</Bought> </Vehicle> </xml> My XML is in this format. I am using a SAX parser to parse this file as the size of ...

How to convert XML to java.util.Map and vice versa

I'm searching a lightweight API (preferable single class) to convert a Map<String,String> map = new HashMap<String,String(); to xml and, vice versa, convert the XML back to a Map. example: Map<String,String> map = new HashMap<String,String(); map.put("name","chris"); map.put("island","faranga"); MagicAPI.toXML(map,"root"); result...

How can I prevent a package-private interface appearing in Javadoc?

I've got a class like this: package org.jjerms.thing; interface IThing { void doSomething(); } final class Thing implements IThing { /** * This Javadoc pretends (to users outside the package) * that doSomething originates here. */ public void doSomething() { // some code... } } And when I l...

Creating batch updates from within Java

I want to update every row on a specific column in a mySql database. Currently I am using a java.sql.PreparedStatement for each row and iterating in a for loop. I was wondering if there were any other alternatives in terms of Java programming to make this less time and resource consuming (something like executing the prepared statements ...

Pattern to model a business object in Seam framework ?

Hi, I habe been studying Seam framework for a long time. Altough i do not use it at work, i like its approach. It is very interesting. But i have some doubts. After reading Seam in Action book, i think it is not possible you bind more than one parameter to a business method. Something like @Stateless public class BusinessObjectImpl imp...

Java references values are addresses values?

When I do: int x[] = new int[2]; System.out.println("...> " + x); the output value is like this: [I@1b67f74 so that hex number is concerning to the memory address where the object has been allocated? and [I what does it meaning? ...

Shared Business Rules for c# and Java objects

I've got a system that has Java server side objects and C# client objects. The objects can be modified in both sides of the system and so have business rules attached to them. The thing is currently the business rules only live on the server side, and I really want to avoid having to contact the server every time I want to verify the o...

Strange Problem of Having TEST as selectedFile in JFileChooser

I face the following strange problem while using JFileChooser package sandbox; import java.io.File; import javax.swing.JFileChooser; /** * * @author yccheok */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { final JFileChooser chooser = new JFile...

shutdown / undeploy tomcat from Servlet

I have an init servlet in Tomcat that loads critical data. soemtimes it is necessary to abort startup on certain errors. how do i gracefully shutdown the deployed app/ the whole app server without calling System.exit(1) i want to avoid calling the shutdown servlet via port, since this is not configured in my installation. there may b...

asking the container to notify your application whenever a session is about to timeout in Java

Which method(s) can be used to ask the container to notify your application whenever a session is about to timeout?(choose all that apply) A. HttpSessionListener.sessionDestroyed -- correct B. HttpSessionBindingListener.valueBound C. HttpSessionBindingListener.valueUnbound -- correct this is kind of round-about but ...

Netbeans Facelets code completion

Does anyone know how one can enable the code completion for xhtml (facelets) files in Netbeans (6.7.1)? According to some information I found on Google it is a known issue that there is no code completion for xml namespaces as used in the xhtml files, but that should be resolved by installing the netbeans facelets support module. But eve...