Structured Programming | Object-Oriented Paradigm | Class | Object | Method | Abstraction |
Encapsulation | Data Hiding | Inheritance | Reusability | Polymorphism | Dynamic Binding
11 INTRODUCTION
One characteristic that is constant in the software industry today is “change”. Change is one of the
most critical aspects of software development and management. New tools and new approaches are
announced almost everyday. The impact of these developments is often very extensive and raises a
number of issues that must be addressed by the software engineers. Most important among them are
maintainability, reusability, portability, security, integrity, and user friendliness of software products.
To build today's complex software it is just not enough to put together a sequence of programming
statements and sets of procedures and modules. We need fo use sound construction techniques and
program structures that are easy to comprehend, implement and modify in a wide variety of situations.
Since the invention of the computer, many programming approaches have been tried. These
include techniques such as modular programming, top-down programming, bottom-up programming
‘and structured programming. The primary motivation in each case has been the concem to handle
the increasing complexity of programs that are reliable and maintainable. These techniques became
popular among programmers over the last two decades.
With the advent of languages such as G, structured programming became very popular and
was the paradigm of the 1980s. Structured programming proved to be a powerful tool that enabled
programmers to write moderately complex programs fairly easily. However, as the programs grow
larger, even the structured approach failed to show the desired results in terms of bug-free, easy-to-
maintain, and reusable programs.
Object-Oriented Programming (OOP) Is an approach to program organization and development,
Which attempts to eliminate some of the pitfalls of conventional programming methods by
incorporating the best of structured programming features with several new concepts. It is a new way
of organizing and developing programs and has nothing to do with any particular language. However,
rot all languages ate suitablo {0 implement the COP concepts easily. Languages that support
OOP features include Smalltalk, Objective C, C++, Ada and Object Pascal. C++, an extension of
C language, is the most popular OOP language today. C++ is basically a procedural language with2. Programming with Java
object-oriented extension. Java, a pure object-oriented language, is one of the recent languages
added to this list, the latest one being C##,
1.2 OBJECT-ORIENTED PARADIGM
major objective of object-oriented approach is to
auminate some of the flaws encountered jn the procedural
approach. OOP treats data as a critical element in the program
development and does not allow it to flow freely around the
system, It ties data more closely to the functions that operate
on it and protects it from unintentional modification by other
functions. OOP allows us to decompose a problem into a
number of entities.called Objects and then build data and
functions (known as methods in Java) around these entities. oe
The combination of data and methods make up an object
(see Fig. 1.1).
The data of an object can be accessed only by the methods
associated with that object. However, methods of one object
can access the methods of other objects. Some of the features
of object-oriented paradigm are: Object = Data + Methods
1. Emphasis is on data rather than procedure.
2. Programs are divided into what are known as Objects.
3. Data structures are designed such that they characterize the objects.
4. Methods that operate on the data of an object are tied together in the data structure.
5. Data is hidden and cannot be accessed by external functions.
6.
7.
8.
Method
}. Objects may communicate with each other through methods.
. New data and methods can be easily added whenever necessary.
. Follows bottom-up approach in program design.
Object-oriented paradigm is the most recent concept among programming paradigms and means
different things to diferent people. It is therefore important to have a working definition of object-
oriented programming before we proceed further.
Object-oriented programming is an approach that provides a way of modularizing programs
py creating partitioned memory area for both data and functions that can be used as templates
for creating copies of such modules on demand. This means that an object is considered to be
2 Parlilioned afea of computer memory that stores data and a set of operations that can access the
data. Since the memory partitions are independent, the objects can be used in a vari i t
Programs without modifications. eee
1.3 BASIC CONCEPTS OF OBJECT-ORIENTED PROGRAMMING
As mentioned earlier, object-oriented is a term, which is inter i i
a ' rpreted differently by different people.
7 7 shetlore necessary to understand some of the concepts used extensively in object-oriented
ian . now discuss the general concepts of OOP which form the heart of Java
Objects and Classes
Objects are the basic runtime entities
a place, a bank account, a table of dat
i an object-oriented system. They may represent a person,
represent user-defined data types such
‘a of any item that the program ma
h y handle. They may also
8 vectors and lists, Any Programming problem is analyzed inFundamentals of Object-Oriented Programming 3
terms of objects and the nature of communication
between them. Program objects should be
chosen such that they match closely with the
real-world objects. AS pointed out earlier, an
object takes up Space in the memory and has an
associated address like a record in Pascal, or a
structure in C.
When a program is executed, the objects
interact by sending messages to one another,
For example, ‘customer’ and ‘account’ are two
objects in a banking program, then the customer
object may send a message to the account object
requesting for the balance. Each object contains
data and code to manipulate the data. Objects
can interact without having to know the details of
each other's data or code. It is sufficient to know
the type of message accepted and the type of
response returned by the objects. Although different authors represent them differently, Fig. 1.2 shows
a notation that is popularly used to represent an object in object-oriented analysis and design.
We just mentioned that objects contain data and code to manipulate that data. The entire set of
data and code of an object can be made a user-defined data type using the concept of a class. A class
may be thought of as a ‘dala type’ and an object as a ‘variable’ of that data type. Once a class has
been defined, we can create any number of objects belonging to thal class. Each object is associated
with the data of type class with which they are created, A class is thus a collection of objects of similar
type. For example, mango, apple and orange are members of the class fruit. Classes are user-defined
data types and behave like the built-in types of a programming language. For example, the syntax
used to create an object is no different than the syntax used to create an integer object in C. If fruit
has been defined as a class, then the statement
fruit mango;
Object
Name Data
BasicPay
Salary () _Mothods
Z| Representation of an object
will create an object mango belonging to the class fruit.
Data Abstraction and Encapsulation
The wrapping up of data and methods into a single unit (called class) is known as encapsulation. Data
encapsulation is the most striking feature of a class. The data is not accessible to the outside world
and only those methods, which are wrapped in the class, can access it. These methods provide the
interface between the object's data and the program. This insulation of the data from direct access by
the program is called dafa hiding. Encapsulation makes it possible for objects to be treated like ‘black
boxes’, each performing a specific task without any concern for internal implementation (see Fig. 1.3).
Abstraction refers to the act of representing essential features without including the background
details or explanations. Classes use the concept of abstraction and are defined as a list of abstract
attributes such as size, weight and cost, and
methods that operate on these attributes. They
encapsulate all the essential properties of the ad
objects that are to be created. Encapsulation is "formation “in” Data
one of the three COP principles, the other two
being inheritance and polymorphism.
The concept of data encapsulation and ab-
straction can be well understood by consider-
ing the simple example of a mobile phone. It is
Information “out”
[EEBEEG) Encapsulation—Objects as “black boxes”———_
4 Programming th Java
ication. How the
is used for text and voice communi
wich is verte end user 10 talk {0 remote person is irrelevant from jy,
eo about is the fact thal by Pressing the green ‘Anet®
3 Tus, the user is isolated from all the complex oe
he mobile phone.
‘5 that can be perform
.ctronic device,
a complex ele
functions to en:
of the mobile phone
viewpoint. The only thing
key, he can talk to the person 09 {!
virdah is well encapsulated within | aa with a mobile Phone—dlaling cay
y
Now, think of the standard operation !
‘counya Cal, ene jing and receiving text messege tc. Also, consider the common data elements
that are found in all types of mobile phone” ie, address DOO. inbox, sent items, etc. We can refer ty
these sets of data and operations a5 an abs' generic mobile phone. All the mobile phon,
of different makes adhere to this Spetraction of a generic mobile phone. In other words, we can fe
that all mobile phones from different manufacturers ‘are nothing but different instances of this commo,
abstraction of a generic mobile phone n
Inheritance
Inheritance is the process by whic
class. Inheritance supports the con
h objects of one lass acquire the properties of objects of anoth,
cept of hierarchical classification. For ‘example, the bird robin ig
is
a part of the class flying bird, which is again a part of the class bird. As illustrated in Fig. 1.4, th
principle behind this sort of division ig that each derived class shares common characteristics with te
e
class from which it is derived.
In OOP, the concept of inheritance provides the idea of reusability. This means that we car
2d oot fcateres to an existing class without modifying i. THs TS essible by deriving a new aes
acne iaing one. The new class will have the combined features of both the clasees. Ths os
that it allows the programmer to reuse epi
real appeal and power of the inheritance mechanism is
that is almost, but not exactly, what he wants, and to tailor the class in such a way that it does
ot
Rate
| Bird
| Attributes: |
| Feathers
| Layeggs |
Nonflying
Bird
| Attributes:
‘Swallow
f
| Attributes:
fer :
») Penguin Kiwi
Attributes:
j
© Attributes:
I
Property inheritanceFundamentals of Object-Oriented Programming 5
troduce any undesirable side effects i
inode Into the rest of the classes. In Java, the derived class is known
Note that each subclass defines only those fe
0 atures th: i
inheritance, each Class would have to explicitly include all of ieteue Sa ete
Polymorphism
Polymorphism Is another important OOP concept. Pelymorphism means the ability to take more
than one form. : ‘xample, an operation may exhibit different behavior in different instances. The
bios depen upon the types dia used inthe eperation, For example, consider the operation
tion. , the operation will generate a sum. If the oj i
Of aefon Would produce o tia sting by contact Cae operand ar stings hen the
name can be used to handle different number and different types of arguments. This is something
similar to a particular word having several different meanings depending on the context.
[ Girete Object © Box Object ™ “Triangle Object |
k Draw (Circle) Draw (box) Draw (Triangle)
Polymorphism
Polymorphism plays an important role in allowing objects having different internal structures to
share the same external interface. This means that a general class of operations may be accessed
in the same manner even though specific actions associated with each operation may differ.
Polymorphism is extensively used in implementing inheritance.
Compile Time and Runtime Mechanisms
In the context of a programming language, compile time may refer to any of the following:
«The operations performed by the compiler such as syntactic and semantic analysis
«The pre-runtime assessment of the program's behavior
In Java, apart from syntax and semantic checks, one important logical task that is considered to be
performed at compile time is the implementation of inheritance. Itis at compile time that the child class
inherits the public data members and methods of the base class.
Runtime, on the other hand, is the time period when a syntactically correct program is actually
executed in the computer system. Thus, all the tasks that are performed during this time period are
prefixed with the word ‘runtime’ or ‘dynamic’, such as runtime type checking or dynamic memory
allocation, In Java, one of the important concepts that is associated with runtime is the implementation
of polymorphism. It is also referred as dynamic binding, as explained in the next section.
Dynamic Binding
Binding refers to the linking of a procedure call to the code to be executed in response to the call.
Dynamic binding means that the code associated with a given procedure call s not known until6 Programmi with Java
ism and inheritanc
i ime. It is associated with polymorphi 2A peo
the fine Fe a - Heron, Gepends on the dynamic type of that reference.” eee ap
Mee By inheritance, every object will have this pro
draw procedure will be redefined jn ec ‘
cl
associated with a po He Le
ider the procedure “dra\ . 1.5.
Ca ROW que to each object and So the draw
ihe code matching the object under current reference will by nc
alleg
however, unit
algorithm is, t
he object. At runtime,
that defines
Message Communication
program consists of a set of objects that communicate with each oth
vpn objectoriented language, therefore, involves the following basic sf,
define objects and their behavior. eps:
Jass definitions.
ig objects.
by sending and receiving information much th
shown in Fig. 1.6. The concept of Tes
age
at directly model or simulate thei
heir reat.
Rey
An object-oriented
process of programming in
1. Creating classes that
2. Creating objects from cl
3, Establishing communication amon:
fh one another
another as si
Objects communicate wit
itding systems th
way as people pass messages to one
passing makes it easier to talk about bul
counterparts.
Ne
letwork of objects communicating between them
Fig.
A message for an object i
ject is a reque
method (procedure) in the S a request for execution of
receiving object that gene: @ procedure, and therefc a
rates the desired r refore will invoke a
result, as shown in Fit
ig. 1.7.
Receiving
Sending ”
a ‘ :
ess2ge | Method ().) Rees
ject
Object
[EERE Message riggers a methodFundamentals of Object-Oriented Programming 7
Message passing Involves Specifying the nam
and the information to be sent. For example, oxy
Employee.salary (name) ;
Here, Employee is the object, salary i
information. Y Is the message and name is the Parameter that contains
Of the object, the ni:
ame of the method (m
ler the statement (rnessnoe)
Employee.salary (name) ;
cee) |
Message Information
Objects have a life cycle. They can be created a a ee rl
feasible as long as itis alive. ind destroyed. Communication with an object is
1.4 BENEFITS OF Oop
OOP offers several benefits to both the
to the solution of many problems associ:
1. Through inheritance, we can eliminate redundant code and extend the use of existing classes.
2. We can build programs from the standard working modules that communicate with one another,
rather than having to start writing the code from scratch. This leads to saving of development
time and higher productivity,
3. The principle of data hiding helps the programmer to build secure programs that cannot be
invaded by code in other parts of the program.
Itis possible to have multiple objects to coexist without any interference.
Itis possible to map objects in the problem domain to those objects in the program.
It is easy to partition the work in a project based on objects.
The data-centered design approach enables us to capture more details of a model in an
implementable form.
Object-oriented systems can be easily upgraded from small to large systems.
Message passing techniques for communication between objects make the interface
descriptions with external systems much simpler.
10. Software complexity can be easily managed.
Noo
ee
While it is possible to incorporate all these features in an object-oriented system, their importance
depends on the type of the project and the preference of the programmer. There are a number of
issues that need to be tackled to reap some of the benefits stated above. For instance, class
libraries must be available for reuse. The technology is stil developing and current products may
be superseded quickly. Strict controls and protocols need to be developed if reuse is not to be
compromised. ae ,
A software that is easy to use is hard to build, It is hoped that the object-oriented programming
languages like C++ and Java would help manage this problem.
1.5 APPLICATIONS OF OOP
00P is one of the programming buzzwords today. There appears to be a great deal of excitement
and interest among software engineers in using OOP. Applications of OOP are beginning to gain8 Programming with Java a
i as, The most popular application of cole ieee adr UP ty
impo en: retscer interface design such 25 indows. S OF wine
has been in the area | ; 7
systems developed using oP teen uch more complex and contain many more -objecgs |
Real-business systems eods. OOP is useful in this type of spplcations because it can simpli
complicated altribuics Fe oor application of OOP include: lity
ecomplex problem. The promising ares
|. Real-time systems
‘Simulation and modeling
Object-oriented database:
Hypertext, hypermedia an
‘Al and expert systems
Neural networks and parallel progran
Decision support and office automatic
; CIMICADICAD system Oe ait
yelieved that the richness of OOP environm J
sniy the acally of software systems but also its produ
changing the way software engineers think, analyze, desigi
S
d expertext
gramming
n systems
PNOMReENe
enable the software industry to improve
vity, Object-oriented technology is certare
n and implement systems today. nly
ey
“ SUMMARY]
. it enables us not only to organize our program code into logical
ge of encapsulation, inheritance, and polymorphism, In
Java is an object-oriented languag
ject-oriented programming which include
units called objects but also to take advanta: si
this chapter, we have introduced the basic concepts of obje
‘+ Encapsulation,
Inheritance, and
‘+ Polymorphism
We also discussed briefly the benefits and applications of object-oriented programming approach,
SUSE Pr
REVIEW QUESTIONS —————————
What do you think are the major issues facing the software industry today?
Briefly discuss the software evolution during the period from 1950 to 1995.
1
4.
1°3 What is object-oriented programming? How is it different from the procedure-oriented
wee
programming?
1.4 How are data and methods organized in an object-oriented program?
115 What are the unique advantages of an object-oriented programming paradigm?
4.6 Distinguish between the following terms:
(a) Objects and classes
(b) Data abstraction and data encapsulation
(c) Inheritance and polymorphism
(d) Dynamic binding and message passing
1.7 What kinds of things can become objects in OOP?
1.8 Describe inheritance as applied to OOP.
1.9 List a few areas of application of OOP technology.
1.10 state whether the following statements are TRUE or FALSE:
(a) In conventional, procedure-oriented programming, all data are shared by all functions.
(b) The main emphasis of procedure-oriented programming is on algorithms rather than on dleee
Fundamentals of ‘Object-Oriented Programming 9
(6) Onesof the striking features of object-oriented rogramming is the division of programs into
objects that represent real-world entities, ee ~ n fs
(@) Wrapping up of data of different types into a single unit is known as encapsulation.
(¢) One problem with OOP is that once a class ig Created, it can never be changed.
Inheritance means the ability to reuse the date values of one object by other objects.
(g) Polymorphism is extensively used in implementing inheritance.
(h) Object-oriented programs are executed much faster than conventional programs.
(i) Object-oriented systems can scale up better from small to large.
@) Object-oriented approach cannot be used to create, databases,: | Multithread | Bytecod:
| World Wide Web I Applets | Package ! Platform-neutral ytecode
ne ining | Is | HTML | Web browser | Applet tag ! Web server | HotJava |
p | javah | javadoc | jab
i Oak!
| Dynamic linking ! Native method r
Netscape Navigator | appletviewer | java | javac | javar
2.1. JAVA HISTORY
Java Is a general-purpose, object-oriented programming language developed by Sun Microsystems of
USA in 1991. Originally called Oak by James Gosling, one of the inventors of the language, Java was
designed for the development of software for consumer electronic devices like TVs, VCRs, toasters and
such olher electronic machines. The goal had a strong impact on the development team to make the
language simple, portable and highly reliable. The Java team which included Patrick Naughton discovered
that the existing languages like C and C++ had limitalions in terms of both reliability and portability,
However, they modeled their new language Java on C and C++ but removed a number of features of
C and C++ that were considered as sources of problems and thus made Java a really simple, reliable,
portable, and powerful language. Table 2.1 lists some important milestones in the development of Java
Table 2.1 Java Milestones
Year Development 23 SRE TRS 3
1980] Sun Microsystems decides to develop special sofware that could be used to manipulate consumer
«lectronic devices. A team of Sun Microsystems programmers headed by Jamos Gosling was formed to
Undertake this task.
1891 | After exploring the possibilty of using the most popular object-oriented language G++, the team announced
a new language named “Oak”.
1992 _| The team, known as Green Project team by Sun, demonstrated the a
n, pplication of their new language to
contol a list of home appliances using a hand-held device with a tiny touch-sensitive screen.
1993 | The World Wide Web (WWW) appeared on the Internet and transf
i formed the text-based Internet into a
Sraphieal-rich environment, The Green Project team came up with the idea of developing Web applets (ny
Programs) using the new language thal could run on all types of computers connected to Intemet.
(Contd)Java Evolution 11
Table 2.1 (Contd)
[Year “Development
1994 | The team developed a Web browser called
HolJava demonstrated the power of the net
users,
1995 | Oak was renamed Java", due to some legal snags. Java is just a name and is nolan acronym. Many
Popular companies including Netscape and Microsoft announced thelr support to Java
1996 | Java established itsetf not on}
oriented programming langue
“HotJava" to locate and run applet programs on Internet.
Ww language, thus making it instantly popular among the Internet
ly a a leader for Internet programming but also as a general-purpose, object-
ge. Sun releases Java Development Kit 1.0.
1997 | Sun releases Java Development Kit 1.1 (JDK 1.1),
1998 | Sun relases the Java 2 with version 1.2 of the Software Development Kit (SDK 1.2)
1999 _ Sun releases Java 2 Platform, Standard Edition (J2SE) and Enterprise Edition (2EE),
2000. | J2SE with SDK 1.3 was released,
| 2002. | J2SE with SOK 1.4 was released.
2004 | s2SE with JDK 5.0
'stead of JDK 1.5) was released. This is known as J2SE 5.0.
2006 _| Java SE 6 was released. With this release, Sun changed the name from ‘J2SE' to ‘Java SE’ and also
removed ‘.0' from the version name.
2011 _ | Java SE 7 was released.
The most striking feature of the language is that it is a platform-neutral language. Java is the first
programming language that is not tied to any particular hardware or operating system. Programs
developed in Java can be executed anywhere on any system. We can call Java as a revolutionary
technology because it has brought in a fundamental shift in how we develop and use programs.
Nothing like this has happened to the software industry before.
2.2 JAVA FEATURES
The inventors of Java wanted to design a language which could offer solutions to some of the
problems encountered in modern programming. They wanted the language to be not only reliable,
portable and distributed but also simple, compact and interactive. Sun Microsystems officially des-
cribes Java with the following attributes:
[Yava2 Features. Additional Features of Enhancements in. Enhancements In.
: PASE 5.0 Java SEG JavaSE7
+ Compiled and interpreted | - Ease of Development * Scripting Language + Language
+ Platform-independent | + Scalability and Performance | Support Enhancements
and Portable + Monitoring and + XML Processing and | + NIO2.0
+ Object-Oriented Manageabilly Web Services + Parallel Programming
“+ Robust and Secure + Desktop Client + JDBC 4.0 Support + Dynamic Language
+ Distibuted + Core XML Support + Annotation-based ‘Support
+ Familiar, Simpte and + Supplementary character Programming
‘Small support + Dynamic Compilation
+ Mutithreaded and + JDBCRowSet
Interactive
+ High Performance
+ Dynamic and Extensible
Although the above appears to be a list of buzzwords, they aptly describe the full potential of the
language. These features have made Java the first application language of the World Wide Web. Java
will also become the premier language for general-purpose standalone applications.— Ul
42. Programming with Java
ed or interpreted. Java combines both these approaches
led and Interpreted
translates source code into what is knoyin
Compi , vl
language is either comp pre
Usually a computer to atage system. First, Java compl tare es oe wt Kom
thus making Java at Bytecodes are not machine inst hive ane ,
as bytecode instruction ay nine code that can be directly execiien Te in ha
ein progr near tws say that Java is both @ compiled an $
the Java program.
d Portable , A
Platform-Independent an ava over other languages is its portabiliy. Java programs
contribution of Java ‘anywhere and anytime. Changes ang
to another, i
oo el ces will not force any changes in Java
The most significant
stem TesOul
can be easily moved from one 7 '
Upgrades in operating sysems, processors and SYSteM ee eee ane
vn ue ete worl download a Java applet f
programs. This is the reason wh "8 oe oon ene
i ifferent kinds of systems W : ‘
vomot i ent ou cal system via Internet and execute it locally. This makes the Internet an
note corr usor’s basic aystem providing practically unlimited number of accessible applets ang
extensi
Pacis er it mpiler generates bytecode instructions that
ity in two ways. First, Java compi rate t
iis o Cee eon oy machine. Secondly, the size of the primitive data types are machine.
independent.
Object-Oriented ;
Java is a true object-oriented language. Almost everything in Java Is an object. All program code
and data reside within objects and classes. Java comes with an extensive set of classes, arranged
in packages, that we can use in our programs by inheritance. The object model in Java is simple and
easy to extend.
Robust and Secure 7
Java is a robust language. It provides many safeguards to ensure reliable code. It has strict compile
time and run time checking for data types. It is designed as a garbage-collected language relieving
the programmers virtually all memory management problems, Java also incorporates the concept of
exception handling which captures serious errors and eliminates any risk of crashing the system.
Security becomes an important issue for a language that is used for Programming on Intemet.
Threat of viruses and abuse of resources are everywhere. Java systems not only verify all memory
access but also ensure that no viruses are communicated with an applet. The absence of pointers in
Java ensures that programs cannot gain access to memory locations without proper authorization.
Distributed
Java is designed as a distributed language for creating applications on networks. It has the ability to
share bath data and programs. Java applications can open and access remote objects on Intemet
2S Easily as they can do in a local system. This enables multiple program i
locations to collaborate and work together on a single project, ess. eS ae
Simple, Small and Familiardava Evolution 13
Familiarity is a
eager eral stking a of Java. To make the language look familiar to the existing
programe; was modeled an and C++ languages. Java uses many constructs of C and C++
looks like a C+4" code. In fact, Java is a simplified version of C++.
Multithreaded and Interactive
ithread ,
esreme Hed means consins multiple tasks simultaneously. Java supports multithreaded
programs, This meer thal we Need not wait for the application to finish one task before beginning
time download an applet ‘rom a distant Bn audio clip, whila;seroling a page. and at the seme,
rn ‘ - mn
Wi otnance of graphical aplicatons, computer. This feature greally improves the interactive
The Java runtime comes with tools that , a
‘smoothly running interactive systems. support multiprocess synchronization and construct
High Performance
Java performance is impressive for an interpreted lan i it i
° \uage, mainly due to the use of intermediate
OSE Aon ovemoati a speed is comparable to the native C/C++. Java architecture is also
fesigne heads during runtime. Further, the incorporat ireadi
overall execution speed of Java programs. ree cn ot cee ea
Dynamic and Extensible
Java Is a dynamic language. Java is capable of dynamically linking in new class libraries, methods,
and objects. Java can also determine the type of class through a query, making it possible to either
dynamically link or abort the program, depending on the response.
Java programs support functions written in other languages such as C and C++. These functions
are known as native methods. This facility enables the programmers to use the efficient functions
available in these languages. Native methods are linked dynamically at runtime.
Ease of Development
Java 2 Standard Edition (J2SE) §.0 supports features, such as Generics, Enhanced for Loop,
Autoboxing or unboxing, Typesafe Enums, Varargs, Static import and Annotation. These features
reduce the work of the programmer by shifting the responsibilty of creating the reusable code to
the compiler. The resulting source code is free from bugs because the errors made by the compiler
are less when compared to those made by programmers. Thus, each of the linguistic features is
designed to develop Java programs in an easier way.
Scalability and Performance
JOSE 5.0 assures a significant increase in scalal
time and reducing the amount of memory used in
introduction of the class, data sharing in the Hotsp:
startup time by loading the core classes from the jar
is reduced by sharing data in the shared archive among mut
versions, the data was replicated in each JVM instance.
bility and performance by improving the startup
Java 2 runtime environment. For example, the
jot Java Virtual Machine (JVM) improves the
files into a shared archive. Memory utilization
tiple JVM processes. In the earlier
Monitoring and Manageability
Java supports a number of APIs, such 2s JVM Monitoring and Manageme!
Platform Extension, Logging, Monitoring and Management Interface,
Extension (JMX) to monitor and manage Java applications. For example,
Monitoring and Management API to track the information at the application level and
nt API, Sun Management
and Java Management
Java provides JVM
JVM level when14 Programming with Java
ips, jstat, and jet
ides tools, such as jconsole, jps, jst Ista tp
rovides t ple, GUI-based {ool called jconsole jg vette
deploying a large application. Java p .
lo
7 7
use of monitoring and management facillies. For exar
monitor the JVM.
Desktop Client ‘ i chien ‘
uirements and challenges of the Jay,
J2SE 5.0 provides enhanced features to meet the req 8 desktop
users. It provides an improved Swing look and feel called Ocean. This feature is main)
i K al lled is nl
ides an impt ing loo ;
Gprabriny graphics applications that require OpenGL hardware acceleration Y USEd for
Miscellaneous Features ; :
In addition to the above features, J2SE 5.0 supports the following features:
IL feature to the Java platform. Java
jort J2SE 5.0 adds a powerful XM containg
ore ct Heacee for interface, to instantiate Simple API for XML (SAX) and Document Object
Model (DOM) parsers to parse an XML document, transform the content of an XML document, and
validate an XML document against the schema,
32-bit supplementary character support as
lementary Character Support Java adds the n vata
re ‘Unicode 20 support. The supplementary characters are encoded with UTF-16 values to generate
a different character called, surrogate codepoint.
Se Java supports JDBC RowSet to send data in a tabular format between the Temote
componente ak a distibuted enterprise application. JDBC RowSet contains CachedRowset and
WebRowSet objects. The CachedRowSet object is a JavaBean component which sets tke a
Container. This object contains a number of rows of data, which are retrieved from the databsse The
data stored in the CachedRowSet can be directly accessed without connecting to the database or any
other data source. The rows of data that are retrieved from the database can be synchronized later.
The WebRowSet object can operate without being connected to the database or data source. The
WebRowSet object uses XML format to read and write the rowset.
Enhancements in Java SE 6
‘Some of the key enhancements in Java SE 6 are:
* Scripting Language Support: Java SE 6 integrates various scripting languages such as Java
Saipl and PHP Script into the Java platform. It allows scripts to be embeded in Java programs,
and compiled and executed with the help of appropriate scripting engine.
XML Processing and Web Services: It allows development of Web services and clients that
communicate using XML.
JDBC 4.0 Support: It supports JDBC 4.0 for developing database-centric applications, As a
[fsult Programmers can leverage the various features of JDBC 4.0 Such as automatic loading of
JDBC driver class, connection management features, ate.
Annotation-based Programming: It allows programmers to define annotations (meta-tags)
{or various program elements so that the same can be used by the compiler or other tools to
generate ready code whenever necessary,
Dynamic Compilation: The Java Compiler AP allows dynamic compilation of Java source code
form a running Java application,
Enhancements in Java SE7
Some of the key enhancements in Java SE 7 are:vava evowution 15
+ Language Enhancements: Java SE 7 adds several language features aimed at helping the
Programmers implement difficult functionality with ease. The new language features include
strings in switch statement, multiple exception handling, diamond syntax, etc.
+ NIO 2.0: The new file system API (NIO 2.0) in Java SE 7 makes it a lot easier to work with file
systems. It contains several enhancements to the standard file operations such as open, read,
write, etc. In addition, it also allows the programmers to create custom file systems.
* Parallel Programming: Java SE 7 facilitates parallel programming through the use of Fork/Join
framework. While the conventional multithreaded programming allowed programmers to use a
single processor for multitasking; the Fork/Join framework enables programmers to make the
best use of the available multiple processors through parallel programming.
« Dynamic Language Support: Java SE 7 supports dynamically typed languages in the JVM.
The invokedynamic instruction is used to define customized linkage mechanisms for these
languages.
2.3 HOW JAVA DIFFERS FROM C AND C++
Although Java was modeled after C and C++ languages, it differs from C and C++ in many ways.
Java does not incorporate a number of features available in C and C++. For the benefit of C and C++
programmers, we point out here a few major differences between C/C++ and Java languages.
Java and C
Java is a lot like C but the major difference between Java and C is that Java is an object-oriented
language and has mechanism to define classes and objects. In an effort to build a simple and safe
language, the Java team did not include some of the C features in Java.
1. Java does not include the C unique statement keywords sizeof, and typedef.
2. Java does not contain the data types struct and union.
3. Java does not define the type modifiers keywords auto, extern, register, signed, and
unsigned.
4, Java does not support an explicit pointer type.
5, Java does not have a preprocessor and therefore we cannot use # define, # include, and #
ifdef statements.
6. Java requires that the functions with no arguments must be declared with empty parenthesis
and not with the void keyword as done in C.
7. Java adds new operators such as instanceof and >>>.
8. Java adds labeled break and continue statements.
9. Java adds many features required for object-oriented programming.
Java and C++
Java is a true object-oriented language while C++ Is basically C with object-oriented extension. That
is what exactly the increment operator ++ indicates. C++ has maintained backward compatibility with
C. It is therefore possible to write an old style C program and run it successfully under C++. Java
appears to be similar to C++ when we consider only the “extension” part of C++, However, some
object-oriented features of C++ make the C++ code extremely difficult to follow and maintain.
Listed below are some major C++ features that were intentionally omitted from Java or significantly
modified.
1. Java does not support operator overloading.
2. Java does not have template classes as in C++.
3, Java does not support multiple inheritance of classes. This is accomplished using a new feature
called “interface”.——i—‘“aié—S
46 Programming with Jave
ot support global variable Every
or aitiod is deciared within class
rt of that class:
t use pointers. 2
the destructor functio'
4. Java does nm
variable and
and forms p2!
5, Java does not
8, Java has replaced
afinalize()function.
7. There are no header files in Java.
adds some new features. While Crt
re, Java is nelther a superset Net
Or Ger Java may be considered 2
Ficrt and a second cousin of © 85
2.1. Amore detailed discussion oF
ween C++ and Java is available
in with
Java also
is a superset
a subset of C
fa first cousin o}
itustrated in Fig,
the differences bel
in Appendix A.
2.4 JAVAAND INTERNET
with the Int
a Web browser to ru
fais strongly associated
was HotJava,
and run them local
bled browser t
local computer (see Fig.
ge system of
t up their
dav
written in Java
create applet programs
can also use a Java-enal
Internet and run it on his
true extension of the storat
Internet users can also se
remote users of Internet.
has made Java a unique programming language
known as Internet language.
Remote
‘Computer
Local
Computer
ternet because of the
n applets on
lly using @ “Java-enal
(0 download an app!
2.2), In fact,
the local computer.
Web sites containin:
The ability of Java applets to hit
for the Intemet. In fact, due to this, Java is popular
y
]
[EEIERE overtopping of C, C++, and Java
fact that the first applicati
Internet. Internet users Sonne eo
bled browser” such as Hotlava, Trey
let located on a computer anywhere in
“fale applets have made the Inmet’
.g Java applets that could be used
fh a ride on the Information Superhghny
De
[EEE] owntoading of applets via internetJava Evolution 47
2.5 JAVA AND WORLD WIDE WEB
World Wide Web (WWW) Is an open-ended
information retrieval system designed to be used ag
in the Internet's distributed environment. This
system contains what are known as Web pages
that provide both information and controls. Unlike
a menu-driven system where we are guided
through a particular direction using a decision tree
structure, the Web system is open-ended and we
can navigate to a new document in any direction
as shown in Fig, 2.3. This is made possible with
the help of a language called Hypertext Markup
Language (HTML). Web pages contain HTML
tags that enable us to find, retrieve, manipulate
and display documents worldwide.
Java was meant to be used in distributed environments such as Internet. Since, both the Web and
Java share the same philosophy, Java could be easily incorporated into the Web system. Before Java,
the World Wide Web was limited to the display of stil images and texts. However, the incorporation
of Java into Web pages has made it capable of supporting animation, graphics, games, and a wide
range of special effects. With the support of Java, thé Web has become more interactive and dynamic.
On the other hand, with the support of Web, we can run a Java program on someone else's computer
across the Internet.
Java communicates with a Web page through a special tag called