In general, Java is the language of the Internet, which can be used to create two types of programs: applications and applets. The output of a Java compiler is not executable code, but rather bytecode - making the Java run-time system an interpreter for bytecode.
Similarities
The two main similarities between Java and C++ are that they both use similar syntax, such as the general forms of the for, do, and while loops. Secondly, they both support object-oriented programming.
Differences
On the contrary, there are a number of differences between the two languages. Some main features that are not supported in Java are:
1. Perhaps the single greatest difference between C++ and Java, is that Java doesn’t support pointers, therefore the -> operator DNE as well.
2. Java does not include structures or unions because the class encompasses these other forms. It is redundant to include them.
3. Java does not support operator overloading.
4. Java does not include a preprocessor or support the preprocessor directives.
5. Java does not perform any automatic type conversions that result in a loss of precision.
6. All the code in a Java program is encapsulated within one or more classes.
7. Therefore, Java does not have global variables or global functions.
8. Java does not support multiple inheritance.
9. Java does not support destructors, but rather, add the finalize() function.
10. Java does not have the delete operator.
11. The << and >> are not overloaded for I/O operations.
12. Java does not support templates.
13. Java supports “garbage collection”, where as C++ does not.
There are also a number of other differences between the way Java and C++ relate to classes. By default, members of a class are accessible by other members of their class, derived classes, and by other members of their package. Therefore, class members are “more public” than they are in C++, however, the private access specifier applies only to the variable or method that it immediately precedes. All class objects are instantiated in Java using the new operator. Therefore, all class objects are dynamically allocated. When there are no references to an object, then the object is considered inactive.
Java includes two class-management features that help make using and organizing classes easier. The first is called a package, which defines a scope. Therefore, names declared inside a package are private to that package. Java uses file directories to store packages. Therefore, each package must be stored in a directory that has the same name as the package—including capitalization.
Java, like C++, supports hierarchies of classes. However, the way that inheritance is implemented in Java differs substantially from the way that it is implemented in C++. Since multiple inheritance is not allowed in Java, Java class hierarchies are linear. In Java, inheritance is referred to as subclassing. A base class in C++ is referred to as superclass in Java.
And there you have it, hope that helps.
Tuesday, August 21, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment