java

Is there an easy way to change the behavior of a Java/Swing control when it gets focus?

For most GUI's I've used, when a control that contains text gets the focus, the entire contents of the control are selected. This means if you just start typing, you completely replace the former contents. Example: You have spin control that is initialized with the value zero. You tab to it and type "1" The value in the control is n...

Java VNC Libraries

Are there any VNC Libraries for Java, I need to build a JSP/Servlet based VNC server, to allow user to share their desktops with helpdesk. I've seen jVNC, but i'd like to build it myself, for a University project. In particular, I'm looking for Java Libraries that I can use inside another servlet based application. Unfortuatnely tight V...

How to handle static fields that vary by implementing class

I hit this problem all the time. Suppose I am making a command line interface (Java or C#, the problem is the same I think, I will show C# here). I define an interface ICommand I create an abstract base class CommandBase which implements ICommand, to contain common code. I create several implementation classes, each extending the base ...

JEE SqlResultSetMapping Syntax problem?

I have the following Java 6 code: Query q = em.createNativeQuery( "select T.* " + "from Trip T join Itinerary I on (T.itinerary_id=I.id) " + "where I.launchDate between :start and :end " + "or ADDDATE(I.launchDate, I.equipmentPullDayOfTrip) between :start and :end", "TripResults" ); q.se...

System.gc() in java

I know that garbage collection is automated in java. But I understood that if you write System.gc() in your code the java vm may or may not decide at runtime to do a garbage collection at that point. how does this work precisely? On what basis/parameters exactly does the VM decide to do (or not do) a GC when it sees a System.gc()? Are th...

Fail fast finally clause in Java

Is there a way to detect, from within the finally clause, that an exception is in the process of being thrown? ie: try { // code that may or may not throw an exception } finally { SomeCleanupFunctionThatThrows(); // if currently executing an exception, exit the program, // otherwise just let the exception thrown by the...

Problem with unicode String literal in unit test

I have a JUnit test that tests adding Strings to a Dictionary custom type. Everything works fine for everyone else on a Linux/Windows machine, however, being the first dev in my shop on a mac, this unit test fails for me. The offending lines are where unicode string literals are used: dict.add( "Su字/会意pin", "Su字/会意pin" ); dict...

How to control the capitalization of month and day names returned by DateFormat?

Here is a quick test program: public static void main( String[] args ) { Date date = Calendar.getInstance().getTime(); System.out.println("Months:"); printDate( "MMMM", "en", date ); printDate( "MMMM", "es", date ); printDate( "MMMM", "fr", date ); printDate( "MMMM", "de", date ); System.out.println("Da...

Java Servlet 404 errors

What culprits are the most likely to cause a 404 resource not found error when a page in a given .WAR, autocreated by Sun's J2EE deploytool, is trying to load a Servlet in the same .WAR file? Eg: HTTP Status 404 - /MyServlet/MyServlettype Status reportmessage /MyServlet/MyServletdescription The requested resource (/MyServlet/MyServ...

Integration of JavaScript and JMS

Where can I find a guide for integrating JavaScript and JMS (Java Messaging Service)? I would like a best practice or established technology that allows me to directly or indirectly receive messages from a topic and update a site based on the message. I was thinking of creating two components, a servlet for the Web module, and an MDB (M...

Java applet cached forever, not downloading new version?

We have a case where clients seem to be eternally caching versions of applets. We're making use of the <param name="cache_version"> tag correctly within our <object> tag, or so we think. We went from a version string of 7.1.0.40 to 7.1.0.42 and this triggered a download for only about half of our clients. It doesn't seem to matter whi...

How do you tell whether a string is an IP or a hostname

So you have a String that is retrieved from an admin web UI (so it is definitely a String). How can you find out whether this string is an IP address or a hostname in Java? Update: I think I didn't make myself clear, I was more asking if there is anything in the Java SDK that I can use to distinguish between IPs and hostnames? Sorry for...

Is there a specification of Java's threading model running under Windows XP available anywhere?

There are various documents describing threading on Solaris/Linux, but nowwhere describing the Windows implementation. I have a passing interest in this, it seems strange that something so critical is (seemingly) not documented. Threading is not the same on different OS' - "Write Once, Run Anywhere" isn't true for threading. See http:/...

Reading from a ZipInputStream into a ByteArrayOutputStream

I am trying to read a single file from a java.util.zip.ZipInputStream, and copy it into a java.io.ByteArrayOutputStream (so that I can then create a java.io.ByteArrayInputStream and hand that to a 3rd party library that will end up closing the stream, and I don't want my ZipInputStream getting closed). I'm probably missing something bas...

How to debug a JSP tomcat service using eclipse?

I would like to debug my separately running JSP/Struts/Tomcat/Hibernate application stack using the Eclipse IDE debugger. How do I setup the java JVM and eclipse so that I can set breakpoints, monitor variable values, and see the code that is currently executing? ...

How do I register a custom type converter in Spring?

I need to pass a UUID instance via http request parameter. Spring needs a custom type converter (from String) to be registered. How do I register one? ...

ResourceBundle from Java/Struts and replace expressions

If I have a Resource bundle property file: A.properties: thekey={0} This is a test And then I have java code that loads the resource bundle: ResourceBundle labels = ResourceBundle.getBundle("A", currentLocale); labels.getString("thekey"); How can I replace the {0} text with some value labels.getString("thekey", "Yes!!!"); Such...

How do I convert jstring to wchar_t *

Let's say that on the C++ side my function takes a variable of type jstring named myString. I can convert it to an ANSI string as follows: const char* ansiString = env->GetStringUTFChars(myString, 0); is there a way of getting const wchar_t* unicodeString = ... ...

Does Java save its runtime optimizations?

My professor did an informal benchmark on a little program and the Java times were: 1.7 seconds for the first run, and 0.8 seconds for the runs thereafter. Is this due entirely to the loading of the runtime environment into the operating environment or is it influenced by Java's optimizing the code and storing the results of those optim...

How to create a windows service from java app

I've just inherited a java application that needs to be installed as a service on XP and vista. It's been about 8 years since I've used windows in any form and I've never had to create a service, let alone from something like a java app (I've got a jar for the app and a single dependency jar - log4j). What is the magic necessary to make...