Differences among C , C++ and Java
Table of Content:
Introduction to C, C++, and Java
C is a general-purpose high-level language that was originally developed by Dennis Ritchie in 1972 for the Unix operating system. C is a successor of B language which was introduced around 1970. C is a structured language which is easy to learn and produces efficient programs. it's a top-down approach. It can handle low-level activities and can be compiled on a variety of computers. Today C is the most widely used System Programming Language.
C++ is a general-purpose programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs, designed to make programming more enjoyable for the serious programmers.C++ is a superset of the C programming language. In addition to the facilities provided by C, C++ provides flexible and efficient facilities for defining new types. The key concept in C++ is class. A class is a user-defined type.
Java is a programming language created by James Gosling from Sun Microsystems in 1991. The first publicly available version of Java (Java 1.0) was released in 1995. The Old name of Java was Oak. Java is now taken by Oracle Corporation. The acquisition of Sun Microsystems by Oracle Corporation was completed by Oracle in January 2010. The current version of Java is Java 1.8 ( Java 8 ). Java is a Programming language as well as a Platform itself.
Although Java was modeled after C and C++ languages, it differs from C and C++ in many ways. Java does not incorporate a number of features available in C and C++. For the benefit of C and C++ programmers, we point out here a few major differences between C/C++ and Java language.
Java also adds some new features, while C++ is a superset of C, Java is neither a superset nor a subset of C or C++.
C vs Java
1. JAVA is Object-Oriented while C is procedural. Different Paradigms, that is.
Most differences between the features of the two languages arise due to the use of different programming paradigms. C breaks down to functions while JAVA breaks down to Objects. C is more procedure-oriented while JAVA is data-oriented.
2. Java is an Interpreted language while C is a compiled language.
We all know what a compiler does. It takes your code & translates it into something the machine can understand-that is to say-0’s & 1’s-the machine-level code. That’s exactly what happens with our C code-it gets ‘compiled’. While with JAVA, the code is first transformed to what is called the bytecode. This bytecode is then executed by the JVM(Java Virtual Machine). For the same reason, JAVA code is more portable.
3. C is a low-level language while JAVA is a high-level language.
C is a low-level language(difficult interpretation for the user, closer significance to the machine-level code) while JAVA is a high-level lagunage(abstracted from the machine-level details, closer significance to the program itself).
4. C uses the top-down {sharp & smooth} approach while JAVA uses the bottom-up {on the rocks} approach.
In C, formulating the program begins by defining the whole and then splitting them into smaller elements. JAVA(and C++ and other OOP languages) follows the bottom-up approach where the smaller elements combine together to form the whole.
5. Pointer go backstage in JAVA while C requires explicit handling of pointers.
When it comes to JAVA, we don’t need the *’s & &’s to deal with pointers & their addressing. More formally, there is no pointer syntax required in JAVA. It does what it needs to do. While in JAVA, we do create references for objects.
6. The Behind-the-scenes Memory Management with JAVA & The User-Based Memory Management in C.
Remember ‘malloc’ & ‘free’? Those are the library calls used in C to allocate & free chunks of memory for specific data(specified using the keyword ‘sizeof’). Hence in C, the memory is managed by the user while JAVA uses a garbage collector that deletes the objects that no longer have any references to them.
7. JAVA supports Method Overloading while C does not support overloading at all.
JAVA supports function or method overloading-that is we can have two or more functions with the same name(with certain varying parameters like return types to allow the machine to differentiate between them). That it to say, we can overload methods with the same name having different method signatures. JAVA(unlike C++), does not support Operator Overloading while C does not allow overloading at all.
8. Unlike C, JAVA does not support Preprocessors, & does not really them.
The preprocessor directives like #include & #define, etc are considered one of the most essential elements of C programming. However, there are no preprocessors in JAVA. JAVA uses other alternatives for the preprocessors. For instance, public static final is used instead of the #define preprocessor. Java maps class names to a directory and file structure instead of the #include used to include files in C.
9. The standard Input & Output Functions.
Although this difference might not hold any conceptual(intuitive) significance, but it’s maybe just the tradition. C uses the printf & scanf functions as its standard input & output while JAVA uses the System.out.print & System Resources and Information..read functions.
10. Exception Handling in JAVA And the errors & crashes in C.
When an error occurs in a Java program it results in an exception being thrown. It can then be handled using various exception handling techniques. While in C, if there’s an error, there IS an error.
Difference between C and Java
C Programming | Java Programming |
---|---|
It does include the unique statement keywords sizeof and typedef. | It does not include the C unique statement keywords sizeof, and typedef. |
It contains the data type struct and union. | It does not contain the data type struct and union. |
It defines the type modifiers keywords auto, extern, register, signed, and unsigned. | It does not define the type modifiers keywords auto, extern, register, signed, and unsigned. |
It supports an explicit pointer type. | It does not support an explicit pointer type. |
It has a preprocessor and therefore we can use # define, # include, and # ifdef statements. | It does not have a preprocessor and therefore we cannot use # define, # include, and # ifdef statements. |
It requires that the functions with no arguments, with the void keyword | It requires that the functions with no arguments must be declared with empty parenthesis, not with the void keyword |
C has no operators such as instanceof and >>>. | Java adds new operators such as instanceof and >>>. |
C adds have a break and continue statements. | Java adds labeled break and continue statements. |
C has no object-oriented programming features. | Java adds many features required for object-oriented programming. |
What is the difference between C and C++?
C++ is derived from C Language. It is a Superset of C. The major difference between C and C++ is that C is a procedural programming language and does not support classes and objects, while C++ is a combination of both procedural and object oriented programming language; therefore C++ can be called a hybrid language. Earlier C++ was known as C with classes. In C++, the major change was the addition of classes and a mechanism for inheriting class objects into other classes. Most C Programs can be compiled in C++ compiler. C++ expressions are the same as C expressions. All C operators are valid in C++. The following table presents differences between C and C++ in detail.
C | C++ |
---|---|
C supports procedural programming paradigm for code development. | C++ supports both procedural and object oriented programming paradigms; therefore C++ is also called a hybrid language. |
C does not support object oriented programming; therefore it has no support for polymorphism, encapsulation, and inheritance. | Being an object oriented programming language C++ supports polymorphism, encapsulation, and inheritance. |
In C (because it is a procedural programming language), data and functions are separate and free entities. | In C++ (when it is used as object oriented programming language), data and functions are encapsulated together in form of an object. For creating objects class provides a blueprint of structure of the object. |
In C, data are free entities and can be manipulated by outside code. This is because C does not support information hiding. | In C++, Encapsulation hides the data to ensure that data structures and operators are used as intended. |
C, being a procedural programming, it is a function driven language. | While, C++, being an object oriented programming, it is an object driven language. |
C does not support function and operator overloading. | C++ supports both function and operator overloading. |
C does not allow functions to be defined inside structures. | In C++, functions can be used inside a structure. |
C does not have namespace feature. | C++ uses NAMESPACE which avoid name collisions. A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries. All identifiers at namespace scope are visible to one another without qualification. Identifiers outside the namespace can access the members by using the fully qualified name for each identifier. |
C uses functions for input/output. For example scanf and printf .
|
C++ uses objects for input output. For example cin and cout .
|
C does not support reference variables. | C++ supports reference variables. |
C has no support for virtual and friend functions. | C++ supports virtual and friend functions. |
C provides malloc() and calloc() functions for dynamic
memory allocation, and free() for memory de-allocation.
|
C++ provides new operator for memory allocation
and delete operator for memory de-allocation.
|
C does not provide direct support for error handling (also called exception handling) | C++ provides support for exception handling. Exceptions are used for "hard" errors that make the code incorrect. |
C was developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs. | C++ was developed by Bjarne Stroustrup in 1979 with C++'s predecessor "C with Classes". |
When compared to C++, C is a subset of C++. | C++ is a superset of C. C++ can run most of C code while C cannot run C++ code. |
In C
|
In C++
|
Differences among C, C++ and Java Programming Languages: C vs C++ vs Java
The purpose of learning a programming language is to become a better programmer i.e. to become more effective at designing and implementing new systems and at maintaining old ones.
C, C++, and Java are the most popular programming languages used today at a broad level. They have a pretty similar syntax for basic concepts. Most of the basic constructs like if statements, loops, function syntax, switch case statements and concepts like recursion are still valid. Many other concepts like the syntax for comments, and the idea of static class variables, also held in both Java and C++.
Java uses the syntax of C and structure of C++ language.
Aspects | C | C++ | Java |
---|---|---|---|
The developed year | 1972 | 1979 | 1991 |
Developed By | Dennis Ritchie | Bjarne Stroustrup | James Gosling |
Successor of | BCPL | C | C(Syntax) & C++ (Structure) |
Paradigms | Procedural | Object Oriented | Object Oriented |
Platform Dependency | Dependent | Dependent | Independent |
Keywords | 32 | 63 | 50 defined (goto, const unusable) |
Datatypes: union, structure | Supported | Supported | Not Supported |
Pre-processor directives | Supported (#include, #define) | Supported (#include, #define) | Not Supported |
Header files | Supported | Supported | Use Packages (import) |
Inheritance | No Inheritance | Supported | Multiple Inheritance not Supported |
Overloading | No Overloading | Supported | Operator Overloading not Supported |
Pointers | Supported | Supported | No Pointers |
Code Translation | Compiled | Compiled | Interpreted |
Storage Allocation | Uses malloc, calloc | Uses new, delete | uses garbage collector |
Multithreading and Interfaces | Not Supported | Not Supported | Supported |
Exception Handling | No Exception handling | Supported | Supported |
Templates | Not Supported | Supported | Not Supported |
Storage class: auto, extern | Supported | Supported | Not Supported |
Destructors | No Constructor or Destructor | Supported | Not Supported |
Database Connectivity | Not Supported | Not Supported | Supported |