Java was designed for networks. Rapidly increasing Network presents new challenges. One challenge presented by networked computing environment is the wide range of devices that the network interconnects. A typical network has different kinds of devices with diverse hardware architecture, Operating Systems and purpose. Java architecture addresses this challenge by creating platform independent programs.
Java architecture has four distinct but interrelated technologies:
- Java Programming language
- Java class file format
- Java Application Programming Interface [API]
- Java Virtual Machine [JVM]
When you write Java program, you are tapping the power of these four technologies. you write the program in the source file, compile to Java class file, and run the class file containing bytecode on JVM. You access system resources in your program by calling methods in the classes that implements Java API methods.
JVM and Java API forms a platform. Java programs can run on many different kinds of computers because the Java Platform can itself be implemented in software.
When you compile java program on one Operating System the java compiler generates bytecode. You can run that bytecode on any Operating System which has its own implementation of JVM. JVM interprets bytecode and generates native code for the corresponding Operating System. Because of bytecode and JVM, Java is called platform independent [Write once, run anywhere]. But there are few exceptions.
Java is mostly platform independent because of below exceptions:
- If you are relying on libraries that make calls to OS functions: you can either code and compile for each platform or write in OS detection & conditional function calls. For more details click here.
- Java Native Interface [JNI]: JNI is used in case standard java class library may not support platform-dependent feature needed by your application. You already have library or application written in other language and you wish to make it accessible to the java application, then JNI can be used. In a way, you're losing platform portability when using JNI. We will discuss more on JNI in the next post.
- If you are using GUI frameworks, components are displayed according to the view of Operating System.
- You are coding/compiling for a JVM that is not widely supported.
- Your code has higher/more/different hardware requirements than your target platforms support (e.g. relying on a specific input mechanism; or coding software meant to run on a smart TV or refrigerator [yes, some fridges run Java now] that needs 1G of memory, 2 cores & an always-on internet connection).
Despite all these exceptions, Cross-platform incompatibility should not cause you to completely rewrite code.


Good one. Few more to add here...
ReplyDeleteRarely hardware built for the Internet use Java, because it demands more hardware & slower(unless samsung or lg builds a smart tv or refrigirator). In my last startup, we were building a video-over-the-web platform and we had to reprogram & flash a 2500/- TV AV stick. Was done in C++, Webkit, JS, HTML & CSS
I tinker with my Raspberry Pi for making fun side projects. Go & Node is what I've used because of lite memory & computing footprints. Java is out of the question for inexpensive IoT products.
Just my thoughts. Feel free to disagree :-)