java

Can I make this search relevancy function better without "doing advanced stuff"?

Hi! My search engine uses the following function to calculate relevancy. private static int calculateScore(String result, String searchStr, int modifier) { String[] resultWords = result.split(" "); String[] searchWords = searchStr.split(" "); int score = 0; for (String searchWord : searchWords) { for (Strin...

same function in different jar

Hi, I have a question and wonder if there is anyone came across the same situation as I did. I upgrade java version from 1.4 to 1.6, the java6 includes soap package itself, which means the axis soap libs i used previously will not be invoked. for example, javax.xml.soap.SOAPMessage. Is there anyway that I can explicitly force the a...

how to assign different concurrency strategy to the same (persistence) entity?

I'm using JPA and I am using second-level cache for all the reference entities. Everything's working well, I can get the entities from second-level cache is they were already been selected before. Now, I have two applications, they both use the same database (so they both use the same table, values, etc). 1.The read-only application ju...

Generalized Singleton base class in Java.

In C++, I understand that it is possible to create a Singleton base class using templates. It is described in the book, Modern C++ Design, by Andrei Alexandrescu. Can something like this be achieved in Java? ...

Insert One Bit into Byte Array

Hello, I'm trying to insert a single bit into an array of bytes, which would shift all the bits in the byte array to the left. Say I have a Java byte array as follows: byte[] byteArray = new byte[2]; byteArray[0] = 0x11 byteArray[1] = 0x00 In binary, this byte array represented as: 0001 0001 0000 0000 Now I want to insert a zero ...

How can I get jcifs to play nicely with apache axis

I need to connect Apache Axis 1.4 to a Webservice that uses NTLM authentication to restrict access to its operations. I'm expecting to use Samba Jcifs to handle the NTLM handshake. I found http://hc.apache.org/httpcomponents-client/ntlm.html which gives me fantastic directions for how to wire up HttpClient 4.0 with jcifs. Trouble is...

Mac OS X Java SDK Support

Can anyone tell me, or send me to a page, that can tell me what version of Java that a Mac OS X supports out of the box? I know for instance 10.5 comes with Java 1.5 installed by default. what about 10.4? 10.3? 10.2? 10.1? My app needs to be cross platform and I need to figure out what Java version to use to build my Java code. This wo...

How can this Java code compile?

A colleague came across some code that looked like this and couldn't understand how it could ever compile: class FooClass { public static void bar(String arg) { System.out.println("arg = " + arg); http://www.google.com System.out.println("Done!"); } } Basically, there was a random URL pasted in the middle of a metho...

Testing Methods in JUnit Prevents Email Sending

I'm developing in Java and using JUnit to test some of my methods. Some of my methods send emails. The emails are actually sent by a separate thread that is spawned. The problem is that whenever I test these methods everything goes fine except that the emails are not actually sent. I've followed the execution through the whole stack and ...

Java JTabbedPane, how can I select a tab from a button?

Hi all How can I select a tab as if it was clicked by clicking on a button? I have googled and looked at all the actions but there are just just so many... :( Anyone know off hand? Thanks in advance! ...

Is the "caller" in Java the same as the "receiver" in Ruby?

If I say x.hello() In Java, object x is "calling" the method it contains. In Ruby, object x is "receiving" the method it contains. Is this just different terminology for expressing the same idea or is there a fundamental difference in ideology here? Coming from Java I find Ruby's "receiver" idea quite baffling. Perhaps someone coul...

Naming Collection Extensions for clarity

Introducing some of the goodness of collection operations to our codebase without adding a new external library dependency, we are adding these methods to our utility package. static public List<T> filter(List<T> source, Predicate<T> filter); static <Y,T> public List<Y> transform(List<T> source, Mutator<Y,T> filter); static public boole...

Updating cell renderer after a DefaultCellEditor derived instance does its job

Hello, I use a JTable which has its own cell renderer and cell editor. Say, this table contains 2 columns and x rows: The first column contains a boolean value, its own cell rendering and cell editor (a radiobutton) The second column contains a string value, its own cell renderer: it makes it bold when the first column of the current...

Convert A String (like testing123) To Binary In Java

I would like to be able to convert a String (with words/letters) to other forms, like binary. How would I go about doing this. I am coding in BLUEJ (Java). Thanks ...

Hibernate/JPA Parent-Child - is it okay for Parent equals()/hashCode() to use the DB Id?

Given the following: @Entity public class Parent implements Serializable { @Id private Long id; // mapped ManyToOne below... private List<Child> children = new ArrayList<Child>(); ... } Is it a bad practice to have Parent.equals() and Parent.hashCode() use only id? I understand that Child.equals() and Child.hashCode() shou...

Automatic stubbing in java word. What to use?

Hi, I have huge class that I need to build stub for. To give you picture it is Messages class of the GWT. Often this is class with dozens of methods that return String. With JMock I can do stubbing, but I will end with allowing each method... This is not something that I would like to see. Is there something that will automatically b...

Where can I find some good examples to learn the basics of threading?

I am at the end of my first year doing computer science and want to mess around with something basic. I want to use threads so I can learn. What are some good examples to learn from? ...

NAT Traversal with Java

I'm trying to find a way to communicate between two NAT-ed nodes using Java. My requirements pretty much align with the ICE-specification; i.e. I want to try STUN first and then fall back to relaying the data when nothing else works. I need some kind of streaming protocol, so either TCP must be supported or the library should provide som...

Tomcat 6 and log4j application logging produce no output

I'm trying to get log4j application (webapp) logging working in a Tomcat 6 app. I have log4j-1.2.15.jar in my WEB-INF directory, log4j.dtd and log4j.xml in WEB-INF/classes. My log4j.xml looks like: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" > <log4j:configuration> <appender name="massAppende...

Calling built-in java native methods

Is it possible to call the JVM's built-in native code, i.e. the code that various class in java.lang and java.io call? In other words, can you bypass the built-in java API to access various system-level calls such as file-system access? I know I could do this by building my own native code library and calling that via JNI, but it would b...