Let's say I have this entity (for Hibernate):
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
@CollectionOfElements
@IndexColumn("phones_index")
Set<String> phones;
}
For example, I want to get instances of Person where their phones contain "555-1234".
How can I do a ...
Has anyone implement fingerprint recognition system in Java?
...
Hi there,
I want a Servlet to handle requests to files depending on prefix and extension, e.g.
prefix_*.xml
Since mapping on beginning AND end of request path is not possible, I have mapped all .xml requests to my Servlet.
The question now is: how can I drop out of my servlet for XML files not starting with "prefix", so that the reques...
I'm writing a server that is supposed to communicate with some embedded devices. The communication protocol is based on a fixed length header. The problem is I can't get my server to handle sudden disconnects of the devices properly (by "sudden" I mean situations when I just turn the device off). Here is the code for the client thread ma...
Here is the piece of code that I have used for Java 5.0
TreeSet<Integer> treeSetObj = new TreeSet<Integer>( Collections.reverseOrder() ) ;
Collections.reverseOrder() is used to obtain a comparator in order to reverse the way the elements are stored and iterated.
Is there a more optimized way of doing it?
...
Is there a way to say "this method returns this" using Generics?
Of course, I want to override this method in subclasses, so the declaration should work well with @Override.
Here is an example:
class Base {
public Base copyTo (Base dest) {
... copy all fields to dest ...
return this;
}
}
class X extends Base {
...
The Javadoc about String.intern() doesn't give much detail. (In a nutshell: It returns a canonical representation of the string, allowing interned strings to be compared using ==)
When would I use this function in favor to String.equals()?
Are there side effects not mentioned in the Javadoc, i.e. more or less optimization by the JIT co...
Hi!
As I have understood MVC, the logic for the model should also go into model itself - making every object a selfcontained entity. This means that the methods of an class has to have triggers and chains of actions. For example, by using setZipCode(zip) in a Person class could trigger an action where it looks up the zip code from a zip...
I want to port an small open source AES encryption class to Android, and it would cut my work down a lot if the API of Android is as close as possible to the Java 6 API.
How much is implemented (or referenceable), as I have tried searching about this on google, and i have not yet come up with anything useful?
...
I have requirement to write help(for example show description of what some button does) for my web app. Are there any good examples for doing this?
...
I have the following code in a jsp page (Struts backed):
<c:if test="${USERINFO.someproperty == 'test'}">
...
</c:if>
But what I would like to do is compare only a substring of someproperty, like e.g. if the suffix ends with "st".
I am using JSTL 1.0 so the endsWith() function from JSTL 1.1 is not available (as far as I know) and furt...
I'm building a small statistics application for Java Message Service. I have a container with several topic and loads of subscribers (consumers) to each topic.
JMS provider: SonicMQ
I've gotten the program to the state where I:
Create a session
Create a MessageConsumer to the topic
Listen for messages
Collect the statistics
And it'...
I have to process XML files that have a DTD with a XSLT in Java. The DTD is really needed because it contains the definitions of entities I use. (aside: yes, using entities for stuff that could use unicode is a bad idea ;-)
When I run the transformation it downloads the DTD from the external source every time. I want it to use a XML cat...
Just a quick question about ReadWriteLocks in Java (specifically the ReentrantReadWriteLock implementation) as I don’t find the sun documentation clear.
What happens if a read lock is held by a thread when a write lock is requested by another?
Does the write lock thread have to wait for all currently held read-locks to be released?
Als...
Hi all,
I have two JFrames in my application. In the first JFrame there is a JTable. When the user clicks the JTable I want to get the clicked row's object then open the second JFrame and fill its data fields with this object's elements.
So how can I transfer objects between JFrames? Can someone give me an example for this?
...
I want to read lines from a file into a Set or List. Is there a standard utility for doing this?
If these lines are of the form [key]=[value] I can do:
Properties properties = new Properties();
properties.load(new FileInputStream(file));
The values are single entries, one per line, each value becomes an entry in the Set/List
I know ...
We're deploying a WAR file into Tomcat 5.5 and it works fine if WEB-INF\classes contains .classes files, but if we move the .jar file containing that .classes into WEB-INF\lib, we get an exception on runtime complaining that java.lang.NoSuchMethodError, but existing class file in .jar file contains the class and method does exits!
Any ...
Is there a more elegant solution to convert an 'Arraylist' into a 'Arraylist<Type>'?
Current code:
ArrayList productsArrayList=getProductsList();
ArrayList<ProductListBean> productList = new ArrayList<ProductListBean>();
for (Object item : productsArrayList)
{
ProductListBean product = (ProductListBean)item;
productList.add(produc...
Good day,
I am using CacheFilter to filter a certain path to my server (which outputs an image stream to the response stream). And I've configured it in my web.xml as follows:
<filter>
<filter-name>imagesCache</filter-name>
<filter-class>com.samaxes.cachefilter.presentation.CacheFilter</filter-class>
<init-param>
<p...
I know you can set max heap size at startup using -Xmx but is it possible to change it dynamically during runtime?
Is there any tool or (undocumented) api which will allow me to do that?
...