java

JPA Definition of a One-To-Many Relationship with Junction Table

I have a one-to-many relationship modeled using an extra table: create table t1 (id int primary key, name varchar(10) /*...*/); create table t2 (id int primary key, name varchar(10) /*...*/); create table t1_t2 (t1_id int, t2_id int, primary key (t1, t2)); The tables are supposed to model the relationship of one t1 to many t2. What is...

Performance ConcurrentHashmap vs HashMap

How is the performance of ConcurrentHashMap compared to HashMap, especially .get() operation (I'm especially interested for the case of only few items, in the range between maybe 0-5000)? Is there any reason not to use ConcurrentHashMap instead of HashMap? (I know that null values aren't allowed) Update just to clarify, obviously the...

Java: testing thread access to "not thread-safe" methods.

My strategy for threading issues in a Swing Java app is to divide methods in three types: methods that should be accessed by the GUI thread. These methods should never block and may call swing methods. Not thread-safe. methods that should be accessed by non-GUI threads. Basically this goes for all (potentially) blocking operations suc...

Adding "this" reference to Array fails in Java Constructor

I am absolute clueless why the following code keeps throwing NullpointerExceptions. I was not able to understand or debug this (its stripped down code from a larger class)... The code is based on the "Enum Pattern" and I want to keep a List/Map of all "Constants" that are contained in the class (I might be using Reflection for this but ...

How can I remove the first page of a PDF file with Java?

I was thinking about using a library such as PDFBox but I would like your input. SOLUTION With IText public void removeFirstPage(String input_filename, String output_filename) throws DocumentException, IOException { File outFile = new File(output_filename); PdfReader reader = new PdfReader(input_filename); int pages_number...

Including comments in Java regular expressions

I have some complex regular expressions which I need to comment for readability and maintenance. The Java spec is rather terse and I struggled for a long time getting this working. I finally caught my bug and will post it as an answer but I'd be grateful for any other advice on maintaining regexes As an example I want to comment the sub...

Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation?

Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation? Failing that, is there another way to suppress warnings in Visual Studio? ...

GUI for history recorded by Envers

Some time ago we began to record all changes of our EJB3 entities with the help of Envers framework. And now the question is - what GUI can we suggest to users to view this history. The main requirements are: rather easy to implement (cause viewing history is not a service with very high priority) easy for users enough that they will...

Is there any sample example of Webcam integration in java.

I am creating one swing GUI. In which I have to integrate a Web cam.How should I do that ? ...

How to fill a byte array from multiple threads safely?

Is there a way to safely populate a byte array from multiple threads (e.g. first thread fills the first half, the second thread fills the second half using System.arraycopy) without synchronizing on the array itself using Java 6 or 7? The jsr166 related libraries only contain int arrays (AtomicIntegerArray, ParallelIntegerArray). ...

A Question in Layouts

Hi I have a doubt in layouts.I have designed one layout using group layout using addgaps and groups.My Question is whether my design changes with screen size?That is I have designed layout for 15 inches monitor will the layout looks same in bigger size monitor screen? Thank u chaithu ...

Very slow read from DVD in Java and .Net

I noticed in two applications to generate hashes of files, one written in Java and the other in C#, that the performance is horrible when reading from a DVD. I'm using Windows XP SP3. I noticed from the noise, that the drive keeps spinning down after reading a bunch of blocks, causing pauses of a couple of seconds between reads. The str...

How to get/set data of(into) visual components (of winodws programs) programmatically?

Let me clarify the question a bit. I am talking about windows GUI programs. Say a program-window has a dialog box (or a confirm button) asking user input. How can I provide input to that program using my program (written in say C#, Java or Python). Or say, a program window is showing some image in one of its panels. How can I grab that f...

How can I make a multipart/form-data POST request using Java?

In the days of version 3.x of Apache Commons HttpClient, making a multipart/form-data POST request was possible (an example from 2004). Unfortunately this is no longer possible in version 4.0 of HttpClient. For our core activity "HTTP", multipart is somewhat out of scope. We'd love to use multipart code maintained by some other...

Using the NetBeans GUI editor, how can I create a JTextField or JFormattedText field that must be validated against a regular expression?

I have a regular expression (\d{4}\w{3}(0[1-9]|[12][0-9]|3[01])([01][0-9]|2[0-3])([0-5][0-9]){2}) that I need to validate the input of a text field against when the user clicks the OK button or moves the cursor to another field. That I know how to do, writing the code. However, I'm interested in if it's possible to have the NetBeans GUI ...

mysql/jdbc function in out param

So i need to run a jdbc call that is going against a sql server database. CallableStatement cs = conn.prepareCall("{ ? = call " + spName + " ( ?, ?, ?, ?, ? ) }"); So the sql server call is a function that has output parameters. we are using mysql database and it looks like mysql functions don't support functions with out put param...

JSP displaying single and double quotes as symbol

I have a JSP page retrieving data and when single or double quotes are in the text they are displayed as this symbol ”. JSP Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>General</title> </head> <body> <h1> <%= order.getDescription %> </h1> </bod...

Why does this Java regex cause "illegal escape character" errors?

I'm working on a solution to a previous question, as best as I can, using regular expressions. My pattern is "\d{4}\w{3}(0[1-9]|[12][0-9]|3[01])([01][0-9]|2[0-3])([0-5][0-9]){2}" According to NetBeans, I have two illegal escape characters. I'm guessing it has to do with the \d and \w, but those are both valid in Java. Perhaps my synt...

Android Content Provider database leak issue

I am writing a content provider for this application and in my content provider I am opening a database connection, running a query and returning the cursor of results to the calling program. If I close this database connection in the provider, the cursor has no results. If I leave it open, I get "leak found" errors in my DDMS log. What ...

TreeSet Comperator

I used a TreeSet with a self written Comparator. Now when I'm adding elements to the TreeSet and the Comparator's compare methods returns 0, it seems like the TreeSet contains only one of the Object with equal ranking. I didn't see that this behaviour is documented in the javadocs. Maybe I miss something. Can you confirm this behaviour...