Saturday, November 26, 2016

Java and C


Java and C are two of the most common programming languages. When a person begins to learn computer science, he or she will learn either Java or C. We learn Java in CMSC 150, while one of my friends learns C++ in the introduction course of computer science of his university.

Both Java and C are imperative languages. The difference is that Java is object oriented, whereas C is function oriented. Unlike C, however, C++ supports object-oriented programming.

Compared with C, Java is more portable, as "write once, run anywhere". Different operating system can use JVM to interpret Java codes, but some C codes can only be executed in certain operating systems. This is because Java is interpreted language, and all codes will be transformed to bytecode and executed by JVM, whereas C is compiled language, and codes have to be translated by compiler to some codes that can be understood by the operating system first and then be executed.

Let’s compare Java and C specifically. See the following hello world codes from http://introcs.cs.princeton.edu/java/faq/c2java.html.
Java:
public class HelloWorld {
   public static void main(String[] args) {
       System.out.println("Hello");
   }
}

C:
#include<stdio.h>
int main(void) {
   printf("Hello\n");
   return 0;

}

---------------------------------------------------------------------------------

Writing References:
1.http://introcs.cs.princeton.edu/java/faq/c2java.html
2.http://durofy.com/10-major-differences-between-c-and-java/
Picture References:
1.http://code.rohitink.com/wp-content/uploads/2013/06/1301825696_183475245_1-Pictures-of-C-Java-for-10th-11th-12th-student-of-all-syllabus.jpg

1 comment:

  1. Hi,
    I have mostly heard of people starting their Computer Science journey by learning about Java first and then digressing into different languages. It is interesting to know that some people are also taught to start their Computer Science journey learning about the language C.

    ReplyDelete