java

Why Clojure instead of Java for concurrent programming

When Java is providing the capabilities for concurrent programming, what are the major advantages in using Clojure (instead of Java)? ...

BooleanQuery$TooManyClauses exception when using wildcard queries

I'm using Hibernate Search / Lucene to maintain a really simple index to find objects by name - no fancy stuff. My model classes all extend a class NamedModel which looks basically as follows: @MappedSuperclass public abstract class NamedModel { @Column(unique = true) @Field(store = Store.YES, index = Index.UN_TOKENIZED) pr...

Java: Retrieve the generic parameter value at runtime

What is the best way to retrieve the runtime value of a generic parameter for a generic class? For example: public class MyClass<T> { public void printT() { // print the class of T, something like: // System.out.println(T.class.getName()); } } So if I call new MyClass<String>().printT() it will print "String" ...

Spring3/Hibernate3/TestNG: some tests give LazyInitializationException, some don't

Dear Sirs, The preface: I'm struggeling with LazyInitializationException in my Unit Tests, and I have a really hard time getting my head around it, as you can see from my questions Database Sessions in Spring, TestNG and Spring 3 and LazyInitializationException while unit-testing Hibernate entity classes for use in Spring, using TestNG...

Java AWT applet white screen when resizing window

I have a java applet built using awt. I draw some text on a panel object and everything goes fine. but when resizing the windows all the text disappears. this behaviour is different among different jvms and platforms. moving to swing isn't a possible option, because we have to maintain compatiblty with Microsoft JVM. ...

Passing large C structure through JNI efficiently

I have a large C structure (about 40 members, int and char[]) which I have to pass through JNI to the Java side for further processing. This happens repeatedly. (I already put the GetMethodID() etc. into an init() function on the C side so I only have to call them once.) What would be an efficient way to do this? I can think of: Inst...

Why is the Java date API (java.util.Date, .Calendar) such a mess?

As most people are painfully aware of by now, the Java API for handling calendar dates (specifically the classes java.util.Date and java.util.Calendar) are a terrible mess. Off the top of my head: Date is mutable Date represents a timestamp, not a date no easy way to convert between date components (day, month, year...) and Date Calen...

Converting values to unit prefixes in JSP page

How can I convert values to to other units in JSP page. For example if I get value 1001 and I want to only display 1K, or when I get 1 000 001 I would like to display 1M and not that long attribute, how can I do that, when I get Integer value to my jsp page for example ${myValue}? ...

'A4J' is undefined

hello i have a problem with ajax4jsf library on ie7 it give me error 'A4J is undefined' but this error not appear on firefox and chrome library which i used myfaces1.1.5 and ajax4jsf1.1 Here is my web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="java.sun.com/xml/ns/j2ee"; xmlns:xsi="w3.org/2001/XMLSchema-...

Multiplayer browser game [Java]

I've been developing a small card game which is called "Tarneeb". The game itself looks like Bridge card game but with different rules. Anyway, i finished the entire game as a standalone desktop application using Java 6. This is a picture of the game. Anyway, i now need to transform that into a web app with multiplayer capabilities, so t...

Java Need help implementing an algorithm

This algorithm is so advanced for my basic programming skills that I just don't see how I could implement it. I'm posting this in a new question because I can't keep bothering the guy who gave me the algorithm alone about this in the comment section in the previous question. MaxSet(node) = 1 if "node" is a leaf MaxSet(node) = Max(1 + S...

Transform a java object tree into a 2 dimension table

Hi, I'm faced to the following problem. I have a tree of java objects for which I have to export each field value into a CSV file. The result of the exportation must be similar to what we have in SQL left outer join (called cartesian product). Class author @DataField(pos = 1) String firstName; @DataField(pos = 2) String lastName; @O...

Ambiguity in servlet-mapping

I have two servlets 'ExtensionServlet' and 'PatternServlet' and a static html page. The HTML code is given below. <html> <head> <title> Resolve servlet ambiguity </title> </head> <body> <form action="servlets/form.col" method="POST"> <input type="submit" value="Goto Servlet"> </form> </bod...

Preventing apps from invoking my Activity

I have an Activity X which is only accessible after you've entered a valid credential. How can I prevent other apps from calling startActivity with an Intent pointing to X ? e.g. Intent intent = new Intent( this, ActivityX.class ); startActivity( intent ); Basically I don't want Activity X to be exported to any apps except my app. ...

Writing a java code which will execute every hour(quartz)

Can someone please correct me, I've found this example online and bunch of others not working, this particular example throws the following error : Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/SetUtils at org.quartz.JobDetail.<init>(JobDetail.java:85) at tralala.org.xml.CronSchedule....

Listing files in Java without using java.io

how to list files and directories in current directory without using java.io.*? ...

BlackBerry ListCall back error

i am implementing ListField to show users data in next screen. but its throwing an exception can u plz guide me whats wrong with this code. import java.io.*; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.system.*; import net.rim.device.api.ut...

Java7 swing application framework support

The future of the Swing application framework on the Java 7 platform is undefined. http://weblogs.java.net/blog/archive/2009/08/19/saf-and-jdk7 Is it safely to use it now? ...

How can I enforce a type constructor in a concrete class through the interface it implements?

Let me describe the situation, and I'm sure I'm just thinking about this problem incorrectly. I have a concrete class that will implement an interface. I want to enforce in the contract that the class must have a constructor with a specific type. So for instance: interface MyInterface {} public class MyClass implements MyInterface { ...

Search/Queries in Collections (Java)

I've created many Geodata objects (name,postalCode,lat,lon). Now I want to put them into a collection to search for different entries later. Everything should happen objectOriented/in-memory, so there shouln't be a need for a relational database. Such a Query looks like: Find lat and lon by name or plz Find objects between LAT1,L...