I use the following line of code to have Adobe Reader print my generated PDF: It always uses the standard printer. Is there a way to display the “choose printer” dialog instead? Answer http://download.oracle.com/javase/tutorial/2d/printing/dialog.html
Tag: java
Java : list that contains unique elements in order
Is there a list type in java that stores objects in ascending order and not adds if this object is previously added. I know java maps can do that but I wonder if there is a list type that does what I want. Otherwise I have to override contains, equalsTo and add methods,right? Answer So you need a list contain…
How to find the index of an element in a TreeSet?
I’m using a TreeSet<Integer> and I’d quite simply like to find the index of a number in the set. Is there a nice way to do this that actually makes use of the O(log(n)) complexity of binary trees? (If not, what should I do, and does anyone know why not? I’m curious why such a class wou…
Java method to save current state of a program
Is it possible to save the current state of a java program and then reload it? The program is fairly complicated. I just need to be able to save the current state to a file and then reload it. Could you please refer me to a java library or a place to read more about that from. Answer There is
How can I get a Spring bean in a servlet filter?
I have defined a javax.servlet.Filter and I have Java class with Spring annotations. I want to get the bean UsersConnectionRepository in my Filter, so I tried the following: But it always returns null. How can I get a Spring bean in a Filter? Answer Try: Where usersConnectionRepository is a name/id of your be…
Abstraction frameworks to work with NoSQL databases
There are popular frameworks out there such as MyBatis (former iBatis), and Hibernate to work with relational databases. Can I get some advice from the community on whether are there such frameworks …
Using a synchronizedSet to synchronize access between two threads
I’m not able to synchronize two threads using a set: and passing it to two threads. One accessing: and another updating: What happens is that [1], [2], [3] happens in sequence. During [1], it is correct that the set doesn’t have yet the item I’m looking for. But then [2] updates it by adding…
How can I convert ZipInputStream to InputStream?
I have code, where ZipInputSream is converted to byte[], but I don’t know how I can convert that to inputstream. Answer Here is how I solved this problem. Now I can get single files from ZipInputStream to memory as InputStream.
JPA: DELETE WHERE does not delete children and throws an exception
I am trying to delete a large number of rows from MOTHER thanks to a JPQL query. The Mother class is defined as follows: As you can see, the Mother class has “children” and when executing the following query: an exception is thrown: Of course, I could first select all the objects I want to delete …
Synchronized keyword and static classes in java
I was reading a threading tutorial that’s originally from (I believe) the IBM developerworks site. In it they talked about the synchronized keyword and how a synchronized block of code is locked by the actual object, not the block of code itself. For instance, in the code below the authors state that even tho…