java-5

When should I use the java 5 method cast of Class?

Looking through some code I came across the following code trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); and I'd like to know if casting this way has any advantages over trTuDocPackTypdBd.update((TrTuDocPackTypeDto)packDto); I've asked the developer responsible and he said he used it because it was new (which d...

Java Generics: Generic type defined as return type only

I'm looking at some GXT code for GWT and I ran across this use of Generics that I can't find another example of in the Java tutorials. The class name is com.extjs.gxt.ui.client.data.BaseModelData if you want to look at all of the code. Here are the important parts: private RpcMap map; public <X> X get(String property) { if (allowNes...

Convert java 5 code using generics to code that can run on a J2ME device?

Are there any solutions or tools that transform java 5 code that uses all the new java 5 features(generics, autoboxing, varargs, static imports) into code that can run on a J2ME device? I am particularly interested in handling generics - the other features are nice to have but not mandatory. I need source code as the result of this conv...

Is there a log4j or commons logging extension or other logging framework that is designed for Java 5 or higher?

Java 5 has introduced many features that can be make logging statements less cluttering, such as variable number of arguments and printf. That can alleviate all the message building code that happens when something is logged, as well as the surrounding if. For example, instead of writing: if (log.isDebugEnabled() { log.debug("User ...

What is the easiest way to iterate over all the key/value pairs of a java.util.Map in Java 5 and higher?

What is the easiest way to iterate over all the key/value pairs of a java.util.Map in Java 5 and higher? ...

Executing Java 5 Code With Java 6

Is there any way I can run class files (i.e. with main as the entry point) on JDK 6 that were compiled with Java 5? ...

what is the use of <T> in public static <T> T addAndReturn(T element, Collection<T> collection){ ....

Hi All, I am getting confused as and when i come across a generic method of this sort? public static <T> T addAndReturn(T element, Collection<T> collection){ collection.add(element); return element; } The reason being is that i could not understand why is required in this method? Also, I would be greatful to you if you can ...

send a mail from java5 and java6

I know similar questions have been asked many times befor, but I think this one slitly different :) I'm writing a maven report plugin which will send emails to a list of users. I now have the problem, that the code seems to be working fine when I run it with java5, but failes with java6. Actualy the plugin is writen in Groovy and uses t...

XML to Java Object only using Java5 (no external libs)

Hi, normally I would use JaxB, XMLBeans or Simple to convert a XML file to a Java Object. In this case I can however only use Java5 and no external libraries (for several reasons). What is the best way to do that? My XML input is very simple. What is the most flexible and elegant way to get the XML into a Java-Object (I don't really ne...

Java version migration deprecated date methods

I'm migrating from Java 1.1. to Java 5. I notice that some methods have been deprecated e.g. java.util.Date has a getYear() method which is deprecated. My question is if the getYear() method is left as it is in 1.1 will it still function in Java 5 ...

Is it possible to complie Java 1.5 source Web Applications to 1.4?

I tried compiling my webapplication with javac – source 1.5 – target 1.4 I end up with the error: javac: source release 1.5 requires target release 1.5 Since I’m using generics and other features; when I try compiling with –source 1.4 I end up with the errors: (use -source 5 or higher to enable generics) (use -source 5 or higher to en...

Do you use Java annotations?

Possible Duplicates: How and where are Annotations used in Java? Java beans, annotations: What do they do? How do they help me? Over and over, I read about Java 5's annotations being an 'advanced feature' of the language. Until recently, I haven't much used annotations (other than the usual @Override, &c), but work on a n...

Pop-up window in Java Swing

Hey, Can someone suggest me how to implement a pop-up window in Java Swing. I want the pop-up window to be a modal window (user cannot return to the main window when the pop-up is open). I tried doing it using JDialog but it allows only one widget for user input to be in it whereas I need multiple widgets. I may be wrong here but this ...

(JPA/Toplink) Network error IOException: Address already in use: connect

Hello, I have a JPA project which used to work. This month, I have added some data in my database. When I run the usual job (I used to run on preceeding months), I get this error: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException Internal E...

Enums With Default Throw Clause?

I noticed the following in the Java Language spec in the section on enumerations here: link switch(this) { case PLUS: return x + y; case MINUS: return x - y; case TIMES: return x * y; case DIVIDE: return x / y; } throw new AssertionError("Unknown op: " + this); However, looking at the switch statement definition section, I...

Best ways to write a method that updates two objects in a multithreaded java environment?

Suppose we have a class called AccountService that manages the state of accounts. AccountService is defined as interface AccountService{ public void debit(account); public void credit(account); public void transfer(Account account, Account account1); } Given this definition, what is the best way to implement transfer() so that y...

How to find out the drag source component in the drop target TransferHandler?

Question is regarding Java 5 and Drag n Drop. Is there a way to determine the drag source component in the drop target TransferHandler? I need to know this in my canImport(..) or importData(..) method in order to take different actions for transfer data of the same type or DataFlavor. The way I have achieved this currently is to hijac...

FindBugs: How can I run it in Java 5 mode?

When I run FindBugs on my project via Maven, I get lots of these: Can't use annotations when running in JDK 1.4 mode! How do I fix that? Couldn't find anything in the manual. ...

Reasons and advantages for upgrading to Java 6 for a non-technical decider (at the client)

I'd like to upgrade from Java 5 to Java 6. We all know about the technical advantages and benefits, but: I have the problem that a major client refuses to upgrade from java 5 to java 6 because of "the risks" and "no/too few benefits for us" (banking sector). What can be answered to a non-technical decider at the client what benefits he...

Java5 on Windows service app - get Full Thread Dump need clarification

I've looked through couple of articles here such as: http://stackoverflow.com/questions/2124672/java-stack-dump-on-windows http://stackoverflow.com/questions/239544/thread-dump-programmatically-jdi-java-debugger-interface But didnt catch the exact answer. The problem: There is a Java5 Application on Windows that's runs as a service (...