java

How do I import a new Java CA cert without using the keytool command line utility?

Executive summary: how do I install a new root certificate into Java using Java code? We have a desktop application which accesses various web services. Recently one of them switched their SSL certificate to one signed by Trustwave. While the Trustwave SSL certificates are accepted by regular internet browsers, Java does not seem to com...

isAssignableFrom with reference and primitive types

I'd like to get a better understanding of the isAssignableFrom behaviour in Java between primitive and reference types. Eg: System.out.println(boolean.class.isAssignableFrom(Boolean.class)); // false System.out.println(Boolean.class.isAssignableFrom(boolean.class)); // false boolean primitive; Boolean referenceType = true; primitive =...

How safe is my safe rethrow?

(Late edit: This question will hopefully be obsolete when Java 7 comes, because of the "final rethrow" feature which seems like it will be added.) Quite often, I find myself in situations looking like this: do some initialization try { do some work } catch any exception { undo initialization reth...

Zombie threads eating my brainz (J2EE, Tomcat, Hibernate, Quartz)

It is Hallowe'en after all. Here's the problem: I'm maintaining some old-ish J2EE code, using Quartz, in which I'm running out of threads. jconsole tells me that there are just short of 60K threads when it goes pear-shaped, of which about 100 (!!) are actually running. Intuition and some googling (see also here) suggest that what's ha...

Does JBoss run well on Windows?

It appears that we will have to build/deploy one of our new JBoss apps on Windows. All our current deployments are on Solaris so we were slightly concerned with the stability of this model. Apparently half of JBoss deployments are on Windows if this article is accurate. But I was wondering what the community had to say.. Is Windows...

Why Object[].class.isAssignableFrom(String[].class) == true ?

Why is Object[].class.isAssignableFrom(String[].class) == true, while String[].getSuperClass() or getGenericInterfaces() could not get Object[]? I checked the source of JDK, but i don't think i can get the answer myself. For now, I know JDK uses tree to store the relationship between Classes, and depth to indicate its level, Class::isAs...

Using LiveConnect, calling a function doesn't pass the strings properly

I've got a little problem with calling javascript functions via liveconnect on java. It's not calling the function with the proper items, as the Safari console just classes the objects as "RuntimeObject" but in javascript i use: chat.call("message", new String[]{ action, data }); arguments action and data are not being forwarded as pr...

Drag and drop between 2 Jtrees

In my application I have 2 JTree controls in a JPanel. How can I transfer data between them, so that the items from the source tree are removed. ...

Display pairs in Random order

Hi everyone, How can I randomised the order of pairs? e.g. I have 3 elements stored in list e.g. A,B,C --> which makes pairs of A-B, A-C, B-C. How can I display the pair in Random order? e.g. A-B, A-C, B-C or B-C, A-B, A-C or A-C, A-B,B-C ArrayList<String> s = new ArrayList<String>(); s.add("A"); s.add("B"); s.add("C"); ListGen...

Java: cast collection type to subtype

Suppose class B extends class A. I have a List<A> that I happen to know only contains instances of B. Is there a way I can cast the List<A> to a List<B>? It seems my only option is to iterate over the collection, casting one element at time, creating a new collection. This seems like an utter waste of resources given type erasure makes ...

how to choose the jvm heap size ?

Hi, What i usually do concerning the jvm heap size is setting the max value really high to avoid the infamous OutOfMemoryException. However, this strategy (or lack of strategy) doesn't seem to be really smart. :-). My question is how to choose the min and max values, and the difference between the two (should max-min be small or big?...

JPopUpMenu problem with adding menu items

I'm creating JPopUpMenu with following code: JPopupMenu popup1 = new JPopupMenu(); JPopupMenu popup2 = new JPopupMenu(); JMenuItem freeze = new JMenuItem("freeze"); freeze.addActionListener(new FreezActionListener(this)); JMenuItem unfreeze = new JMenuItem("unfreeze"); unfreeze.addActionListener(new UnFreezActionListener(this)); JMen...

Moving the instruction pointer while debugging Java in Eclipse

Can I move the instruction pointer directly to a line of my choice (within the current method) while debugging a Java program in Eclipse (Galileo)? It's straightforward to drag the instruction pointer to the desired line within a method in Visual Studio, but I don't see a way to do that in Eclipse (and don't find anything about it in th...

Java - DAO Layer or Plugin

Hi, I work on the JBJF Project on SourceForge and we want to improve on the Database Access for this framework. Currently, it's semi-flexible, but the access is done at the Task level. We'd like to setup a simple Interface of some kind that's generic in nature and can host the database access to/from JBJF. Thus, Framework classes don...

Is it possible to override a generisized function?

Hello Is it possible to override a generisized function as illustrated in the code snippet below? interface A { } interface B extends A { } abstract class C { protected abstract <T extends A> void abc(T xyz); } class D extends C { @Override protected void abc(B xyz) { // doesn't compile // The method abc(B) of type ...

Implementation of ZipCrypto / Zip 2.0 encryption in java

I'm trying o implement the zipcrypto / zip 2.0 encryption algoritm to deal with encrypted zip files as discussed in http://www.pkware.com/documents/casestudies/APPNOTE.TXT I believe I've followed the specs but just can't seem to get it working. I'm fairly sure the issue has to do with my interpretation of the crc algorithm. The docum...

Custom class loader in Constructor.newInstance

I'm using rhino via the bean scripting framework to create and configure objects in my java process. Some of the classes used in the scripts need to be loaded dynamically as they won't always be on the standard classpath. To load these classes I initialize the scripting framework's context factory with a custom class loader that loads t...

java FileChannel transferFrom questions?

Following is my method to append one file onto another file. public static void appendFile(File baseFile, File newFile) throws IOException { long baseFileSize = baseFile.length(); FileChannel outChannel = new FileOutputStream(baseFile).getChannel(); long position1 = outChannel.position(); outChannel.position(baseFileSiz...

Java Random Slowdowns on Mac OS

I have a Java program for doing a set of scientific calculations across multiple processors by breaking it into pieces and running each piece in a different thread. The problem is trivially partitionable so there's no contention or communication between the threads. The only common data they access are some shared static caches that don...

Simple Java Xml to POJO mapping/binding?

Hey guys, I'm trying to figure out the simplest way to map an xml file to to a plain old java object. Note: That in my example the xml doesn't quite match up with my intended POJO. ///////// THE XML <?xml version="1.0" encoding="UTF-8"?> <Animal> <standardName> <Name>Cat</Name> </standardName> <standardVersion> <Versio...