NCERT Computer: Chapter 6 – Fundamentals of Internet and Java Programming Part 5
Java and C++
Java is a derivative of C and C++: simple, familiar syntax and with fewer complex features.
It does not have many of the poorly understood, confusing and rarely used features of C++.
There are no pointers in Java only tightly bounded arrays. This eliminates the possibility of over writing memory and corrupting data unwittingly.
Pointers have been the source of raw power in C and C++ programs as well as the primary feature that helped introduce bugs into almost all programs. Java is sophisticated enough to help programmers express complex ideas using arrays and has an efficient automatic garbage collector based memory management scheme. In addition, unlike C or C++, Java does not support structures, enums or functions. Every programmable object is an instance of a 'class' in object oriented Java.
Java does not support multiple inheritance whose semantic and usage has been quite controversial in other languages.
6.7 Characteristic of Java
(I) Simple and Small
Java is easily programmable, with a minimum of training, since it is based on C++. Most of the development tools available today are huge in size and complexity, and require powerful development platforms.
(Ii) Object Oriented
An object-oriented design enables the development of small, modular, yet selfcontained units, each of which could later be used as building block for any specific application.
It also facilitates a clean definition of interfaces and allows 'plug-and-play' features, wherein reusable software components can be distributed easily across diverse hardware platforms.
Programmers can even attach their applications and data together, and bundle the combination as a single entity.
Java retains many of the object oriented features and the 'look and feel' of C++. Hence, programmers can migrate easily to Java and be productive quickly
To be truly considered as 'object oriented' a programming language should support a minimum of four characteristics.
Encapsulation - implements information hiding and modularity (abstraction).
Polymorphism - the same message sent to different objects results in behaviour that is dependent on the nature of the object receiving the message.
Inheritance - you define new classes and behaviour based on existing classes to obtain code re-use and code organization.
Dynamic binding - objects could come from anywhere possibly across the network. You need to be able to send messages to objects without having to know their specific type at the time you write your code. Dynamic binding provides maximum flexibility while a program is executing.
(Iii) Portable and Interpreted
A software application written in Java, be it a word-processor or spreadsheet, a multimedia tool or virtual reality designer, will run perfectly on any computer, on any platform.
A Java application is a combination of a compiled and interpreted language.
The source code written by a programmer is first compiled into Byte Code which is uniform for all machines.
(Iv) Architecture - Neutral
The Java Compiler generates an architecture-neutral object file, 'generic' Byte Code instructions, which have nothing to do with particular computer architecture.
The same version of the software runs on all platforms, independent of any CPU or hardware architecture, across networks.
Java completely avoids dependency on other software components like libraries.
Therefore, Java applications are always ready-to-run, without any side-effects, irrespective of changes or revisions that may take place in those external components.
Java has an extensive library of routines for easy distribution of applications as it abides by industry standard networking protocols like TCP/IP, HTTP, and FTP.
(Vii) Automatic Memory Management
This contributes enormously to making the code robust.
The Java garbage collector keeps tracks of all objects generated, automatically freeing the memory used by objects that have no further use and are not referred to by other existing objects.
Multithreading is a way of building applications with multiple processes.
The garbage collector is efficiently run as a background process overcoming the biggest drawback of garbage collector based languages.
The result is better interactive response and near real-time features.
This enables Java to interface and support many features of modern operating systems and new protocols.
Java programs are robust because explicit memory manipulations by the programmer are prevented.
Java programs are secured: distributed applications have to exhibit the highest levels of security concerns.
A type code verifier in the Java interpreter ensures that the complied code is strictly language compliant, thus trapping all malafide modifications, more so the computer viruses parading as legal code.