java

Using m4 macros with Eclipse & Java

Is there a way to use m4 macros when developing in Java for Eclipse, ie. making sure the preprocessor is automatically invoked before Eclipse compiles? Or has anyone used another preprocessor successfully with Eclipse? ...

JNI Freeing Memory to Avoid Memory Leak

So i have this C++ program that is called via JNI from my Java program, the code follows: JNIEXPORT jstring JNICALL Java_com_entrust_adminservices_urs_examples_authn_LdapAuthenticator2_takeInfo(JNIEnv *env, jobject obj, jstring domain, jstring id, jstring idca, jstring password) { const char *nt_domain; const char *nt_id; ...

On the longevity of static strings vs seemingly local strings in Java

Given the following snippet A private static final String SQL = "SELECT * FROM TABLE WHERE ID = ?"; and snippet B public List<MyObject> getData(final Long id){ return (List<MyObject>)template.query("SELECT * FROM TABLE WHERE ID = ?",id); } and snippet C public List<MyObject> getData(final Long id){ return (List<MyObject>)t...

Spring context property-placholder ehcahe configuration

I have a spring context xml file with this <context:property-placeholder location="classpath:cacheConfig.properties"/> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="cacheManagerName" value="cacheName"/> <property name="shared" value="false"/> <property name=...

Java: Instantiate Google Collection's HashBiMap

I'm using Eclipse, and I've added google-collect.1.0-rc2.jar as a referenced library. Yet somehow this still doesn't work: import com.google.common.collect.HashBiMap; public class Odp { //... HashBiMap<Character, Integer> charOcc = HashBiMap<Character, Integer>.create(); } Eclipse gives the following erro...

Java Generics for class objects implementing a specific interface

I am trying to define HashMap< ? , String> where ? is a class object from some implementation of a given interface, P. For example, for interface ISearchEngine, i want ? to possibly be Google.class, Yahoo.class, Bing.class, etc. ...

How do I remove the non-numeric character from a string in java?

I have a long string. What is the regular expression to split the numbers into the array? ...

Testing a String is null!

OMG. I have a little project to do and the Strings are killing me! Now, I have a String which is null (is taken the value from invoking getParameter() from a servlet). The problem is that, I'm trying to see if it's null, and, even if it's null, in the program is telling me that is not null, but later in program, when I'm using the vari...

How can I register my own callback with commons logger

I'm setting up an openid site, and using the javaopenidsxip library and it uses commons logger. I already have my own application logger, how do I get it to call my logger instead of writing to stdout? ...

Eclipse package explorer type icons

Does anyone know of an eclipse plugin that changes the file icon used by the package explorer to something that indicates type? It would be handy if the icon looked different for interfaces, abstract classes, enum, and concrete classes. ...

Is there an easier way to change BufferedReader to string?

Right Now I have ;; buffer->string: BufferedReader -> String (defn buffer->string [buffer] (loop [line (.readLine buffer) sb (StringBuilder.)] (if(nil? line) (.toString sb) (recur (.readLine buffer) (.append sb line))))) This is too slow. Edit: I have a BufferedReader when i try to do (str BufferedReader) it ...

bluetooth search and receive sms

Can the bluetooth search run while checking if any SMS messages have been received? When I try to check if there is a new SMS by the command "msg = smsconn.receive()", the program will not go back to search for bluetooth devices. Meaning that I can't get it to check for SMS while running the bluetooth search. Can someone please help m...

How do I fix an "Illegal start of expression" error in Java?

I am getting an "Illegal start of expression" error in the following code at the location marked by a comment. How can I correct this error? class planetUfo { public static void main (String[] args) { // having data for counting the index char letters[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','...

groovy mocks with abstract methods

I have a Java object called Parameter and I'm trying to mock it using groovy. Parameter is an abstract class with 1 abstract method. It also has a non-abstract method called getName(). I'm trying to mock it as follows in Groovy: def p1 = [name:{"p1Name"}] as Parameter But I get a runtime error because I don't implement the abstract m...

Infinite loop at compile time?

Is it possible to enter an infinite loop at compile time? My program seems to enter an infinite loop when I attempt to compile it. I have a class with a class constructor that calls the method gameRun(). gameRun() calls itself at the end of its execution, but should have the appropriate checks to be able to break from it during run time...

A question on JPA Cascading

I have two entities called User and UserProfile in my datamodel. Here is how they are mapped. Code from User Entity: @OneToOne(cascade=CascadeType.ALL) @PrimaryKeyJoinColumn public UserProfile getUserProfile(){ return this.userProfile; } public void setUserProfile(UserProfile userProfile){ this.userProfile=userProfile; } Cod...

Use part of the URL as an argument to a controller in Spring MVC

For example, with the URL foo.com/bar/99 99 will be available directly to a method in the controller as an argument. The controller is mapped to /bar For anyone familiar with ASP.NET MVC or Django, this would be similar to routes.MapRoute in the former and using (?P\d+) in urlpatterns in the latter. It would be possible to process ...

Fast (in means of developer time) way to use a lot of C++ code from Java

Background: We are designing a physics app, that will do a lot of data analysis, but our focus is integrating physical electronic equipement. Basically I would like to be able to call root (it's a big data analysis library from CERN written in C++) library written in C++ library from Java. Basically ability to use ROOT classes from Ja...

How to make C++ code draw on Java components

We are designing physics app, and we would like to have it written in Java, and also we want to use root (root is writen in C++). Root has some nice graphical features -- it is able to draw very nice 3D charts, and I'm thinking whether it's possible to embedd those charts in Java app. Is there any way to make C++ code draw on for examp...

JAXB and multiple object relationships

We are using Jersey (Java REST library) for a project for the last few months and loving it. But this week have run into an issue with JAXB. What I have is an element that has 2 children, each of them have children where some of their children reference each other. Let me show some code. Root root = new Root(); Parent parent1 = ne...