java

How to mock the InitialContext class with jmockit?

I'm using jmockit with my tests and with one class I wish to test, uses InitialContext directly. So I have the following: public class MyClass { public void myMethod() { InitialContext ic = new InitialContext(); javax.mail.Session mailSession = ic.lookup("my.mail.session"); // rest of method follows..... } In my test ...

Upgrade to Quartz 1.6 on JBoss 4.2.x

Is there a recommended way to upgrade Quartz in JBoss 4.2.x? JBoss bundles quartz 1.5.2, but I have encountered issues (QUARTZ-399, QUARTZ-520) that I want to avoid. I would not want to patch quartz.jar in JBoss just to resolve the errors, but instead provide a new quartz.jar (plus associated configuration artifacts). The Quartz 1.6 mi...

Error connecting to oracle. Getting an UnsatisfiedLinkError for the method t2cGetCharSet

Hi, I am running a series of JUnits using Apache ANT using JDK 1.5. All JUnits that use an Oracle JDBC driver give the UnsatisfiedLinkError shown below. What native library is it looking for and how do I solve this? What should the PATH variable contain? oracle/jdbc/driver/T2CConnection.t2cGetCharSet([CI[CI[CI[CII[SLoracle/jdbc/drive...

Updating an object within a Set

Hey, Let's say I have this type in my application: public class A { public int id; public B b; public boolean equals(Object another) { return this.id == ((A)another).id; } public int hashCode() { return 31 * id; //nice prime number } } and a Set<A> structure. Now, I have an object of type A and want to do the following: If...

How to improve java knowledge?

I'm in college. Basically I have already learnt the syntax of java from books and have been programming in java for two years (Not every other day of course, because it's a computer science and not software engineering course). However, I find myself lacking sufficient knowledge of java and feel inadequate. For example, none of the book...

Tool for finding package namespace conflicts in java code

We have a number of projects that use the same and/or similar package names. Many or these projects will build jar files that are used by other projects. We have found a number of foo.util foo.db and foo.exceptions where the same class names are being used leading to name space conflicts. Does anyone know of a tool that will search a s...

Starting external process during integration testing in maven

I want completely automated integration testing for a Maven project. The integration tests require that an external (platform-dependent) program is started before running. Ideally, the external program would be killed after the unit tests are finished, but is not necessary. Is there a Maven plugin to accomplish this? Other ideas? ...

Unmanaged Threads Spring Quartz Websphere Hibernate

It appears that our implementation of using Quartz - JDBCJobStore along with Spring, Hibernate and Websphere is throwing unmanaged threads. I have done some reading and found a tech article from IBM stating that the usage of Quartz with Spring will cause that. They make the suggestion of using CommnonJ to address this issue. I have ...

Java: Serializing beginner problem :-(

I want to save and store simple mail objects via serializing, but I get always an error and I can't find where it is. package sotring; import java.io.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; import com.sun.org.apache.bcel.internal.generic.INEG; public class storeing { public static vo...

Why does the string "¿" get translated to "¿" when calling .getBytes()

When writing the string "¿" out using System.out.println(new String("¿".getBytes("UTF-8"))); ¿ is written instead of just ¿. WHY? And how do we fix it? ...

Java2D: Clipping a Graphics object with a Line

Is there a way to use a Graphics object's 'setClip()' method to clip using a Line-ish shape? Right now I'm trying to use a Polygon shape but I'm having problems simulating the "width" of the line. I basically draw the line, and when I reach the end, I redraw it but this time subtract the line width from y-coordinate: Polygon poly = ne...

Java, convert lat/lon to UTM

Does anyone know of a way, in Java, to convert an earth surface position from lat, lon to UTM (say in WGS84)? I'm currently looking at Geotools but unfortunately the solution is not obvious. ...

Swing: Is there a way to differentiate between a user-caused ItemEvent and an application-caused one?

I'm working with a combobox in a Swing-based application, and I'm having a hard time figuring out what to do to differentiate between an ItemEvent that is generated from a user event vs one caused by the application. For instance, Lets say I have a combobox, 'combo' and I'm listening for itemStateChanged events with my ItemListener, 'l...

Why is ¿ displayed different in Windows vs Linux even when using UTF-8?

Why is the following displayed different in Linux vs Windows? System.out.println(new String("¿".getBytes("UTF-8"), "UTF-8")); in Windows: ¿ in Linux: ¿ ...

Suppressing warnings for JDK1.4 project

Is it possible to suppress warnings in Eclipse for JDK1.4 project? EDIT: Longer version. There is a project which requires JDK1.4 (no annotations). Only way of suppressing warnings I know is using annotation @SuppressWarnings - no can do in JDK1.4. Is there any way to remove some warning notifications in some specific method/class (not ...

Forcing file deletion on Windows from Java

Is there a programatic way from java to force a file deletion on windows even if the file is locked by some process? I cannot kill the process that locks the file. ...

How can elements be added to a wildcard generic collection?

Why do I get compiler errors with this Java code? 1 public List<? extends Foo> getFoos() 2 { 3 List<? extends Foo> foos = new ArrayList<? extends Foo>(); 4 foos.add(new SubFoo()); 5 return foos; 6 } Where 'SubFoo' is a concrete class that implements Foo, and Foo is an interface. Errors I get with this code: On Line 3: "C...

How can I enumerate all classes in a package and add them to a List?

I need to enumerate all classes in a package and add them to a List. The non-dynamic version for a single class goes like this: List allClasses = new ArrayList(); allClasses.add(String.class); How can I do this dynamically to add all classes in a package and all its subpackages? Update: Having read the early answers, it's absolutel...

Circular References in Java

Given an aggregation of class instances which refer to each other in a complex, circular, fashion: is it possible that the garbage collector may not be able to free these objects? I vaguely recall this being an issue in the JVM in the past, but I thought this was resolved years ago. yet, some investigation in jhat has revealed a circul...

java 1.5 to 1.4

What is the best way to convert existing jar (without source) written in java 1.5 into java 1.4.x? ...