Is Java platform independent?

Theoreticaly yes. But what if i use Borland JBuilder (or MS J++, for that matter)? They come with their own SDK. How do i know my (uncompiled) code is going to work on an other machine? How do i know it's the same syntax? How big projects do we talk about before the differences start to "feel"?



Kind Regards
Konrad
----------------------------
(+46/0) 708-70 73 92
[email protected]
www.chamster.com

Comments

  • : Theoreticaly yes. But what if i use Borland JBuilder (or MS J++, for that matter)? They come with their own SDK. How do i know my (uncompiled) code is going to work on an other machine? How do i know it's the same syntax? How big projects do we talk about before the differences start to "feel"?
    :
    :
    : Kind Regards
    : Konrad
    : ----------------------------
    : (+46/0) 708-70 73 92
    : [email protected]
    : www.chamster.com
    :
    With Microsoft you don't even know if you're compiled code will work :P.

    Well, I don't think there are any non-standard extensions to Java at the source code level, and your code should work no matter where you compile it if you use the same libraries. If you stick to just the standard Java libraries your code should compile with any current Java compiler. The source for MS J++ should still work with everything else, I believe, I think it's just the library and the runtime engine that doesn't, I'm not sure though.

    I don't know if any new syntax elements have been added to specific Java implementations, but I guess it's like C. Stick to the standard syntax and you shouldn't have a problem.

    I have no idea what that last question is.

    "No Bad Religion song can make your life complete."
    -No Direction, Bad Religion


  • : I have no idea what that last question is.

    I had a hunch that it would be a though one... Example taken from C++ as you seem to be familiar with the language:

    As long as you stick to console mode you have no problems changing between different implementations. As your apps get more sophisticated you will add some graphics and BOOM - you're stuck with YOUR compiler.

    I was wondering wheter some simple source code snippets created with Borlands JBuilder may be "cut out" and "pasted in" as text into another IDE and *without needing any adaptiation* are going to work. You have kind of answered my question already anyway. :)



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    [email protected]
    www.chamster.com


  • You do have to be very careful to ensure you're using only standard Java libraries, of course. Most of the big-name IDEs make it very easy to use libraries supplied with the IDE instead of or alongside the standard Java classes, and although you can generally redistribute the libraries that may prove to be unwieldy, and may have unacceptable licensing implications.

    It's also worth pointing out that the whole 'Write Once Run Anywhere' (WORA) concept is somewhat inaccurate. There are some areas of the Java spec where exact performance isn't specified (threading springs to mind as an example) and even fully compliant JVMs may perform radically differently on different platforms. Also, in any application the size of a JVM there are likely to be bugs, and these bugs are different on different platforms, so workarounds may be required. The more different APIs you're working with, the more likely you are to encounter such a bug. A better description of Java's platform independence is 'Write Once Test Everywhere' (WOTE).

    That said, I've been fairly impressed in the past by how well large Java apps have performed across different platforms without any modification.

  • : You do have to be very careful to ensure you're using only standard Java libraries, of course. Most of the big-name IDEs make it very easy to use libraries supplied with the IDE instead of or alongside the standard Java classes, and although you can generally redistribute the libraries that may prove to be unwieldy, and may have unacceptable licensing implications.
    :
    : It's also worth pointing out that the whole 'Write Once Run Anywhere' (WORA) concept is somewhat inaccurate. There are some areas of the Java spec where exact performance isn't specified (threading springs to mind as an example) and even fully compliant JVMs may perform radically differently on different platforms. Also, in any application the size of a JVM there are likely to be bugs, and these bugs are different on different platforms, so workarounds may be required. The more different APIs you're working with, the more likely you are to encounter such a bug. A better description of Java's platform independence is 'Write Once Test Everywhere' (WOTE).
    :
    : That said, I've been fairly impressed in the past by how well large Java apps have performed across different platforms without any modification.
    :
    To demonstrate what iapetus was talking about here a statistics from "The Complete Reference of Java 1.1" 2nd Edition, (Java 2 came out like the next damn week, dammit).

    Here's the output from the same program run on Windows 95 and on Solaris. The program just spawns two threads sets them to different priorities and each thread just increments a counter.

    Win95:

    Low-priority thread: 434104
    High-priority thread: 4860791

    Solaris:

    Low-priority thread: 0
    High-priority thread: 3062507

    Due to the way Solaris implements threading the low-priority thread was completely overridden by the higher priority thread. This could be a real big problem in some programs. So, as quoted from this book...

    "For the near future, it is important that you not write code that depends on the preemptive behavior of Windows 95 or any other operating system. If you do, your applications will almost surely fail when run on other platforms. Hopefully, over time, consistent behavior between environments will be achieved."

    Technically, it could be achieved by the JVM handling thread priorities, and the JVM always asking for equal-priority threads. Of course, that would definitely add weight to the JVM and the programs running on it, and it could be somewhat awkward to implement efficiently.

    "No Bad Religion song can make your life complete."
    -No Direction, Bad Religion


  • That was about what i wante to know.
    Thank to you all.



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    [email protected]
    www.chamster.com


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories