There are always some constraints on specific platforms that cannot be ignored. Examples are things like the maximum length of filenames or the available RAM on a system. No matter how much you try to be platform-independent, your code may fail if you try to run it on a platform that is too tightly constrained.
Java retains platform independence even after code is compiled because it compiles to platform-independent bytecode the actual conversion to native code is handled at a later time after the bytecode is loaded by the JVM.
There are occasional bugs in language implementations that only occur on certain platforms. In the specific case of Java: Java code is platform-independent in the sense that the same Java application or algorithms typically compiled to Java bytecode and packaged in a.
Improve this answer. BobDalgleish 4, 5 5 gold badges 16 16 silver badges 23 23 bronze badges. Apart from the technical info being good, this is also really well written. Really simple, in the same way that Hemingway writes on an elementary school level. I have no doubt even a complete non-programmer could understand this. Example: Android apps or libs written in java often need reference android specific stuff like Android-Context or Android-Activity which doe not existis outside of android so these are not portable.
If you masochistically use backslashes as path separators it's not going to work in linux but if you use forward slashes, in most cases it will work fine in both Windows and Linux. It is available for multiple platforms so it is platform dependent — pcodex. In practice, that seems to mean Java is "write once, test everywhere". Gulshan Gulshan 9, 10 10 gold badges 54 54 silver badges 89 89 bronze badges. This approach was also taken years ago by Borland in its Delphi product.
They made another IDE called Kylix which is Delphi for Linux that allows sharing the same code base between Windows and Linux and compiling native applications for both platforms. They also did the same when they first released Delphi. If you were careful enough you will be able to write code that can be compiled to native windows and.
Net platforms. Jalayn 9, 4 4 gold badges 37 37 silver badges 57 57 bronze badges. The meaning of platform-independent is that the java compiled code byte code can run on all operating systems. A program is written in a language that is a human-readable language. It may contain words, phrases, etc which the machine does not understand. For the source code to be understood by the machine, it needs to be in a language understood by machines, typically a machine-level language.
So, here comes the role of a compiler. The compiler converts the high-level language human language into a format understood by the machines. Therefore, a compiler is a program that translates the source code for another program from a programming language into executable code. This executable code may be a sequence of machine instructions that can be executed by the CPU directly, or it may be an intermediate representation that is interpreted by a virtual machine.
It is JVM which morphs the code into a language a particular platform machine will understand. This bytecode is utilised by JVM Java Virtual Machine and converted into a language the machine on which Java is being run would understand.
For this particular reason, that Java is platform-independent it is also portable. Platform independence is the phenomenon by virtue of which languages, frameworks, tool and software do not have to undergo any major changes to be fit to run on different platforms and devices. Platform dependent languages, tools and frameworks differ from platform independent languages, tools and frameworks in a way that only platform independent ones can be executed on any machine whereas platform dependent ones have to be modified for them to be executed on different machines depending upon the operating system and machine architecture.
Now, as we saw that java is platform-independent, this is all because of the ability to generate the bytecode. Forming the intermediate stage, i. To explore articles on Java , click here. About Us. Privacy Policy. Bug Bounty. Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search.
Not really. Your Java program is running within the JVM, which acts as a translation layer between the Java byte code and the native machine code. It hides the platform-specific details from the Java application code.
This is not the case with C. C code typically runs natively, so there is no translation layer isolating it from platform-specific details. Your C code can be directly affected by platform-specific differences word sizes, type representations, byte order, etc. A strictly conforming C program, which uses nothing outside of the standard library and makes no assumptions about type sizes or representation beyond the minimums guaranteed by the language standard, should exhibit the same behavior on any platform for which it is compiled.
All you need to do is recompile it for the target platform. However, if I wanted to write something GUI-driven, or something that communicated over a network, or something that had to navigate the file system, or anything like that, then I'm reliant on system-specific tools and I can't just rebuild the code on different platforms. It's not the language itself that is platform dependent.
In the same way, it is possible to compile Java for a specific target instead of JVM. Compiling java source code to native exe. C is designed to be very close to the hardware.
There's not really a reason to use C if your target is JVM. Then use Java instead.
0コメント