What Issues prevent Java applications from working on multiple platforms?

Java is supposed to be “write once, run anywhere” and it really can be, but in some cases it turns into “write once, debug everywhere”.

What are the most common reasons for problems when moving a Java application from one platform to another?

What are un-common but interesting reasons?


  • Don’t make assumptions about the case (in)sensitivity of the file system
  • Don’t make assumptions about the path or directory separator
  • Don’t make assumptions about the line terminator
  • Don’t use the default platform encoding unless you’re really, really sure you mean to
  • Don’t start “cmd.exe” etc (I know, it sounds obvious – but I’ve seen it cause problems)

Is there a good reason to configure hibernate with XML rather than via annotations?

I’ve been using Hibernate for a few years but have only used it with annotations, and by setting the connection parameters in my code.

Am I “missing something” by not using the XML files? Are there important capabilities available only in XML? Are there situations or patterns where it makes sense to use the XML?


I think it’s pretty safe to say that you’re not missing out on anything.

If there are any capabilities in XML that can’t be represented in attributes (and I believe there are some rare cases) then you still have the option to use [RawXml] and write the XML in the attribute. So you can’t possibly miss out on any functionality.

It might make sense to use XML if you have enough programmers in your team who simply prefer to manage separate files or if there is a genuine need to edit xml mappings on the fly. Xml mapping files are probably easier to manipulate for very complex mapping and they can contain useful information (comments on fetching strategies etc).

There is also the issue of architecture, where some people argue that separating the mapping into XML files provides a better separation between business-related code and instructions on how it is persisted.


How does Java method dispatch work with Generics and abstract classes?

I ran into a situation today where Java was not invoking the method I expected — Here is the minimal test case: (I’m sorry this seems contrived — the ‘real world’ scenario is substantially more complex, and makes much more sense from a “why the hell would you do that?” standpoint.)

I’m specifically interested in why this happens, I don’t care about redesign suggestions. I have a feeling this is in Java Puzzlers, but I don’t have my copy handy.

See the specific question in commends within Test<T>.getValue() below:

public class Ol2 {  

    public static void main(String[] args) {  
        Test<Integer> t = new Test<Integer>() {  
            protected Integer value() { return 5; }  


abstract class Test<T> {  
    protected abstract T value();  

    public String getValue() {  
        // Why does this always invoke makeString(Object)?  
        // The type of value() is available at compile-time.
        return Util.makeString(value());  

class Util {  
    public static String makeString(Integer i){  
        return "int: "+i;  
    public static String makeString(Object o){  
        return "obj: "+o;  

The output from this code is:

obj: 5


No, the type of value is not available at compile time. Keep in mind that javac will only compile one copy of the code to be used for all possible T’s. Given that, the only possible type for the compiler to use in your getValue() method is Object.

C++ is different, because it will eventually create multiple compiled versions of the code as needed.


Suggest a JPA Unit test framework

How to unit test JPA code? is there any way to generate Unit Test case itself?

Note: I am lazy and new to Unit Test code.


Check this out, Unitils. Here is a related discussion, with some example codes.

Here is the example, showing DBUnit, Spring and OpenJPA together. You might not using all, but this can take you somewhere if you want to go with DBUnit, I believe.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..