Friday, August 24, 2007

Java Advantages & Disadvantages


Advantages of JAVA

Java has gained enormous popularity since it first appeared. Its rapid ascension and wide acceptance can be traced to its design and programming features, particularly in its promise that you can write a program once, and run it anywhere. Java was chosen as the programming language for network computers (NC) and has been perceived as a universal front end for the enterprise database. As stated in Java language white paper by Sun Microsystems: "Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture neutral, portable, multithreaded, and dynamic."

Java is simple

No language is simple, but Java considered a much simpler and easy to use object-oriented programming language when compared to the popular programming language, C++. Partially modeled after C++, Java has replaced the complexity of multiple inheritance in C++ with a simple structure called interface, and also has eliminated the use of pointers.

The reason that why Java is much simpler than C++ is because Java uses automatic memory allocation and garbage collection where else C++ requires the programmer to allocate memory and to collect garbage. Also, the number of language constructs in Java is small for such a powerful language. The clean syntax makes Java programs easy to write and read.

Java is Object-oriented Object-oriented programming models the real world. Everything in the world can be modeled as an object. For example, a circle is an object, a person is an object, and a window's icon is an object. Even a mortgage can be perceived as an object. Java is object-oriented because programming in Java is centered on creating objects, manipulating objects, and making objects work together.

An object has properties and behaviors. Properties are described by using data, and behaviors are described by using methods. Objects are defined by using classes in Java. A class is like a template for the objects. An object is a concrete realization of a class description. The process of creating an object class is called instantiation. Java consists of one or more classes that are arranged in a treelike hierarchy, so that a child class is able to inherit properties and behaviors from its parent class. An extensive set of pre-defined classes, grouped in packages that can be used in programs are found in Java.

Object-oriented programming provides greater flexibility, modularity and reusability. For years, object-oriented technology has been perceived as an elitist, requiring substantial investments in training and infrastructure. Java has helped object-oriented technology enter the mainstream of computing, with its simple and clean structure that allows the programmer to write easy to read and write programs.

Java is Distributed

Distributed computing involves several computers on a network working together. Java is designed to make distributed computing easy with the networking capability that is inherently integrated into it. Writing network programs in Java is like sending and receiving data to and from a file. For example, the diagram below shows three programs running on three different systems, communicating with each other to perform a joint task.

Portability: Program once, Run anywhere (Platform Independence)

One of the most compelling reasons to move to Java is its platform independence. Java runs on most major hardware and software platforms, including Windows 95 and NT, the Macintosh, and several varieties of UNIX. Java applets are supported by all Java-compatible browsers. By moving existing software to Java, you are able to make it instantly compatible with these software platforms. JAVA programs become more portable. Any hardware and operating system dependencies are removed.

Java source code is a little more portable than C-based languages. In C and C++, each implementation decides the precision and storage requirements for basic data types (short, int, float, double, etc.). This is a major source of porting problems when moving from one kind of system to another, since changes in numeric precision can affect calculations and assumptions about the size of structs can be violated. Java defines the size of basic types for all implementations; an int on one system is the same size (and can represent the same range of values) as on every other system. It does not permit the use of arbitrary pointer arithmetic, so assumptions about struct packing and sizes can't lead to non-portable coding practices.

Although C and C++ are supported on all platforms that support Java, these languages are not supported in a platform-independent manner. C and C++ applications that are implemented on one operating system platform are usually severely intertwined with the native windowing system and OS-specific networking capabilities. Moving between OS platforms requires recompilation, as a minimum, and significant redesign, in most cases.

Java is Interpreted

An interpreter is needed in order to run Java programs. The programs are compiled into Java Virtual Machine code called bytecode. The bytecode is machine independent and is able to run on any machine that has a Java interpreter. Normally, a compiler will translate a high-level language program to machine code and the code is able to only run on the native machine. If the program is run on other machines, the program has to be recompiled on the native machine. For example, if you compile a C++ program in Windows, the executable code that is generated by the compiler can only be run on a Windows platform. With Java, the program need only be compiled once, and the bytecode generated by the Java compiler can run on any platform.

Security

Java is one of the first programming languages to consider security as part of its design. The Java language, compiler, interpreter, and runtime environment were each developed with security in mind. The compiler, interpreter, and Java-compatible browsers all contain several levels of security measures that are designed to reduce the risk of security compromise, loss of data and program integrity, and damage to system users. Considering the enormous security problems associated with executing potentially untrusted code in a secure manner and across multiple execution environments, Java's security measures are far ahead of even those developed to secure military systems. C and C++ do not have any intrinsic security capabilities. Can you download an arbitrary untrusted C or C++ program and execute it in a secure manner?

Reliability

Security andreliability go hand in hand. Security measures cannot be implemented with any degree of assurance without a reliable framework for program execution. Java provides multiple levels of reliability measures, beginning with the Java language itself. Many of the features of C and C++ that are detrimental to program reliability, such as pointers and automatic type conversion, are avoided in Java. The Java compiler provides several levels of additional checks to identify type mismatches and other inconsistencies. The Java runtime system duplicates many of the checks performed by the compiler and performs additional checks to verify that the executable bytecodes form a valid Java program.

Multimedia: Images, Sounds and Animation

The sizzle of JAVA is MULTIMEDIA - Sounds, Images, Graphics and Video. In this growing age of multimedia, new computers are known as "multimedia ready" with CD-Rom drives, sound cards, 3D accelerator cards and other new special sound or graphic technology capabilities. Multimedia demands incredible computing power and only recently - in the past 5 years at least, affordable computers of this kinds are becoming widespread.

We also need programming languages that make creating multimedia easy. Most programming languages do not have built-in multimedia capabilities. JAVA, however through the packages of classes that are an integral part of the Java programming world, provides extensive multimedia facilities that will enable a programmer to start developing powerful multimedia applications immediately. Among the image formats supported by Java is the Graphics Interchange Format .GIF and Joint Photography Experts Group .JPEG. Among the audio formats are AIFF, AU and WAV. Music formats currently supported are MIDI Type 0, MIDI Type 1, and Rich Music Format (RMF). Sound formats now allow 8- and 16-bit audio data, in mono and stereo, with sample rates from 8 kHz to 48 kHz. Capability to play MPEG- Layer 2 and 3 formats are also available. And the list goes on, and continues to grow.

The Virtual Machine: Java VM

This VM sits, metaphorically, between the Java program and the machine it is running on, offering the program an "abstract computer" that executes the Java code and guarantees certain behaviors regardless of the underlying hardware or software platform. Java compilers thus turn Java programs not into assembly language for a particular machine but into a platform-neutral "byte code" that the machine-specific VM interprets on the fly.

The Java VM also enforces security policies, providing a sandbox that limits what the Java program can do. A Java applet cannot, for example, peek into arbitrary files on the machine it's running on. The most recent version of Java from Sun, known as Java Development Kit (JDK) 1.1, though, provides no consistent method for an applet to request restricted system resources. This capability will be available in JDK 1.2, due out later this year.

Networking

JavaBeans

A key addition to JDK 1.1 is support for JavaBeans, a component model for Java. JavaBeans make it easy to write reusable components that can be strung together with a minimum of additional coding. Although Microsoft's ActiveX offers similar advantages, Beans are less focused on a Windows-centric world and are somewhat more portable. Still, ActiveX does have the advantage of supporting any underlying programming language, while Beans are designed solely to encapsulate Java.

JavaBeans offer a promising mechanism for building general-purpose business components that you can reuse with minimal modifications.

Other Language Features

The Java language provides many language features that make it preferable to C or C++ for modern software development. On the top of this list is Java's intrinsic support for multi-threading, which is lacking in both C and C++. Other features are its exception-handling capabilities, which were recently introduced into C++; its strict adherence to class and object-oriented software development; and its automated garbage-collection support. In addition to these features, Java enforces a common programming style by removing the capability to slip outside the class- and object-oriented programming paradigm to develop C-style function-oriented programs.

Java is Robust

Robust means reliable and no programming language can really assure reliability. Java puts a lot of emphasis on early checking for possible errors, as Java compilers are able to detect many problems that would first show up during execution time in other languages. Java eliminates certain types of programming constructs in other languages that are prone to errors. For instance, Java does not support pointers, which eliminates the possibility of overwriting memory and corrupting data. Java has a runtime exception-handling feature to provide programming support for robustness, and can catch and respond to an exceptional situation so that the program can continue its normal execution and terminate gracefully when a runtime error occurs.

Java is Portable

One advantage of Java is that its programs can run on any platform without having to be recompiled. This is one positive aspect of portability. It goes on even further to ensure that there are no platform-specific features on the Java language specification. For example, in some languages, such as Ada, the largest integer varies on different platforms. In Java, the size of the integer is the same on every platform, as is the behavior of arithmetic. Having a fixed size for numbers makes Java programs portable. The Java environment itself is portable to new hardware and operating systems, and in fact, the Java compiler itself is written in Java.

Java is Multithreaded

Multithreaded is the capability for a program to perform several tasks simultaneously within a program. For instance, downloading a mp3 file while playing the file would be considered multithreading. In Java, multithreaded programming has been smoothly integrated into it, while in other languages, operating system-specific procedures have to be called in order to enable multithreading. Multithreading is especially useful in graphical user interface (GUI) and network programming. In GUI programming, many things can occur at the same time. For example, a user is able to listen to a mp3 file and surf the Web at the same time. In network programming, a server can serve multiple clients at the same time. Multithreading is a necessity in visual and network programming.

Java is Architecture Neutral

The most remarkable feature of Java is that it is architecture neutral. Architecture neutral means that it is platform independent. A Java program can be run on any platform with a Java Virtual Machine. Many major operating system vendors have adopted the Java Virtual Machine, and soon Java will be able to run on all machines. Java's initial success lies in its Web programming capability. Java applets can be run from a Web browser, but Java is in actual, more than just a Web applet. Stand-alone Java applications can also be run directly from operating systems using a Java interpreter. Nowadays, software vendors usually develop multiple versions of the same product so that it can run on different platforms, such as Windows, OS/2, Macintosh, and various UNIX, VMS, Open/VMS, and IBM mainframes. Using Java, the developers need to only to write one version, and this one version will be able to run on all of the platforms.

Java is Dynamic

The Java programming language was designed to adapt to an evolving environment. New methods and properties can be added freely in a class without affecting their clients. Also, Java is able to load classes as needed at runtime. As an example, you have a class called 'Square'. This class has a property to indicate the color of the square, and a method to calculate the area of the square. You can add a new property to the 'Square' class to indicate the length and width of the square, and a new method to calculate the perimeter of the square, and the original client program that uses the 'Square' class remains the same.

Disdvantages of JAVA

The main disadvantage of Java is speed.

Although Java's ability for producing portable, architecturally neutral code is desirable, the method used to create this code is inefficient. As mentioned above, once Java code is compiled into byte code, an interpreter called a Java Virtual Machine, specifically designed for a computer architecture, runs the program. Why is this a problem? "Java, being an interpreted system, is currently an order of magnitude slower than C." (Just Java, 302). Unlike natively compiled code, which is a series of instructions that correlate directly to a microprocessors instruction set, an interpreter must first translate the Java binary code into the equivalent microprocessor instruction. Obviously, this translation takes some amount of time and, no matter how small a length of time this is, it is inherently slower than performing the same operation in machine code.

How important is this speed difference?

According to PC Magazine, it appears very significant: "Compared with native code, Java VMs are excruciatingly slow. ... Java still cannot compete with natively compiled C++ code." (PC Magazine, April 7, 1998, 104). The difference in speed between C++ and Java is very important. Even with all of Java's benefits, Java will not be widely accepted if it can not perform adequately. C++ has been widely adopted by developers and they will not be willing to change languages if the applications they develop with Java do not measure up to their personal and their clients standards. However, if the speed difference is negligible, developers may be willing to learn and program in Java because of the significant advantages the language offers. Before developers can make this decision, they need an accurate picture of what the speed tradeoffs between the two languages are.

Does not support real-time programming. Smallest collection of available development tools (although this is changing). Language is still immature compared to alternatives.

No comments: