java

How to sort nearly sorted array in the fastest time possible? (Java)

I have an array of values which is almost, but not quite sorted, with a few values displaced (say, 50 in 100000). How to sort it most efficiently? (performance is absolutely crucial here and should be way faster than O(N)). I know about smoothsort, but I can't find Java implementation. Does anyone know whether it is already implemented?...

callbacks in jni

Is there any way to pass a callback to java code, from C. And the call returns immediately. Later on, after completing the task, the java code can invoke that callback. I have a C extension for php that calls a java store to store some items in it. The items can be retrieved from store in synchronous and asynchronous methods (I provide...

How do I build and distribute my Java project?

I used Eclipse to build a pretty simple Java project. It builds and runs in the IDE. I have a few unit tests I wrote using JUnit. They all build and pass in the IDE. My project is in the following path: /home/vg1890/workspace/project/ The main source is in: /home/vg1890/workspace/project/src And the tests are in: /home/vg1890/...

Java: Generic casting down generates warning, why?

I don't understand why the following code generates a warning. interface Generic<T> { } interface A { } class B { Generic<A> c; <T extends A> B(Generic<T> a) { c = (Generic<A>) a; //warning here } } //Unchecked cast from Generic<T> to Generic<A> In class B i'm only interested in using instances of Generic that ar...

Dozer InstantiationException mapping Calendar class

I'm getting an InstantiationException when trying to map Date -> Calendar. Simple test follows: @Test public void testConversion() { GregorianCalendar cal = new GregorianCalendar(2009, 2, 3); Date sourceValue = cal.getTime(); DozerBeanMapper mapper = new DozerBeanMapper(); Object result = mapper.map(sour...

Problem receving in RXTX

I've been using RXTX for about a year now, without too many problems. I just started a new program to interact with a new piece of hardware, so I reused the connect() method I've used on my other projects, but I have a weird problem I've never seen before. The Problem The device works fine, because when I connect with hyperterminal, I...

Java Byte Code Visualizer

What could help me in helping writing highly compact(least byte code count) programs in Java. Possibly I'm looking at: A tool that tells me how many byte codes a Class or a method generates. To visualize byte codes. The tool could tell me which areas need optimization in terms of byte code count or cpu cycles. A byte code chart woul...

Java concurrency file system

Good day, I need to create a File System Manager (more or less) which can read or write data to files. My problem is how do I handle concurrency? I can do something like public class FileSystemManager { private ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); public byte[] read(String path) { readWriteLo...

Java, Most Expensive Statements?

What are the most expensive (both in terms of bytecode and cpu cycles) statements in the Java Programming language? ...

Java GUI alternatives

I write applications in Java, and I'm looking for ways to speedup GUI programming. Binding frameworks help, but the particular application I'm working on now wouldn't benefit too much from that (it doesn't display a lot of data, just a lot of ways to manipulate the data). I feel like I spend way too much time writing boiler-plate GUI cod...

Are there any syntax highlighting plugins for javadoc?

Hi, Currently I format code examples in my javadoc using the PRE tag e.g.: /** * Example javadoc * <pre> String foo = "bar"; </pre> * * @return true if the operation completed */ But this turns out rather monotone and boring in the resulting javadoc, I'd much rather have some syntax highlighting similar to SyntaxHighlighter. ...

How can i get generic type from a Class object ?

Hi, Suppose the following class public class Message { // some code } And a Spring Validator implementation (no Spring knowledge required) public class MessageValidator implements Validator { public boolean supports(Class clazz) { if(clazz.isAssignableFrom(Message.class)) return true; else if(<AN...

How to make RSACryptoServiceProvider work without padding (nopadding)?

Hello :) I need to make a C# application compatible with a Java application. The Java application uses a Cipher.getInstance("RSA/ECB/nopadding"); initializer to make the cipher ECB and no-padding. However, in C#, you have 2 options for padding: OAEP padding or PKCS#1 v1.5 padding. I need a no-padding version, or else I'm definitely s...

Java: Create DOM Element from Element, not Document

As you know, the proper way to create a Dom Element in Java is to do something like this. import org.w3c.dom.Document; import org.w3c.dom.Element; Document d; Element e; e = d.createElement("tag"); You need to use d to generate the element because it needs a document context. (I'm not 100% sure why, but maybe misunderstanding this i...

Encrypting with RSA private key in Java

I'm trying to encrypt some content with an RSA private key. I'm following this example: http://www.junkheap.net/content/public_key_encryption_java but converting it to use private keys rather than public. Following that example, I think what I need to do is: Read in a DER-format private key Generate a PCKS8EncodedKeySpec call gener...

Java while loop not looping

I have the following button in my swing interface private void solveButtonMouseClicked(java.awt.event.MouseEvent evt) { step1(); } which calls step1(); private void step1(){ //step 1 solving the white cross around the yellow middle while( (!(F2.getBackground().equals(w...

Simile Timeline

I'm sure many will know of Simile Timeline (http://www.simile-widgets.org/timeline/), the JavaScript-based widget for embedding interactive timelines into web sites. Timeline is open source software and is licensed under the BSD license. How would I go about using Similie Timeline in a Java desktop application that has no Internet acce...

Does java have a "LinkedConcurrentHashMap" data structure ?

I need a data structure that is a LinkedHashMap and is thread safe. How can I do that ? ...

Is constant polling in RXTX necessary?

While trying to figure out this problem (any help there is appreciated), I ran RXTX while monitoring its activity using PortMon and noticed that RXTX constantly checks if data is available, even when the Java client reads from the gnu.io.SerialPort object only through a SerialPortEventListener. Why is this? Is it a poor implementation ...

Are Java Class Paths First in First Searched?

I had a question about Java Class Path variables. If I have multiple jars with the same classes, which one does the jvm use at runtime. The first one listed in the Class Path, the last one, or is undefined? Thanks ...