java

Java generics - method parameter

Is it necessary to parametrize the entire interface for this scenario, even though Bar is only being used in a single method? public interface IFoo<T>{ void method1(Bar<T> bar); //Many other methods that don't use Bar.... } public class Foo1 implements IFoo<Yellow>{ void method1(Bar<Yellow> bar){...}; //Many othe...

Why is my java application faster on an AMD processor?

I made the observation that my java application is running much faster when executed on an AMD processor in contrast to an Intel CPU. For example my JBoss starts in about 30 seconds on a 3 GHz AMD processor and needs about 60 seconds on a 3 GHz Intel processor with identical disc, RAM and OS? Has anyone else made this observation? Why ...

A difference in style: IDictionary vs Dictionary

I have a friend who's just getting into .NET development after developing in Java for ages and, after looking at some of his code I notice that he's doing the following quite often: IDictionary<string, MyClass> dictionary = new Dictionary<string, MyClass>(); He's declaring dictionary as the Interface rather than the Class. Typically I...

Java: How to be sure to store unique arrays based on its values on a List

I have a number of one dimension arrays of Object[] (these objects are primitive types if it helps) I want to store these arrays in a List, but only the arrays whose contents are unique from the rest. My first aproximation was to iterate througth the arrays storing in a Set the value of Arrays.hashCode(array) and only storing the array...

Is JOptionPane.showMessageDialog thread safe?

JOptionPane.showMessageDialog is supposed to be a useful utility for getting user feedback as it blocks your current thread while you wait. I would expect therefore that it would be thread-safe and that you wouldn't need to wrap the call in an invokeLater or an invokeAndWait. Is this the case? ...

JFace TreeViewer flickering

I'm trying to update the input of JFace TreeViwer periodically using setInput() method. Also I use the viewer.setExpandedElements(expandedElements); viewer.setExpandedTreePaths(expandedTreePaths); methods to save the state of the tree. But after each setInput() call the TreeViewer flickers. How can avoid from flickering ? ...

java generics type parameters and operations on those types

In searching for an answer to an interesting situation which I had recently encountered I came upon the following question: Type safety, Java generics and querying I have written the following class (cleaned up a bit) public abstract class BaseDaoImpl<T extends Serializable> extends HibernateDaoSupport implements BaseDao<T> { /** ...

Adding plugin.jar to the build path in eclipse in a machine indepenent way

I'm working on a project that uses JSObject from the jre's plugin.jar, which isn't included in the build path normally. I can get things to compile fine by adding the jar to the classpath. Currently I'm doing this in eclipse via Project->Configure Build Path->Libraries->Add External JARs... -> find the jar in jdk/jre/lib/plugin.jar. T...

Java packages autoimports

Is there a tool/library that allows me to import the java packages automatically outside the IDE? For instrance if I type in notepad something like: JFrame f = new JFrame(); Then run this magic tool, and then have automatically written as: import javax.swing.JFrame .... JFrame f = new JFrame(); Is there something like that?...

java.lang.OutOfMemoryError: Java heap space

I am getting the following error on execution of a multi-threading program java.lang.OutOfMemoryError: Java heap space The above error occured in one of the threads. Upto my knowledge, Heap space is occupied by instance variables only. If this is correct, then why this error occurred after running fine for sometime as space for inst...

Exception in a Thread

I have made a multi-threading program. In it, the main thread starts 10 threads but the problem is whenever an exception occured in one of the threads, the whole application gets stopped. But I want that whenever an exception occurred in one thread, only that thread should gets stopped and other threads keep working. How can I do that?...

How do I add a horizontal strut to a BoxLayout using the Netbeans GUI builder?

When I create a JPanel in Netbeans, it allows me to specify which LayoutManager to use for it from a fixed set of LayoutManagers, including BoxLayout. After adding a couple of components to the JPanel, I would like to add horizontal spacers (created using Box.createHorizontalStrut) to make the layout look better. I could manually add the...

Using sun PDF Renderer to display PDFs with embedded fonts

I'm having trouble using Sun's PDF Renderer package to view PDFs with embedded fonts. I have the following code which creates a BufferedImage out of every page of a PDF for viewing in my application, and it works fine when there are no embedded fonts. However, when the PDF has embedded fonts, it shows no text. Any ideas? Also, it ope...

Java Encryption C# Decryption

Hi, I got a module which RSA encrypts the data and passes on to the C#. C# needs to decrypt it based on the public key (64 bit encoded) and the passed token. I have token , 64 bit encoded public key, can some help me get with the sample to get started. All I know from Java end is, it is using. I have got the result from Java end and nee...

How to use profiler of Netbeans?

I want to find memory leaks in my java application but I don't know how to use Netbeans profiler to do that. ...

java shell for executing/coordinating processes?

I know about using Runtime.exec, you pass it a native program to run + arguments. If it's a regular program, you can run it directly. If it's a shell script, you have to run an external shell program like sh or csh or cmd.exe. Is there some Java class (either standard or open-source) that implements a shell, meaning a program that you p...

Do I have to explicitly disconnect from a database when using Java?

It is necessary to disconnect from the database after the job is done in Java? If it is not disconnected, will it lead to memory leaks? ...

How to get SOAP message while using a Axis 1.4 wsdl2java-generated client

This is probably an easy question for anyone with any moderate expertise with web services using Apache Axis. I have a web service client that was generated by wsdl2java in Axis 1.4. I am writing unit tests that need to access the actual SOAP message itself, and do a comparison to the client side java classes which are generated by Axis...

Transferring data from PHP to Java

I have an XML file which I need to parse using PHP and send the parsed data to Java, what are some best practices to accomplish it ? ...

Java: create new implementation of type at runtime?

So, I realize the answer to this is probably "it's hard", but: I've got a weird idea, and was wondering if it's possible in Java to create a method like: <T> T wrapInterface (Class<T> interfaceClass, T wrappedObject) { if (mClass.isInterface()) { //create a new implementation of interfaceClass that, in each method, //does so...