java

Teaching a mainframe COBOL programmer Java?

I’m trying to help someone learn Java who’s only programming experience is COBOL on the mainframe. I was wondering if anyone knew any good resources for object oriented concepts. I learned how to program with C++ so just understand the theory behind basic OOP. I’m more concerned about a way to get the basic concepts across, such as encap...

Generic type args which specificy the extending class?

I want to have a class which implements an interface, which specifies the specific subclass as a parameter. public abstract Task implements TaskStatus<Task> { TaskStatus<T> listener; protected complete() { // ugly, unsafe cast callback.complete((T) this); } } public interface TaskStatus<T> { public void complete(T...

In a java regex, how can I get a character class e.g. [a-z] to match a - minus sign?

Pattern pattern = Pattern.compile("^[a-z]+$"); String string = "abc-def"; assertTrue( pattern.matcher(string).matches() ); // obviously fails Is it possible to have the character class match a "-" ? ...

Spring-MVC Problem using @Controller on controller implementing an interface

I'm using spring 2.5 and annotations to configure my spring-mvc web context. Unfortunately, I am unable to get the following to work. I'm not sure if this is a bug (seems like it) or if there is a basic misunderstanding on how the annotations and interface implementation subclassing works. For example, @Controller @RequestMapping("ur...

How to add an attribute to an XML node in Java 1.4

I tried: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(f); Node mapNode = getMapNode(doc); System.out.print("\r\n elementName "+ mapNode.getNodeName());//This works fine. Element e = (Element) mapNode; //This is where the error occurs //it seem...

Any issues with ActiveMQ broker and clients running on different JDKs?

We have a distributed system with components (including the ActiveMQ broker) running on jdk 1.6. A potential customer would like to integrate a component that was built on jdk 1.4 with our system. While this customer is willing to write code to integrate with our system, they are not comfortable moving from jdk 1.4. Would there be any ...

How do I make sure my objects get garbage collected?

One of our programs is sometimes getting a OutOfMemory error on one users machine, but of course not when I'm testing it. I just ran it with jprofiler (on a 10 day evaluation license because I've never used it before), and filtering on our code prefix, the biggest chunk both in total size and number of instances is 8000+ instances of a ...

When to use final

I've found a couple of references (for example) that suggest using final as much as possible and I'm wondering how important that is. This is mainly in the the context of method parameters and local variables, not final methods or classes. For constants, it makes obvious sense. On one hand, the compiler can make some optimizations and i...

Hibernate.initialize() and second-level cache

Does anybody know if Hibernate's static initialize() method, which populates a proxy object, will attempt to hit the second-level cache before going to the database? My code seems to be behaving that way, and I can't seem to find anything in the documentation about this. The Javadoc is (as usual) sparse. Thanks! ...

Polymorphism vs Overriding vs Overloading

In terms of Java, when someone says what is polymorphism. Would overloading or overriding be an acceptable answer? I would seem to think that is a bit more than that. IF you had a abstract base class that defined a method with no implementation, and you defined that method in the sub class is that still overridding? I think overloading...

Embedding the Java h2 database programmatically

At the moment we use HSQLDB as an embedded database, but we search for a database with less memory footprint as the data volume grows. Derby / JavaDB is not an option at the moment because it stores properties globally in the system properties. So we thought of h2. While we used HSQLDB we created a Server-object, set the parameters and...

When would you use a WeakHashMap or a WeakReference?

The use of weak references is something that I've never seen an implementation of so I'm trying to figure out what the use case for them is and how the implementation would work. When would you (or have you) had a need to use a WeakHashMap or WeakReference and how would it be used? ...

How do I use ResourceBundle to avoid hardcoded config paths in Java apps?

I'd like to eliminate dependencies on hardcoded paths for configuration data in my Java apps, I understand that using ResourceBundle will help me use the classloader to find resources. Can someone tell me how I would replace a hardcoded path to a resource (say a .properties configuration data file required by a class) with appropriate u...

How to stop Eclipse from hanging on a long autocompletion list?

I'm using the GL class from JOGL, which basically contains all OpenGL functions. Now I just installed the Javadoc for JOGL, because it's nice to have the parameter names if you can't remember the order. However, with this Javadoc installed, it takes about half a minute to show the autocompletion list whenever I type GL.. Since I'm makin...

Java TreeNode: How to prevent getChildCount from doing expensive operation?

I'm writing a Java Tree in which tree nodes could have children that take a long time to compute (in this case, it's a file system, where there may be network timeouts that prevent getting a list of files from an attached drive). The problem I'm finding is this: getChildCount() is called before the user specifically requests opening a...

Make DocumentBuilder.parse ignore DTD references

When I parse my xml file (variable f) in this method, I get an error C:\Documents and Settings\joe\Desktop\aicpcudev\OnlineModule\map.dtd (The system cannot find the path specified) I know I do not have the dtd, nor do I need it. How can I parse this File object into a Document object while ignoring DTD reference errors? private...

Cheapest Java Code Signing Certificate? (not self-signed)

Does anyone know where I can get an inexpensive Java code signing certificate? Everywhere I look wants $200 to $300 per year! Unfortunately I cannot use a self-signed one, I'm trying to get rid of the scary warnings so that users will be more likely to accept my application. And as far as I know (per this question), it has to be a code s...

Why is it impossible, without attempting I/O, to detect that TCP socket was gracefully closed by peer?

As a follow up to a recent question (http://stackoverflow.com/questions/151590/java-how-do-detect-a-remote-side-socket-close), I wonder why it is impossible in Java, without attempting reading/writing on a TCP socket, to detect that the socket has been gracefully closed by the peer? This seems to be the case regardless of whether one use...

Interface questions.

Hello, suppose that i have interface MyInterface and 2 classes A, B which implements MyInterface, i declared 2 objects MyInterface a = new A() , and MyInterfave b = new B(). when i trying to pass a to function - function doSomething(A a){} i am getting error. This is my code: public interface MyInterface { } public class A impleme...

download mail attachment with Java

Hi, I had a look in the reference doc, and Spring seems to have pretty good support for sending mail. However, I need to login to a mail account, read the messages, and download any attachments. Is downloading mail attachments supported by the Spring mail API? I know you can do this with the Java Mail API, but in the past I've found th...