Milwaukee school of Engineering - Sample Essay
I have been heavily involved with programming throughout my high school career. I’ve studied two years of Java and have taken two college courses at Milwaukee School of Engineering, which covered C++. I have a good background in both languages. Though familiar with the languages, I have analyzed the differences between the two in-depth and clearly stated the advantages Java has over C++. I will explore many various topics and issues regarding both languages, including object-orientation, primitive types, development processes, architecture, and their effectiveness.
As you will see, Java has many superior qualities and offers great advances for the computer programming industries in the near future. This new design offers many opportunities. Contents Page: Introduction Page 3 Body Page 3 Object-orientation Page 3 Primitives Page 4 Robust Page 4 Development Process Page 5 Security Page 5 Architecturally Neutral Page 5 Multithreading Page 6 Garbage Collection Page 6 Pointers and Data Structures Page 6 Conclusion Page 7 Bibliography Page 8 Word Count = 3,163 Intro: Java is one of the greatest advancements in the history of computer programming and is derived from C++.
Programs written in C++ need to be compiled according to each particular computer chip. Thus, when new chips come out, most software must be recompiled. As we all know, once prices become too high for a particular chip, a newer, more efficient one is manufactured and distributed. C++ is not a very adaptive, whereas Java is designed to adapt to an emergent environment. Originally, Java was created by Sun Microsystems for consumer electronics. Java experiments with a new type of interface, which can be used in basic electronic devices we use in our everyday life that require very reliable code.
With this technology, one can create incredibly smart devices with software that can run on any computer chip. Thus far, Java has had its greatest impact on the Internet. It offers possibilities that were unimaginable given the limitations of C++. Having basically revolutionized the computer industry, it’s rather difficult to underestimate its significance Ultimately, Java is a simple, object-oriented, interpreted and compiled, secure, robust, high-performing, portable, multithreaded, dynamic, architecturally neutral, and generally purposeful programming language that makes everything easier than its predecessor.
Its design was heavily influences by imperfections of C++. Here again, C++ was heavily influenced by the flaws of its predecessor C and was a milestone for programming its time. The simplicity of Java is a result of omitting confusing, seldom used, poorly understood features from C++. These features include multiple inheritance, operator overloading, pointers, structures, multi-dimensional arrays, unions, templates, typedefs, unsigned numeric data types, null-terminated strings, stand alone functions, goto, pointers to lists, and more built-in, potentially limiting features.
The purpose of this paper is not to compare the history of the languages or their complexity; rather it will discuss the differences between the two, and describe the programming advantages the emergence of the Java language offers. Body: OBJECT-ORIENTATION The programs one creates with Java and C++ can be thought of as objects, just as objects exist in the real world. They each exist independently and interact with other objects in specific ways. Often, they can be combined with other objects to form something more complex.
Each object contains two things: attributes and behaviors. Attributes are the things that describe the object and the behavior is its functionality. With object-oriented programming, every program is a group of objects that work together to get something done. 1 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 languages2. Both support encapsulation, inheritance, and polymorphism. Unlike C++, Java supports polymorphism automatically3. 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 inheritances4. 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. 5.
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 prone6. 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-code7. 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 interpretation8. 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 calculations9. 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 leaks10. 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 1. Eckel, Bruce. “Learning Java. ” Software Development April 1996. 2. “Frequently Asked Questions – Applet Security” http://www. javasoft. com/sfaq/index. html 11 March 1996. 3.
Gosling, James, and Henry McGilton. “Java–Simple and Familiar. ” http://java. sun. com/whitePaper/java-whitepaper-4. html 7 March 1996 Chap. 2 of “The Java(tm) Language Environment: A White Paper. ” 4. —. “Security in Java” http://java. sun. com/whitePaper/java-whitepaper-8. html 7 March 1996 Chap. 6 of “The Java(tm) Language Environment: A White Paper. ” 5. Hayashi, Alden M. “The Developer of Java Speaks About its History, Future Direction. ” Application Development Trends.