SNS COLLEGE OF TECHNOLOGY, COIMBATORE–35 Union in ++ C++ Vs : What’s the Difference? What is the C++ language?

C++ is a computer programming language that contains the feature of C programming language as well as Simula67 (first object Oriented language). C++ introduced the concept of Class and Objects.

It encapsulates high and low-level language features. So, it is seen as an intermediate level language. Earlier it was called "C with classes" as it had all the properties of the C language. What is the Java language?

Java is programming language developed by Sun Microsystems. A small software development team developed this language. They were known as the Green Team, who initiated Java language in the year 1991. History of C++

C++ language was developed by Bjarne Stroustrup at AT & T Bell Laboratories. Stroustrup was a strong supporter of C and an admirer of Simula67. He wanted to combine the best of both the languages. He was aiming to create a language which supports object-oriented programming features and still retains the power of C. This resulted in C++. History of Java

The Java language was initially called OAK. Originally, it was developed for handling devices and set-top boxes. Oak was a massive failure. Thus, in 1995 Sun changed the name to Java and modified the language to take advantage of the burgeoning World Wide Web development business.

Later, in 2009, Oracle Corporation acquired Sun Microsystems and took ownership of two key Sun software assets: Java and Solaris.

Difference Between C++ and Java Parameter C++ Java No strict relationship between class names The strict relationship is enforced, e.g., and filenames. In C++, header files and Relationship the source code for class PayRoll has to implementation files are used for specific be in PayRoll.java. class. Parameter C++ Java I/O input mechanism is a quite complex Input I/O statements use in and cout, e.g., in » x; as it reads one at a time (System.in). mechanism cout« y; Output is easy, e.g. System.out.println(x); Complier and Java supports both compiler and C++only support compiler Interpreter interpreter compatibility No backward compatibility with any Compatible with C source code, except with other previous language. The syntax is some exceptional cases. languages influenced by C/C++. Access control Flexible model with constant protection The cumbersome model encourages week and object available encapsulation. protection Concept Write once compile anywhere Write once run anywhere everywhere Support for Allows both procedural programming and Support object-oriented programming programming object-oriented programming. model. type Only call through the Allows direct calls to native system libraries. Interface and recently Java Native Access Memory Accessible to programmer System controlled management C++ there is no such root hierarchy. C++ Java is a pure object-oriented supports both procedural and object-oriented Root hierarchy Programming language. That's. Why It programming; therefore, it is called a hybrid follows single root hierarchy. language. Java support automatic garbage C++ supports Object-oriented features Best features collection. It does not support destructors Procedural programming features. as C++ does. Java has no goto statement. The keywords C++ has a goto statement. Although, it is not Goto Statement got, and const are reserved even if they ideal to a use a goto statement. are not used. C++ provide multipleInheritance. The Multiple keywordvirtual is used to resolveproblems Java doesn't provide multiple inheritance. inheritance during multipleinheritance if there is any. C++ has scope resolution operator (: :) No scope resolution operator (: :) in Java. which is used to define a method outside of Scope resolution The method definitions have to occur a class and to access a global variable within operator within a class, so there is no need for from the scope where a local variable also scope resolution. exists with the same name. In Java, Exception handling is different because there are no destructors. Also, in Use of try and In C++, you can't include the try/catch even Java, try/catch must be defined if the catch if the function throws an exception. function declares that it may throw an exception Java only supports method overloading. It Supporting C++ supports both method overloading & does not provide support for operator method operator overloading overloading. The source must be recompiled for the Bytecode classes are transferrable to Portability platform; hence the code is not portable. platform-specific JVM's. Consistent between primitive and object Type semantics Differ for primitive and object types. types. Libraries Predominantly low-level functionality Massive, classes for high-level services. Runtime error Programmer responsibility. System Responsibility. detection Supports Points, structure, and union. Threads and interfaces. Functions and data may exist external to any Functions & All function and data exist within classes; class, global and namespace scopes are Data package scope are available. available. C++ programs are platform dependent. They Java programs are platform independent. Platform need to be compiled for a particular Java programs are written for Java Virtual Parameter C++ Java platform. Machine (JVM). It will run without needing recompilation. Runtime error In C++, It is Programmer responsibility to It is system responsibility to check error detection check the errors. in the program. Java offers only limited support for Pointer C++ support pointers. pointers. Structure It supports structures. It does not any support for structures. Unions C++ supports unions. Java does not support unions. Java is heavy depend on automatic Object C++ supports manual object management garbage collection. It does not support management with the help of new and delete keywords. destructors. Conclusion:

 C++ is object-oriented programming (OOP) language  Java is programming language developed by Sun Microsystems  Bjarne Stroustrup developed C++ at AT & T Bell Laboratories in Murray Hil.  The Java language was initially called OAK. Originally, it was developed for handling devices and set-top boxes.  No strict relationship between class names and filenames. In C++, header files and implementation files are used for specific class.  The strict relationship is enforced, e.g., the source code for class PayRoll has to be in PayRoll.java.