Unlike Java, C++ is based on a hybrid approach to using both procedural and object-oriented methods. Java is the first pure object-oriented program offering a more dynamic, powerful approach to coding. In Java, everything is built on classes except the basic numeric and boolean types and provides object wrappers for those. Numbers, characters, and boolean values are crucial elements in both Java and C++. C++ utilizes stand-alone data and functions for these instances, whereas Java eliminates that. The only two main tasks of Java programming are to create objects and send messages to them.
The functionality of object-orientation in Java is an extension of C++, even though the concepts are fundamentally the same between the two languages. Both support encapsulation, inheritance, and polymorphism. Unlike C++, Java supports polymorphism automatically. Declaring a method to be virtual is not necessary. Computers running on Java automatically create a virtual method each time a method is overridden. Also, Java allows a class to inherit the properties of an existing class with inheritance. Essentially, C++ does the same thing with multiple inheritances. But in Java, no class can have more than one parent class. Java directly supports interfaces, rather than using the pure virtual mechanism in C++. Interfaces are like classes, except they don’t have any implementation of their own. They simply allow everything outside of an object to support a particular set of methods. By inheriting an interface, functionality is provided for the methods specified in the interface. Unlike using multiple classes in C++, multiple interfaces can be inherited in a single class with Java.
PRIMITIVES
The primitives in Java are basically the ideals of C++. There are two data types in Java, primitive types and reference types, whereas C++ has several type categories. Primitives are fixed, built in functionality within a language. By utilizing these concepts into the language, rather than limiting to classes, makes programming more robust and easier to use.
Primitive data members work differently in C++ and Java. Also in Java, with the class definitions one has the ability to initialize primitive data members. One may initialize them in the constructor. To my surprise, the data members are also automatically initialized to zero if they aren’t manually initialized in Java. With C++, if you don’t specifically initialize primitive type variables, they’ll contain garbage. Primitive data members of a class can’t be initialized in a class definition with C++, but local primitive type variables can potentially be initialized when they’re declared.
More specifically, all nonprimitive types are objects in Java, and are titled reference types because they pass by reference, or by object handles. In C++, there are structures, unions, enums, arrays, and other stand-alone data structures. All numeric types in Java are signed, whereas they can be signed or unsigned in C++. Boolean data types are primitive requiring them to be true or false, instead of having no explicit Boolean data type in C++. Thus, conditions are either true or false and not represented with integers. Also, Java makes use of 16-bit Unicode characters and C++ uses 8-bit ASCII characters.
ROBUST
Java is generally more robust than C++ for several reasons. Firstly, references, or handles, are automatically initialized to null. Secondly, those same references are checked before they’re accessed and before exceptions are thrown (if any problems occur). Thirdly, accessing arrays out of bounds is impossible. And finally, automatic garbage collection prevents memory leaks.
Java emphasizes early error checking to prevent possible problems, dynamic runtime checking, and avoiding erroneous situations; Java creates a robust runtime environment for all of its programs. . Although C++ derived strong compile-time checking from C, it is still’s susceptible to its loopholes. Implicit Declaration is one of the main characteristics of C, which causes C++ to be so error prone. The advantage of this is the elimination of having to worry about corrupting or freeing memory. There are no loopholes in Java that would compare to what you would find with C++, since it eliminates implicit types and function declarations. And since Java’s linker can understand the type system, it can perform more checks and be more effective during the development process.
Java can be verified at runtime since its compiled in byte-code. It verifies every memory access using bounds-checked arrays, sufficient type checking, and runtime linking to functions by name. Being able to keep Java programs within bounds, programmers no longer have to worry about memory leaks that are all too common in C++. When a C++ program allocates free memory, a pointer is returned. If that pointer is lost, the memory can’t be deleted, causing memory leaks that lead to nothing but trouble, headaches too. By using this sort of verification process with proper exception handling, Java can avoid potentially bringing down the system.
DEVELOPMENT PROCESS
Java incorporates a combination of compilation and interpretation. The interpreter is the software, which implements Java’s virtual machine. When Java programs run, they are first compiled into byte-codes, which are much like the machine instructions. Usually, the interpreter is written in compiled, native language designed for each platform. This feature can make Java programs very efficient. The byte code is simply interpreted by the native machine instructions, rather than storing it. The consequence is a much simpler linking process, making the development process much faster. Since byte-codes aren’t limited to use on any particular computer, it can be used on many different computers without having to recompile any code. On the other hand, C++ code generally needs to be recompiled as new technology becomes available leaving it generally unstable.
SECURITY
Security and privacy is a major concern for Internet users. And since the Internet has become so widespread and as traffic continues to increase online, so does the need for security. For the designers of Java, security was a major issue. Java’s compiler and runtime system allow for several different ways to protect against faulty code. With the complex environment, it makes the assumption that absolutely no data can be trusted and proceeds from there.
The approach to handling memory is much different in C++ and Java. Instead of using the compiler to determine the memory layout, Java’s virtual machine does this at runtime. Thus, memory addresses in Java can’t be known ahead of time. This way programmers can’t use pointers to allocate a piece of memory. With Java, programmers can’t find memory locations, nor does Java’s pointer allow for this. Therefore, Java is much safer than its predecessor.
Furthermore, Java’s byte code is rigidly verified at runtime. The complier makes several checks ranging from the verification of the code format to the verification of any running byte code with the use of a theorem ensuring its security. After these initial checks, the interpreter can execute worry free, not too mention effectively.
Also, Java prevents classes from deceiving a program with the use of multiple namespaces. By default, all class accesses go to the local namespace. Therefore, accessing a class within a foreign namespace has to be done by the accessing program. Also, separate namespaces for classes can be loaded from different locations. All of the disadvantages of namespace in C++ are solved in Java by including everything in a class, and collecting classes into packages.
ARCHITECTURALY NETURAL
The same Java program can be used and supported on any computer with the Java virtual machine. This is a huge milestone for Internet developers. The Internet is a diverse network since so many different computer types are connected. Java is the ideal language for connecting so many computer systems, due to the fact that it isn’t tied to any specific platform. Transmitting Java programs with byte code allows it to run on any chip and doesn’t require being compiled making it universal and the operating system irrelevant.
This wouldn’t be possible with C++. In order for a language such as C++ to perform on multiple platforms, each user would have to use source code and compile it before running a program. This would make the task complicated and more susceptible to errors.
MULTITHREADING
Utilizing multithreading allows Java programs to have more than one action happen at once, taking advantage of multiple processors. For example, one thread may be interacting with the user, while another may doing complex calculations. Multi threads are very similar to processes. However, multiple threads share the same address space and thus, they can share variables and methods while keeping local variables. In comparison to processes, multi threads are very simplistic and have the capability to run hundreds of threads simulations simultaneously.
Events can happen in any given order during the execution of multi threads. Therefore, Java offers native multithreading support, which is needed to control this type of environment. With Java, all threads are mapped on the operating system directly when supported, unlike the C++ language that requires the use of external libraries to execute multi threads. Incorporating this function into the language allows developers to easily incorporate these features into a program. Although the actual performance is reliant on the operating system, multithreading usually increases the performance.
GARBAGE COLLECTION
Garbage collection is a technique that, in Java, disposes of objects, which are no longer needed. In the form of a thread, this function watches all references and periodically checks each one to determine if it’s still needed. At that point, the garbage collection frees all of the memory allocated for that object. Garbage collection makes programming easier and can eliminate entire classes of errors. This feature was left out of the development of C++ because this would have caused a conflict with C as far as compatibility is concerned. Automatic garbage collection wasn’t suitable for many low-level tasks that its intended for in C++. However, there aren’t any compatabilty issues with Java. Thus, this feature was incorporated into the language and now, programmers don’t have to concern themselves with free blocks of memory, making the language safe and simplistic
POINTERS AND DATA STRUCTURES
Java lacks pointers and specific data structures, but that’s not a bad thing. Unlike C++, several data structures classes can be found in the standard version of Java; contained in the standard class library. Java does not support pointers, or at least Java will not allow the developer to change any address contained in the pointer, nor will it support the use of pointer arithmetic. Unlike Java, C++ supports pointers with dereferencing (* or ->) and with address operators (&) that can lead to potential memory leaks. Java doesn’t utilize pointer arithmetic for array references, but it does automatically check the limits of the array index. Array lengths for multidimensional arrays can vary in Java, but are fixed in C++. Since everything consists of objects in Java, Strings are objects to, whereas strings are nothing more than null-terminated character arrays in C++. Furthermore, Java has a built in string-linking operator and C++ relies solely on library functions for such an operation. Also, typedefs are used in C++ to define types but has been eliminated in Java.
Conclusion:
The advantages are simple. Java’s use of a pure object oriented program offers far more capability than C++’s hybrid approach to this sort of programming and is ultimately an extension of that technology. This makes designing reusable components and classes far simpler with Java. The Primitive, or built-in, functionality Java offers also shows far more potential than C++’s traditional use of libraries allow. Java is developed much more efficiently and realistically, is more or less the ideal C++ language; eliminating the concern of corrupting or freeing memory that prevent hideous problem C++ programmers often encounter, increases productivity, avoiding a lot of frustrating debugging, and further expands the idea of strong compile-time checking. Also, Java’s different way of handling memory offers huge security advantages on networks with byte-code compilation, allowing many new preventative methods. And running on multi platforms makes it ideal for the Internet considering all of the various platforms people use as a means of accessing the Internet. Multi threading allows for multiple processors and is built in, whereas C++’s use of external libraries cannot compare to what Java’s features have to offer in terms of processing. The use of automatic garbage collection and the elimination of pointers and various stand-alone data structures expand Java’s portability while increasing it efficiency.
Java is compelling. It is obviously the next evolutionary step from C++. By discarding many imperfections C++ inherited from its predecessor, Sun Microsystems was able to developing a pure object-oriented language, which can run on multiple platforms (on any operating system). Java’s simplicity, portability, security, and universality make it potentially superior to all of its competitors. Java has been described as the solution to all problems. It has made web design what C++ couldn’t. Although C++ is very powerful, it has risks. Java solved the problem. A single code-base that runs on different platforms is truly one of the greatest accomplishments in software development. Java is full of potential. Even operating systems such as Windows have a difficult time supporting every platform with a single set of code. Thus, it is possible for Java to make operating systems obsolete. If that were the case, it would take over the world and put an end to Microsoft’s domination. It’s possible, but only time will tell.
Bibliography/References
- Eckel, Bruce. "Learning Java." Software Development April 1996.
-
"Frequently Asked Questions - Applet Security" 11 March 1996.
-
Gosling, James, and Henry McGilton. "Java--Simple and Familiar." 7 March 1996 Chap. 2 of "The Java(tm) Language Environment: A White Paper."
-
---. "Security in Java" 7 March 1996 Chap. 6 of "The Java(tm) Language Environment: A White Paper."
-
Hayashi, Alden M. "The Developer of Java Speaks About its History, Future Direction." Application Development Trends. February 1996.
-
Ladd, Robert Scott. C++ Components and Algorithms. San Mateo: M&T Books, 1992.
- "The Java Language: A White Paper." http://java.sun.com/doc/overview/index.html 7 March 1996.
-
"Java Report." 7 March 1996.
-
"The Java Series." 7 March 1996.
-
Stroustrup, Bjarne. The Design and Evolution of C++. Murray Hill: AT&T Bell Labs, 1994.
-
Van Hoff, Arthur, Sami Shaio, and Orca Starbuck. Hooked on Java. Reading: Addison-Wesley, 1996.
-
Sams Publishing. Teach Yourself C++ in 21 Days – Third Edition. USA: February 1999.
-
Sams Publishing. Teach Yourself Java in 24 Hours – Second Edition. Indianapolis, Indiana: November 2000.
-
Patrick Niemeyer and Joshua Peck. Exploring Java. Sebastopol, CA: O’Reilly & Associates, May 1996.
-
IDG Books Worldwide, Inc. Java for Dummies, 3rd Edition, Foster City, CA, 1998.
Sams Publishing. Teach Yourself Java 2 in 24 Hours (USA: Indianapolis, 2000) 156-157.
Van Hoff, Arthur, Sami Shaio, and Orca Starbuck. Hooked on Java. (Reading: Addison-Wesley, 1996) 10-11.
Patrick Niemeyer Joshua Peck. Exploring Java (USA: California, 1996) 130-142.
Sams Publishing. Teach Yourself C++ in 21 Days (USA: Indianapolis, 1999) 392-408
Patrick Niemeyer Joshua Peck. Exploring Java (USA: California, 1996) 82-83.
Stroustrup, Bjarne. The Design and Evolution of C++. (Murray Hill: AT&T Bell Labs, 1994) 25-30.
IDG Books Worldwide, Inc. Java for Dummies, 3rd Edition (USA: California, 1998) 252-255.
Patrick Niemeyer Joshua Peck. Exploring Java (USA: California, 1996) 65-71.
Sams Publishing. Teach Yourself Java 2 in 24 Hours (USA: Indianapolis, 2000) 305-322.
“Java versus C++: Pointers and Data Structures”. . (Excerpt from “Java Software Solutions” by Lewis and Loftus. Appendix I, pp. 609-614)