what is difference between c language and java?
One difference is, C is not object oriented, Java is object oriented.
another difference: java is a high level programming lang. c is a low level programming lang,
java is based on c++ which is based on c .
c is not low level. In fact, it was one of the first high level languages made. More specifically, it was meant to replace the need for using a low level language for writing operating systems and added the high level transportability to that job. As such, it has more low level features than probably any other high level language. Also, it just looks more low level in retrospect because more and more languages have gotten further and further away from the low level stuff. However, the fact that it is transportable code breaks it off of being low level. See, a low level language is not abstracted from the hardware and is therefore not transportable. Oh, sure, some bits can be moved around within a processor family, but in general, it is not code you can easily reuse in every situation.
The biggest difference is that compiled Java code targets the JVM whereas compiled C code targets the native host architecture.
As for the original question, Java only makes byte code for the Java Virtual Machine. So you can't just compile Java and run it on any machine. It must go through the JVM to work on the machine.... LOL... someone just beat me to that.
The beauty of Java is that it only needs to be compiled once. The compiled code can then be run on any platform that has a Java Virtual Machine.
With C it must be compiled for every platform individually. This can be cumbersome when it comes to distribution, as you either need a separate package for each platform or some way of creating a package containing binaries for every supported architecture.
Oddly, that JVM dependence is a low level aspect. In that respect, Java gets pretty low level in a virtual sense. However, if the JVM targeted is not on the machine, you can have issues. So different versions of a Java class file and JVM can lead to unexpected results or the program not even running. The cure is usually to run the latest JVM and get the latest version of the class file.
An example of this in practice is Android. In most cases Android applications are written in Java. The nice thing about that is that means those apps will run without issue on practically all Android devices. For instance there are Android devices with x86 processors (the Intel Atom) and most Android devices run on ARM processors (and there are a number of different versions of ARM). Android applications can also be written in C, using the NDK (native development kit). In this case the developer must choose from a fixed list of architectures. The Android application will then be compiled for each chosen target architecture. Each compiled executable for each selected architecture is then included in the package (APK file). Unfortunately this means that any Android devices running on an architecture not included in the fixed selection will not be supported. Even worse if a new architecture is developed and an Android device is relesed on that architecture, then there is no chance it could have been supported by older native Android applications as that architecture wouldn't have even been on the list of target platforms when the build was performed.
Actually, Android does not run using the JVM. They just use Java as an existing language, but then compile to an Android specific byte code that uses a different VM. That is why not all Java or libraries will work when making an Android program.
You are just being pedantic here. I don't think it is worth getting into the technical details of dalvik vs art and whether or not JIT is used, etc.
The fact of the matter is, the byte code is still supported on all Android devices.
In any case from the above you might logically think that this makes Java the best choice. As it greatly improves portability. The problem is there is still a significant performance cost, even with JIT and other optimizations I will not discuss here. Ultimately for performance critical applications (for instance 3D game engines), C will still give you the highest performance.
It is a different byte code... It does show one other difference between Java and C. Java gets reused to make more than one type of byte code. In fact, there are also things to translate from Java to other destinations. For example, there are Java to ASM translators to make stand alone programs that don't use the JVM. But for C, they generally do not do this. In fact, several languages actually get translated to C, then the C is compiled. So rather than make a compiler for the programming language, they just make translator to C and compile the C. There are Java to C, Smalltalk to C, and others that do this. This makes C an intermediate language for compiling other languages, which Java does not have that I know of.
Also, since C is usually always compiled directly to the target architecture, it is often referred to as "close to the metal". This brings me to another difference. C is the language of choice for system level programming (device drivers and operating system kernels). Java is never used for this purpose.
Very true Alchemista, it is probably the lowest of the high level languages because it was designed originally for writing operating systems. It was only high level by the fact that you could then compile the operating system for different architectures which allowed for code abstraction. So while Java is also high level and abstract, it has a very different target use.
Join our real-time social learning platform and learn together with your friends!