object oriented rogramming with question and answer full
DESCRIPTION
Basics overview of programming paradigms Features of OOPS Classes Encapsulation Polymorphism InheritanceTRANSCRIPT
UNIT STRUCTURE
Basics overview of programming paradigms Features of OOPS Classes Encapsulation Polymorphism Inheritance
LEARNING OBJECTIVES
After going through this unit you should be able to
find the importance of OO approach
define the basic concepts of OO approach
differentiate between object and procedure-oriented approaches
know about various OO languages
describe the applications of OOP and
Understand the benefits of OO approach
1 Object oriented programming
Javas origins go back to 1991 when Sun Microsystems began looking for ways to create
platform-independent code to support consumer electronic products After some initial
efforts with C++ the Sun project team abandoned it and created its own language initially
called Oak later renamed Java Oak first was used to create software for a personal hand-
held remote control device but when the project team lost a bid to develop a television set-
top box for Time-Warner attention switched to the Web The Sun project team then built a
Web browser originally called WebRunner and then renamed HotJava in the Java
programming language The rest as they say is history Sun formally announced Java and
HotJava at the SunWorld 95 conference in San Francisco on May 23 1995
UNIT 1 OBJECT ORIENTED ROGRAMMING
Object-oriented programming (OOP) is a programming language model organized around
objects rather than actions and data rather than logic Historically a program has been viewed
as a logical procedure that takes input data processes it and produces output data The
programming challenge was seen as how to write the logic not how to define the data Object-
oriented programming takes the view that what we really care about are the objects we want to
manipulate rather than the logic required to manipulate them Examples of objects range from
human beings (described by name address and so forth) to buildings and floors (whose
properties can be described and managed) down to the little widgets on a computer desktop (such
as buttons and scroll bars)
Real world objects
The first step in OOP is to identify all the objects the programmer wants to manipulate and how
they relate to each other an exercise often known as data modeling Once an object has been
identified it is generalized as a class of objects (think of Platos concept of the ideal chair that
stands for all chairs) which defines the kind of data it contains and any logic sequences that can
manipulate it Each distinct logic sequence is known as a method Objects communicate with
well-defined interfaces called messages
The concepts and rules used in object-oriented programming provide these important
benefits
a) The concept of a data class makes it possible to define subclasses of data objects that
share some or all of the main class characteristics Called inheritance this property of
OOP forces a more thorough data analysis reduces development time and ensures more
accurate coding
b) Since a class defines only the data it needs to be concerned with when an instance of that
class (an object) is run the code will not be able to accidentally access other program
data This characteristic of data hiding provides greater system security and avoids
unintended data corruption
c) The definition of a class is reuseable not only by the program for which it is initially
created but also by other object-oriented programs (and for this reason can be more
easily distributed for use in networks)
d) The concept of data classes allows a programmer to create any new data type that is not
already defined in the language itself
EVOLUTION OF OO METHODOLOGY
Simula was the first object-oriented programming language Java Python C++ Visual
Basic NET and Ruby are the most popular OOP languages today The Java programming
language is designed especially for use in distributed applications on corporate networks and the
Internet Ruby is used in many Web applications Curl Smalltalk Delphi and Eiffel are also
examples of object-oriented programming languages
Java is an object-oriented programming language based on C++ that allows small programs -- or
applets -- to be embedded within an HTML document When the user clicks on the appropriate
part of the HTML page to retrieve it from a Web server the applet is downloaded into the client
workstation environment where it begins executing [Editors note Since this text was written
the definition of Java has expanded beyond Web-based applets Sun expects the language to be
used for all sorts of applications and promises a Java operating system Java microprocessors
and more -- and now refers to Java as a platform
The relationship among Java programs (or applets) the Java-enabled browser and the Web is
illustrated in Figure Users access a Web page and pull it down to their client In this case
though the Web page contains an additional HTML tag called APP which refers to a Java
applet and that applet can be located anywhere on the Web If the users Web browser is Java-
enabled (for example Suns HotJava browser or Netscapes Navigator 20) then the applet is
pulled down into the users client computer and executed within the browser environment
Java is often described as a cross-platform programming language its also common to refer to Java
programs as architecture-neutral byte codes It has to be this way of course because the Web server
that delivers the Java applet to the Web client doesnt know what kind of hardwaresoftware environment
its running on And the developer who creates the Java applet doesnt want to worry about whether it will
work correctly on OS2 Windows Unix and MacOS
1) The Java compiler javac which translates human-readable Java source code to architecture-neutral bytecodes
2) The Java interpreter which executes Java programs on the users PC or workstation
3) The C header and source file generator javah and java_g These are used to generate header files for C as well as source files for making methods (roughly equivalent to procedures or subroutines in other languages) within Java
4) The Java disassembler javap which prints out information about a class file (a file containing a Java applet)
5) The document generator javadoc which is capable of generating an HTML file from a Java source-code file
6) The profiling tool javaprof which formats the performance data created if the programmer uses the -prof option in the Java interpreter to obtain statistics on run time and performance
Security and robust behavior
Security and robustness are obviously important in the distributed environment represented by
the Internet if you download a Java applet from a Web server for example you really dont
want it to run amok on your computer and delete all the files on your hard disk This is not as far-
fetched as it might sound because the incorporation of Java applets into Web pages means that
you may be invoking computer programs written by people anywhere in the world located
anywhere on the Web Indeed once you begin using a Java-enabled browser youre
automatically at risk since you dont know at the moment you decide to retrieve a Web page (say
by clicking on a hyperlink within an existing page being displayed on your computer) whether it
will contain embedded Java applets
Sun has addressed this concern by imposing severe constraints on the Java programming
language as well as extensive run-time checking in the interpreter located inside the Java-
enabled browser The Java language for example forbids the use of address pointers and pointer
arithmetic found in C and C++ this eliminates a large class of innocent errors that might
otherwise plague the user of Java applets In addition the following steps have been taken to
increase the level of security and robust behavior
1) The Java run-time interpreter verifies that bytecodes (the compiled architecture-neutral
form of Java applet that gets downloaded from the Web server into the users machine)
dont violate any language constructs -- which could happen if an altered Java compiler
was used by a hacker The verification logic checks to make sure that the Java applet
doesnt access restricted memory forge memory pointers or access objects in a manner
inconsistent with its definition It also ensures that method (subroutine) calls include the
correct number of arguments of the right type and that there are no stack overflows
2) During loading of the Java applet the run-time interpreter verifies class names (a class
is an entire Java applet) and access restrictions
3) If a Java applet attempts to access a file for which it has no permission a dialog box will
pop up to allow the user to continue or stop the execution of the applet
4) Future releases of Java are planned to have facilities for using public key encryption to
verify the source and origin of the Java source code and its integrity after traveling
through the network to reach the users machine
5) At run time information about the origin of the Java applet can be used to decide what
the applet is allowed to do For example a security mechanism can be used to determine
whether the compiled Java byte codes originated from within an organizations security
firewall or not This makes it possible to set a security policy that restricts the use and
execution of Java code that an organization doesnt know or trust
This last point is crucial for there are likely to be a number of attempts -- both innocent and
malicious -- to circumvent the security mechanisms that Sun has built into the language In its
white paper on the Java language Sun expresses the following optimistic statement about Java
security Java is designed to operate in distributed environments which means that security is of
paramount importance With security features designed into the language and run-time system
Java lets you construct applications that cant be invaded from outside In the networked
environment applications written in Java are secure from intrusion by unauthorized code
attempting to get behind the scenes and create viruses or invade file systems For the security-
conscious organizations though the firewall protection mentioned above will be crucial -- at
least in the short term
Basics overview of programming paradigms
The term paradigm describes a set of techniques methods theories and standards that together represent
a way of thinking for problem solving According to [Wegner 1988] paradigms are ldquopatterns of
thought for problem solvingrdquo Language paradigms were associated with classes of languages First the
paradigms are defined Thereafter programming languages according to the different paradigms are
classified The language paradigms are divided into two parts imperative and declarative paradigms as
shown in the Figure 1 Imperative languages can be further classified into procedural and object
oriented approach Declarative languages can be classified into functional languages and logical
languages In Figure1 the examples of languages in each category are also given
Language Paradigms
Computer programmers have evolved from the early days of the bit processing first generation
languages into sophisticated logical designers of complex software applications A programming
paradigm is the logical approach used in software engineering that describes how a programming
language is implemented Programming paradigms are unique to each language within the
computer programming domain and many programming languages utilize multiple paradigms
The term paradigm is best described as a pattern or model Therefore a programming
paradigm can be defined as a pattern or model used within a software programming language to
create software applications
Programming languages are extremely logical and follow standard rules of mathematics Each
language has a unique method for applying these rules especially around the areas of functions
variables methods and objects There are many programming paradigms examples include
object oriented procedural and structured programming Each paradigm has unique
requirements on the usage and abstractions of processes within the programming language
Features of OOPS
Object oriented methods are favored because many experts agree that Object Oriented techniques
are more disciplined than conventional structured techniques (Martin and Odell 1992)
The main components of Object Oriented technology are lsquoobjects and classesrsquo lsquodata
abstraction and encapsulationrsquo lsquoinheritancersquo and lsquopolymorphismrsquo It is very important for
you to understand these concepts Further in this unit you can find the details of these concepts
a) Object oriented programming (OOP) is a programming model where Programs are organized around object and data rather than action and logic OOP allow decomposition of a problem into a number of entities called Object and then builds data and function around these objects
b) The Program is divided into number of small units called Object The data and function are build around these objects
c) The data of the objects can be accessed only by the functions associated with that objectd) The functions of one object can access the functions of other object
OOP has the following important features
ClassA class is the core of any modern Object Oriented Programming languageIn OOP languages it is must to create a class for representing data Class is a blueprint of an object that contains variables for storing data and functions to performing operations on these data Class will not occupy any memory space and hence it is only logical representation of data
To create a class you simply use the keyword class followed by the class nameclass Employee
Object
Objects are the basic run-time entities in an object oriented systemThey may represent a
persona place or any item that the program has to handle
Object is a Software bundle of related variable and methods
ldquoObject is an instance of a classrdquo
Class will not occupy any memory space Hence to work with the data represented by the class you must create a variable for the class which is called as an object When an object is created by using the keyword new then memory will be allocated for the class in heap memory area which is called as an instance and its starting address will be stored in the object in stack memory area
When an object is created without the keyword new then memory will not be allocated in heap Ie instance will not be created and object in the stack contains the value nullWhen an object contains null then it is not possible to access the members of the class using that object
class Employee
Syntax to create an object of class Employee-
Employee objEmp = new Employee()
Similarly the following can be treated as objects in different programming problems
Employees in a payroll system Customers and accounts in a banking system Salesman products customers in a sales tracking system Data structures like linked lists stacks etc Hardware devices like magnetic tape drive keyboard printer etc GUI elements like windows menus events etc in any window-based application
All the programming languages supporting object oriented Programming will be supporting these three main concepts
1 Encapsulation2 Inheritance3 Polymorphism
AbstractionAbstraction is To represent the essential feature without representing the back ground details
Abstraction lets you focus on what the object does instead of how it does it
Abstraction provides you a generalized view of your classes or object by providing relevant information
Abstraction is the process of hiding the working style of an object and showing the information of an object in understandable manner
Real world Example of Abstraction - Suppose you have an object Mobile Phone
Suppose you have 3 mobile phones as following-
Nokia 1400 (Features- Calling SMS)Nokia 2700 (Features- Calling SMS FM Radio MP3 Camera)Black Berry (Features-Calling SMS FM Radio MP3 Camera Video Recording Reading E-mails)
Abstract information (Necessary and Common Information) for the object Mobile Phone is make a call to any number and can send SMS
so that for mobile phone object you will have abstract class like following-
abstract class MobilePhone public void Calling() public void SendSMS()
public class Nokia1400 MobilePhone
public class Nokia2700 MobilePhone public void FMRadio() public void MP3() public void Camera()
public class BlackBerry MobilePhone public void FMRadio() public void MP3() public void Camera() public void Recording() public void ReadAndSendEmails()
Abstraction means putting all the variables and methods in a class which are necessaryFor example - Abstract class and abstract methodAbstraction is the common thingexample If somebody in your collage tell you to fill application form you will fill your details like name address data of birth which semester percentage you have got etcIf some doctor gives you an application to fill the details you will fill the details like name address date of birth blood group height and weight
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
Object-oriented programming (OOP) is a programming language model organized around
objects rather than actions and data rather than logic Historically a program has been viewed
as a logical procedure that takes input data processes it and produces output data The
programming challenge was seen as how to write the logic not how to define the data Object-
oriented programming takes the view that what we really care about are the objects we want to
manipulate rather than the logic required to manipulate them Examples of objects range from
human beings (described by name address and so forth) to buildings and floors (whose
properties can be described and managed) down to the little widgets on a computer desktop (such
as buttons and scroll bars)
Real world objects
The first step in OOP is to identify all the objects the programmer wants to manipulate and how
they relate to each other an exercise often known as data modeling Once an object has been
identified it is generalized as a class of objects (think of Platos concept of the ideal chair that
stands for all chairs) which defines the kind of data it contains and any logic sequences that can
manipulate it Each distinct logic sequence is known as a method Objects communicate with
well-defined interfaces called messages
The concepts and rules used in object-oriented programming provide these important
benefits
a) The concept of a data class makes it possible to define subclasses of data objects that
share some or all of the main class characteristics Called inheritance this property of
OOP forces a more thorough data analysis reduces development time and ensures more
accurate coding
b) Since a class defines only the data it needs to be concerned with when an instance of that
class (an object) is run the code will not be able to accidentally access other program
data This characteristic of data hiding provides greater system security and avoids
unintended data corruption
c) The definition of a class is reuseable not only by the program for which it is initially
created but also by other object-oriented programs (and for this reason can be more
easily distributed for use in networks)
d) The concept of data classes allows a programmer to create any new data type that is not
already defined in the language itself
EVOLUTION OF OO METHODOLOGY
Simula was the first object-oriented programming language Java Python C++ Visual
Basic NET and Ruby are the most popular OOP languages today The Java programming
language is designed especially for use in distributed applications on corporate networks and the
Internet Ruby is used in many Web applications Curl Smalltalk Delphi and Eiffel are also
examples of object-oriented programming languages
Java is an object-oriented programming language based on C++ that allows small programs -- or
applets -- to be embedded within an HTML document When the user clicks on the appropriate
part of the HTML page to retrieve it from a Web server the applet is downloaded into the client
workstation environment where it begins executing [Editors note Since this text was written
the definition of Java has expanded beyond Web-based applets Sun expects the language to be
used for all sorts of applications and promises a Java operating system Java microprocessors
and more -- and now refers to Java as a platform
The relationship among Java programs (or applets) the Java-enabled browser and the Web is
illustrated in Figure Users access a Web page and pull it down to their client In this case
though the Web page contains an additional HTML tag called APP which refers to a Java
applet and that applet can be located anywhere on the Web If the users Web browser is Java-
enabled (for example Suns HotJava browser or Netscapes Navigator 20) then the applet is
pulled down into the users client computer and executed within the browser environment
Java is often described as a cross-platform programming language its also common to refer to Java
programs as architecture-neutral byte codes It has to be this way of course because the Web server
that delivers the Java applet to the Web client doesnt know what kind of hardwaresoftware environment
its running on And the developer who creates the Java applet doesnt want to worry about whether it will
work correctly on OS2 Windows Unix and MacOS
1) The Java compiler javac which translates human-readable Java source code to architecture-neutral bytecodes
2) The Java interpreter which executes Java programs on the users PC or workstation
3) The C header and source file generator javah and java_g These are used to generate header files for C as well as source files for making methods (roughly equivalent to procedures or subroutines in other languages) within Java
4) The Java disassembler javap which prints out information about a class file (a file containing a Java applet)
5) The document generator javadoc which is capable of generating an HTML file from a Java source-code file
6) The profiling tool javaprof which formats the performance data created if the programmer uses the -prof option in the Java interpreter to obtain statistics on run time and performance
Security and robust behavior
Security and robustness are obviously important in the distributed environment represented by
the Internet if you download a Java applet from a Web server for example you really dont
want it to run amok on your computer and delete all the files on your hard disk This is not as far-
fetched as it might sound because the incorporation of Java applets into Web pages means that
you may be invoking computer programs written by people anywhere in the world located
anywhere on the Web Indeed once you begin using a Java-enabled browser youre
automatically at risk since you dont know at the moment you decide to retrieve a Web page (say
by clicking on a hyperlink within an existing page being displayed on your computer) whether it
will contain embedded Java applets
Sun has addressed this concern by imposing severe constraints on the Java programming
language as well as extensive run-time checking in the interpreter located inside the Java-
enabled browser The Java language for example forbids the use of address pointers and pointer
arithmetic found in C and C++ this eliminates a large class of innocent errors that might
otherwise plague the user of Java applets In addition the following steps have been taken to
increase the level of security and robust behavior
1) The Java run-time interpreter verifies that bytecodes (the compiled architecture-neutral
form of Java applet that gets downloaded from the Web server into the users machine)
dont violate any language constructs -- which could happen if an altered Java compiler
was used by a hacker The verification logic checks to make sure that the Java applet
doesnt access restricted memory forge memory pointers or access objects in a manner
inconsistent with its definition It also ensures that method (subroutine) calls include the
correct number of arguments of the right type and that there are no stack overflows
2) During loading of the Java applet the run-time interpreter verifies class names (a class
is an entire Java applet) and access restrictions
3) If a Java applet attempts to access a file for which it has no permission a dialog box will
pop up to allow the user to continue or stop the execution of the applet
4) Future releases of Java are planned to have facilities for using public key encryption to
verify the source and origin of the Java source code and its integrity after traveling
through the network to reach the users machine
5) At run time information about the origin of the Java applet can be used to decide what
the applet is allowed to do For example a security mechanism can be used to determine
whether the compiled Java byte codes originated from within an organizations security
firewall or not This makes it possible to set a security policy that restricts the use and
execution of Java code that an organization doesnt know or trust
This last point is crucial for there are likely to be a number of attempts -- both innocent and
malicious -- to circumvent the security mechanisms that Sun has built into the language In its
white paper on the Java language Sun expresses the following optimistic statement about Java
security Java is designed to operate in distributed environments which means that security is of
paramount importance With security features designed into the language and run-time system
Java lets you construct applications that cant be invaded from outside In the networked
environment applications written in Java are secure from intrusion by unauthorized code
attempting to get behind the scenes and create viruses or invade file systems For the security-
conscious organizations though the firewall protection mentioned above will be crucial -- at
least in the short term
Basics overview of programming paradigms
The term paradigm describes a set of techniques methods theories and standards that together represent
a way of thinking for problem solving According to [Wegner 1988] paradigms are ldquopatterns of
thought for problem solvingrdquo Language paradigms were associated with classes of languages First the
paradigms are defined Thereafter programming languages according to the different paradigms are
classified The language paradigms are divided into two parts imperative and declarative paradigms as
shown in the Figure 1 Imperative languages can be further classified into procedural and object
oriented approach Declarative languages can be classified into functional languages and logical
languages In Figure1 the examples of languages in each category are also given
Language Paradigms
Computer programmers have evolved from the early days of the bit processing first generation
languages into sophisticated logical designers of complex software applications A programming
paradigm is the logical approach used in software engineering that describes how a programming
language is implemented Programming paradigms are unique to each language within the
computer programming domain and many programming languages utilize multiple paradigms
The term paradigm is best described as a pattern or model Therefore a programming
paradigm can be defined as a pattern or model used within a software programming language to
create software applications
Programming languages are extremely logical and follow standard rules of mathematics Each
language has a unique method for applying these rules especially around the areas of functions
variables methods and objects There are many programming paradigms examples include
object oriented procedural and structured programming Each paradigm has unique
requirements on the usage and abstractions of processes within the programming language
Features of OOPS
Object oriented methods are favored because many experts agree that Object Oriented techniques
are more disciplined than conventional structured techniques (Martin and Odell 1992)
The main components of Object Oriented technology are lsquoobjects and classesrsquo lsquodata
abstraction and encapsulationrsquo lsquoinheritancersquo and lsquopolymorphismrsquo It is very important for
you to understand these concepts Further in this unit you can find the details of these concepts
a) Object oriented programming (OOP) is a programming model where Programs are organized around object and data rather than action and logic OOP allow decomposition of a problem into a number of entities called Object and then builds data and function around these objects
b) The Program is divided into number of small units called Object The data and function are build around these objects
c) The data of the objects can be accessed only by the functions associated with that objectd) The functions of one object can access the functions of other object
OOP has the following important features
ClassA class is the core of any modern Object Oriented Programming languageIn OOP languages it is must to create a class for representing data Class is a blueprint of an object that contains variables for storing data and functions to performing operations on these data Class will not occupy any memory space and hence it is only logical representation of data
To create a class you simply use the keyword class followed by the class nameclass Employee
Object
Objects are the basic run-time entities in an object oriented systemThey may represent a
persona place or any item that the program has to handle
Object is a Software bundle of related variable and methods
ldquoObject is an instance of a classrdquo
Class will not occupy any memory space Hence to work with the data represented by the class you must create a variable for the class which is called as an object When an object is created by using the keyword new then memory will be allocated for the class in heap memory area which is called as an instance and its starting address will be stored in the object in stack memory area
When an object is created without the keyword new then memory will not be allocated in heap Ie instance will not be created and object in the stack contains the value nullWhen an object contains null then it is not possible to access the members of the class using that object
class Employee
Syntax to create an object of class Employee-
Employee objEmp = new Employee()
Similarly the following can be treated as objects in different programming problems
Employees in a payroll system Customers and accounts in a banking system Salesman products customers in a sales tracking system Data structures like linked lists stacks etc Hardware devices like magnetic tape drive keyboard printer etc GUI elements like windows menus events etc in any window-based application
All the programming languages supporting object oriented Programming will be supporting these three main concepts
1 Encapsulation2 Inheritance3 Polymorphism
AbstractionAbstraction is To represent the essential feature without representing the back ground details
Abstraction lets you focus on what the object does instead of how it does it
Abstraction provides you a generalized view of your classes or object by providing relevant information
Abstraction is the process of hiding the working style of an object and showing the information of an object in understandable manner
Real world Example of Abstraction - Suppose you have an object Mobile Phone
Suppose you have 3 mobile phones as following-
Nokia 1400 (Features- Calling SMS)Nokia 2700 (Features- Calling SMS FM Radio MP3 Camera)Black Berry (Features-Calling SMS FM Radio MP3 Camera Video Recording Reading E-mails)
Abstract information (Necessary and Common Information) for the object Mobile Phone is make a call to any number and can send SMS
so that for mobile phone object you will have abstract class like following-
abstract class MobilePhone public void Calling() public void SendSMS()
public class Nokia1400 MobilePhone
public class Nokia2700 MobilePhone public void FMRadio() public void MP3() public void Camera()
public class BlackBerry MobilePhone public void FMRadio() public void MP3() public void Camera() public void Recording() public void ReadAndSendEmails()
Abstraction means putting all the variables and methods in a class which are necessaryFor example - Abstract class and abstract methodAbstraction is the common thingexample If somebody in your collage tell you to fill application form you will fill your details like name address data of birth which semester percentage you have got etcIf some doctor gives you an application to fill the details you will fill the details like name address date of birth blood group height and weight
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
The concepts and rules used in object-oriented programming provide these important
benefits
a) The concept of a data class makes it possible to define subclasses of data objects that
share some or all of the main class characteristics Called inheritance this property of
OOP forces a more thorough data analysis reduces development time and ensures more
accurate coding
b) Since a class defines only the data it needs to be concerned with when an instance of that
class (an object) is run the code will not be able to accidentally access other program
data This characteristic of data hiding provides greater system security and avoids
unintended data corruption
c) The definition of a class is reuseable not only by the program for which it is initially
created but also by other object-oriented programs (and for this reason can be more
easily distributed for use in networks)
d) The concept of data classes allows a programmer to create any new data type that is not
already defined in the language itself
EVOLUTION OF OO METHODOLOGY
Simula was the first object-oriented programming language Java Python C++ Visual
Basic NET and Ruby are the most popular OOP languages today The Java programming
language is designed especially for use in distributed applications on corporate networks and the
Internet Ruby is used in many Web applications Curl Smalltalk Delphi and Eiffel are also
examples of object-oriented programming languages
Java is an object-oriented programming language based on C++ that allows small programs -- or
applets -- to be embedded within an HTML document When the user clicks on the appropriate
part of the HTML page to retrieve it from a Web server the applet is downloaded into the client
workstation environment where it begins executing [Editors note Since this text was written
the definition of Java has expanded beyond Web-based applets Sun expects the language to be
used for all sorts of applications and promises a Java operating system Java microprocessors
and more -- and now refers to Java as a platform
The relationship among Java programs (or applets) the Java-enabled browser and the Web is
illustrated in Figure Users access a Web page and pull it down to their client In this case
though the Web page contains an additional HTML tag called APP which refers to a Java
applet and that applet can be located anywhere on the Web If the users Web browser is Java-
enabled (for example Suns HotJava browser or Netscapes Navigator 20) then the applet is
pulled down into the users client computer and executed within the browser environment
Java is often described as a cross-platform programming language its also common to refer to Java
programs as architecture-neutral byte codes It has to be this way of course because the Web server
that delivers the Java applet to the Web client doesnt know what kind of hardwaresoftware environment
its running on And the developer who creates the Java applet doesnt want to worry about whether it will
work correctly on OS2 Windows Unix and MacOS
1) The Java compiler javac which translates human-readable Java source code to architecture-neutral bytecodes
2) The Java interpreter which executes Java programs on the users PC or workstation
3) The C header and source file generator javah and java_g These are used to generate header files for C as well as source files for making methods (roughly equivalent to procedures or subroutines in other languages) within Java
4) The Java disassembler javap which prints out information about a class file (a file containing a Java applet)
5) The document generator javadoc which is capable of generating an HTML file from a Java source-code file
6) The profiling tool javaprof which formats the performance data created if the programmer uses the -prof option in the Java interpreter to obtain statistics on run time and performance
Security and robust behavior
Security and robustness are obviously important in the distributed environment represented by
the Internet if you download a Java applet from a Web server for example you really dont
want it to run amok on your computer and delete all the files on your hard disk This is not as far-
fetched as it might sound because the incorporation of Java applets into Web pages means that
you may be invoking computer programs written by people anywhere in the world located
anywhere on the Web Indeed once you begin using a Java-enabled browser youre
automatically at risk since you dont know at the moment you decide to retrieve a Web page (say
by clicking on a hyperlink within an existing page being displayed on your computer) whether it
will contain embedded Java applets
Sun has addressed this concern by imposing severe constraints on the Java programming
language as well as extensive run-time checking in the interpreter located inside the Java-
enabled browser The Java language for example forbids the use of address pointers and pointer
arithmetic found in C and C++ this eliminates a large class of innocent errors that might
otherwise plague the user of Java applets In addition the following steps have been taken to
increase the level of security and robust behavior
1) The Java run-time interpreter verifies that bytecodes (the compiled architecture-neutral
form of Java applet that gets downloaded from the Web server into the users machine)
dont violate any language constructs -- which could happen if an altered Java compiler
was used by a hacker The verification logic checks to make sure that the Java applet
doesnt access restricted memory forge memory pointers or access objects in a manner
inconsistent with its definition It also ensures that method (subroutine) calls include the
correct number of arguments of the right type and that there are no stack overflows
2) During loading of the Java applet the run-time interpreter verifies class names (a class
is an entire Java applet) and access restrictions
3) If a Java applet attempts to access a file for which it has no permission a dialog box will
pop up to allow the user to continue or stop the execution of the applet
4) Future releases of Java are planned to have facilities for using public key encryption to
verify the source and origin of the Java source code and its integrity after traveling
through the network to reach the users machine
5) At run time information about the origin of the Java applet can be used to decide what
the applet is allowed to do For example a security mechanism can be used to determine
whether the compiled Java byte codes originated from within an organizations security
firewall or not This makes it possible to set a security policy that restricts the use and
execution of Java code that an organization doesnt know or trust
This last point is crucial for there are likely to be a number of attempts -- both innocent and
malicious -- to circumvent the security mechanisms that Sun has built into the language In its
white paper on the Java language Sun expresses the following optimistic statement about Java
security Java is designed to operate in distributed environments which means that security is of
paramount importance With security features designed into the language and run-time system
Java lets you construct applications that cant be invaded from outside In the networked
environment applications written in Java are secure from intrusion by unauthorized code
attempting to get behind the scenes and create viruses or invade file systems For the security-
conscious organizations though the firewall protection mentioned above will be crucial -- at
least in the short term
Basics overview of programming paradigms
The term paradigm describes a set of techniques methods theories and standards that together represent
a way of thinking for problem solving According to [Wegner 1988] paradigms are ldquopatterns of
thought for problem solvingrdquo Language paradigms were associated with classes of languages First the
paradigms are defined Thereafter programming languages according to the different paradigms are
classified The language paradigms are divided into two parts imperative and declarative paradigms as
shown in the Figure 1 Imperative languages can be further classified into procedural and object
oriented approach Declarative languages can be classified into functional languages and logical
languages In Figure1 the examples of languages in each category are also given
Language Paradigms
Computer programmers have evolved from the early days of the bit processing first generation
languages into sophisticated logical designers of complex software applications A programming
paradigm is the logical approach used in software engineering that describes how a programming
language is implemented Programming paradigms are unique to each language within the
computer programming domain and many programming languages utilize multiple paradigms
The term paradigm is best described as a pattern or model Therefore a programming
paradigm can be defined as a pattern or model used within a software programming language to
create software applications
Programming languages are extremely logical and follow standard rules of mathematics Each
language has a unique method for applying these rules especially around the areas of functions
variables methods and objects There are many programming paradigms examples include
object oriented procedural and structured programming Each paradigm has unique
requirements on the usage and abstractions of processes within the programming language
Features of OOPS
Object oriented methods are favored because many experts agree that Object Oriented techniques
are more disciplined than conventional structured techniques (Martin and Odell 1992)
The main components of Object Oriented technology are lsquoobjects and classesrsquo lsquodata
abstraction and encapsulationrsquo lsquoinheritancersquo and lsquopolymorphismrsquo It is very important for
you to understand these concepts Further in this unit you can find the details of these concepts
a) Object oriented programming (OOP) is a programming model where Programs are organized around object and data rather than action and logic OOP allow decomposition of a problem into a number of entities called Object and then builds data and function around these objects
b) The Program is divided into number of small units called Object The data and function are build around these objects
c) The data of the objects can be accessed only by the functions associated with that objectd) The functions of one object can access the functions of other object
OOP has the following important features
ClassA class is the core of any modern Object Oriented Programming languageIn OOP languages it is must to create a class for representing data Class is a blueprint of an object that contains variables for storing data and functions to performing operations on these data Class will not occupy any memory space and hence it is only logical representation of data
To create a class you simply use the keyword class followed by the class nameclass Employee
Object
Objects are the basic run-time entities in an object oriented systemThey may represent a
persona place or any item that the program has to handle
Object is a Software bundle of related variable and methods
ldquoObject is an instance of a classrdquo
Class will not occupy any memory space Hence to work with the data represented by the class you must create a variable for the class which is called as an object When an object is created by using the keyword new then memory will be allocated for the class in heap memory area which is called as an instance and its starting address will be stored in the object in stack memory area
When an object is created without the keyword new then memory will not be allocated in heap Ie instance will not be created and object in the stack contains the value nullWhen an object contains null then it is not possible to access the members of the class using that object
class Employee
Syntax to create an object of class Employee-
Employee objEmp = new Employee()
Similarly the following can be treated as objects in different programming problems
Employees in a payroll system Customers and accounts in a banking system Salesman products customers in a sales tracking system Data structures like linked lists stacks etc Hardware devices like magnetic tape drive keyboard printer etc GUI elements like windows menus events etc in any window-based application
All the programming languages supporting object oriented Programming will be supporting these three main concepts
1 Encapsulation2 Inheritance3 Polymorphism
AbstractionAbstraction is To represent the essential feature without representing the back ground details
Abstraction lets you focus on what the object does instead of how it does it
Abstraction provides you a generalized view of your classes or object by providing relevant information
Abstraction is the process of hiding the working style of an object and showing the information of an object in understandable manner
Real world Example of Abstraction - Suppose you have an object Mobile Phone
Suppose you have 3 mobile phones as following-
Nokia 1400 (Features- Calling SMS)Nokia 2700 (Features- Calling SMS FM Radio MP3 Camera)Black Berry (Features-Calling SMS FM Radio MP3 Camera Video Recording Reading E-mails)
Abstract information (Necessary and Common Information) for the object Mobile Phone is make a call to any number and can send SMS
so that for mobile phone object you will have abstract class like following-
abstract class MobilePhone public void Calling() public void SendSMS()
public class Nokia1400 MobilePhone
public class Nokia2700 MobilePhone public void FMRadio() public void MP3() public void Camera()
public class BlackBerry MobilePhone public void FMRadio() public void MP3() public void Camera() public void Recording() public void ReadAndSendEmails()
Abstraction means putting all the variables and methods in a class which are necessaryFor example - Abstract class and abstract methodAbstraction is the common thingexample If somebody in your collage tell you to fill application form you will fill your details like name address data of birth which semester percentage you have got etcIf some doctor gives you an application to fill the details you will fill the details like name address date of birth blood group height and weight
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
The relationship among Java programs (or applets) the Java-enabled browser and the Web is
illustrated in Figure Users access a Web page and pull it down to their client In this case
though the Web page contains an additional HTML tag called APP which refers to a Java
applet and that applet can be located anywhere on the Web If the users Web browser is Java-
enabled (for example Suns HotJava browser or Netscapes Navigator 20) then the applet is
pulled down into the users client computer and executed within the browser environment
Java is often described as a cross-platform programming language its also common to refer to Java
programs as architecture-neutral byte codes It has to be this way of course because the Web server
that delivers the Java applet to the Web client doesnt know what kind of hardwaresoftware environment
its running on And the developer who creates the Java applet doesnt want to worry about whether it will
work correctly on OS2 Windows Unix and MacOS
1) The Java compiler javac which translates human-readable Java source code to architecture-neutral bytecodes
2) The Java interpreter which executes Java programs on the users PC or workstation
3) The C header and source file generator javah and java_g These are used to generate header files for C as well as source files for making methods (roughly equivalent to procedures or subroutines in other languages) within Java
4) The Java disassembler javap which prints out information about a class file (a file containing a Java applet)
5) The document generator javadoc which is capable of generating an HTML file from a Java source-code file
6) The profiling tool javaprof which formats the performance data created if the programmer uses the -prof option in the Java interpreter to obtain statistics on run time and performance
Security and robust behavior
Security and robustness are obviously important in the distributed environment represented by
the Internet if you download a Java applet from a Web server for example you really dont
want it to run amok on your computer and delete all the files on your hard disk This is not as far-
fetched as it might sound because the incorporation of Java applets into Web pages means that
you may be invoking computer programs written by people anywhere in the world located
anywhere on the Web Indeed once you begin using a Java-enabled browser youre
automatically at risk since you dont know at the moment you decide to retrieve a Web page (say
by clicking on a hyperlink within an existing page being displayed on your computer) whether it
will contain embedded Java applets
Sun has addressed this concern by imposing severe constraints on the Java programming
language as well as extensive run-time checking in the interpreter located inside the Java-
enabled browser The Java language for example forbids the use of address pointers and pointer
arithmetic found in C and C++ this eliminates a large class of innocent errors that might
otherwise plague the user of Java applets In addition the following steps have been taken to
increase the level of security and robust behavior
1) The Java run-time interpreter verifies that bytecodes (the compiled architecture-neutral
form of Java applet that gets downloaded from the Web server into the users machine)
dont violate any language constructs -- which could happen if an altered Java compiler
was used by a hacker The verification logic checks to make sure that the Java applet
doesnt access restricted memory forge memory pointers or access objects in a manner
inconsistent with its definition It also ensures that method (subroutine) calls include the
correct number of arguments of the right type and that there are no stack overflows
2) During loading of the Java applet the run-time interpreter verifies class names (a class
is an entire Java applet) and access restrictions
3) If a Java applet attempts to access a file for which it has no permission a dialog box will
pop up to allow the user to continue or stop the execution of the applet
4) Future releases of Java are planned to have facilities for using public key encryption to
verify the source and origin of the Java source code and its integrity after traveling
through the network to reach the users machine
5) At run time information about the origin of the Java applet can be used to decide what
the applet is allowed to do For example a security mechanism can be used to determine
whether the compiled Java byte codes originated from within an organizations security
firewall or not This makes it possible to set a security policy that restricts the use and
execution of Java code that an organization doesnt know or trust
This last point is crucial for there are likely to be a number of attempts -- both innocent and
malicious -- to circumvent the security mechanisms that Sun has built into the language In its
white paper on the Java language Sun expresses the following optimistic statement about Java
security Java is designed to operate in distributed environments which means that security is of
paramount importance With security features designed into the language and run-time system
Java lets you construct applications that cant be invaded from outside In the networked
environment applications written in Java are secure from intrusion by unauthorized code
attempting to get behind the scenes and create viruses or invade file systems For the security-
conscious organizations though the firewall protection mentioned above will be crucial -- at
least in the short term
Basics overview of programming paradigms
The term paradigm describes a set of techniques methods theories and standards that together represent
a way of thinking for problem solving According to [Wegner 1988] paradigms are ldquopatterns of
thought for problem solvingrdquo Language paradigms were associated with classes of languages First the
paradigms are defined Thereafter programming languages according to the different paradigms are
classified The language paradigms are divided into two parts imperative and declarative paradigms as
shown in the Figure 1 Imperative languages can be further classified into procedural and object
oriented approach Declarative languages can be classified into functional languages and logical
languages In Figure1 the examples of languages in each category are also given
Language Paradigms
Computer programmers have evolved from the early days of the bit processing first generation
languages into sophisticated logical designers of complex software applications A programming
paradigm is the logical approach used in software engineering that describes how a programming
language is implemented Programming paradigms are unique to each language within the
computer programming domain and many programming languages utilize multiple paradigms
The term paradigm is best described as a pattern or model Therefore a programming
paradigm can be defined as a pattern or model used within a software programming language to
create software applications
Programming languages are extremely logical and follow standard rules of mathematics Each
language has a unique method for applying these rules especially around the areas of functions
variables methods and objects There are many programming paradigms examples include
object oriented procedural and structured programming Each paradigm has unique
requirements on the usage and abstractions of processes within the programming language
Features of OOPS
Object oriented methods are favored because many experts agree that Object Oriented techniques
are more disciplined than conventional structured techniques (Martin and Odell 1992)
The main components of Object Oriented technology are lsquoobjects and classesrsquo lsquodata
abstraction and encapsulationrsquo lsquoinheritancersquo and lsquopolymorphismrsquo It is very important for
you to understand these concepts Further in this unit you can find the details of these concepts
a) Object oriented programming (OOP) is a programming model where Programs are organized around object and data rather than action and logic OOP allow decomposition of a problem into a number of entities called Object and then builds data and function around these objects
b) The Program is divided into number of small units called Object The data and function are build around these objects
c) The data of the objects can be accessed only by the functions associated with that objectd) The functions of one object can access the functions of other object
OOP has the following important features
ClassA class is the core of any modern Object Oriented Programming languageIn OOP languages it is must to create a class for representing data Class is a blueprint of an object that contains variables for storing data and functions to performing operations on these data Class will not occupy any memory space and hence it is only logical representation of data
To create a class you simply use the keyword class followed by the class nameclass Employee
Object
Objects are the basic run-time entities in an object oriented systemThey may represent a
persona place or any item that the program has to handle
Object is a Software bundle of related variable and methods
ldquoObject is an instance of a classrdquo
Class will not occupy any memory space Hence to work with the data represented by the class you must create a variable for the class which is called as an object When an object is created by using the keyword new then memory will be allocated for the class in heap memory area which is called as an instance and its starting address will be stored in the object in stack memory area
When an object is created without the keyword new then memory will not be allocated in heap Ie instance will not be created and object in the stack contains the value nullWhen an object contains null then it is not possible to access the members of the class using that object
class Employee
Syntax to create an object of class Employee-
Employee objEmp = new Employee()
Similarly the following can be treated as objects in different programming problems
Employees in a payroll system Customers and accounts in a banking system Salesman products customers in a sales tracking system Data structures like linked lists stacks etc Hardware devices like magnetic tape drive keyboard printer etc GUI elements like windows menus events etc in any window-based application
All the programming languages supporting object oriented Programming will be supporting these three main concepts
1 Encapsulation2 Inheritance3 Polymorphism
AbstractionAbstraction is To represent the essential feature without representing the back ground details
Abstraction lets you focus on what the object does instead of how it does it
Abstraction provides you a generalized view of your classes or object by providing relevant information
Abstraction is the process of hiding the working style of an object and showing the information of an object in understandable manner
Real world Example of Abstraction - Suppose you have an object Mobile Phone
Suppose you have 3 mobile phones as following-
Nokia 1400 (Features- Calling SMS)Nokia 2700 (Features- Calling SMS FM Radio MP3 Camera)Black Berry (Features-Calling SMS FM Radio MP3 Camera Video Recording Reading E-mails)
Abstract information (Necessary and Common Information) for the object Mobile Phone is make a call to any number and can send SMS
so that for mobile phone object you will have abstract class like following-
abstract class MobilePhone public void Calling() public void SendSMS()
public class Nokia1400 MobilePhone
public class Nokia2700 MobilePhone public void FMRadio() public void MP3() public void Camera()
public class BlackBerry MobilePhone public void FMRadio() public void MP3() public void Camera() public void Recording() public void ReadAndSendEmails()
Abstraction means putting all the variables and methods in a class which are necessaryFor example - Abstract class and abstract methodAbstraction is the common thingexample If somebody in your collage tell you to fill application form you will fill your details like name address data of birth which semester percentage you have got etcIf some doctor gives you an application to fill the details you will fill the details like name address date of birth blood group height and weight
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
by clicking on a hyperlink within an existing page being displayed on your computer) whether it
will contain embedded Java applets
Sun has addressed this concern by imposing severe constraints on the Java programming
language as well as extensive run-time checking in the interpreter located inside the Java-
enabled browser The Java language for example forbids the use of address pointers and pointer
arithmetic found in C and C++ this eliminates a large class of innocent errors that might
otherwise plague the user of Java applets In addition the following steps have been taken to
increase the level of security and robust behavior
1) The Java run-time interpreter verifies that bytecodes (the compiled architecture-neutral
form of Java applet that gets downloaded from the Web server into the users machine)
dont violate any language constructs -- which could happen if an altered Java compiler
was used by a hacker The verification logic checks to make sure that the Java applet
doesnt access restricted memory forge memory pointers or access objects in a manner
inconsistent with its definition It also ensures that method (subroutine) calls include the
correct number of arguments of the right type and that there are no stack overflows
2) During loading of the Java applet the run-time interpreter verifies class names (a class
is an entire Java applet) and access restrictions
3) If a Java applet attempts to access a file for which it has no permission a dialog box will
pop up to allow the user to continue or stop the execution of the applet
4) Future releases of Java are planned to have facilities for using public key encryption to
verify the source and origin of the Java source code and its integrity after traveling
through the network to reach the users machine
5) At run time information about the origin of the Java applet can be used to decide what
the applet is allowed to do For example a security mechanism can be used to determine
whether the compiled Java byte codes originated from within an organizations security
firewall or not This makes it possible to set a security policy that restricts the use and
execution of Java code that an organization doesnt know or trust
This last point is crucial for there are likely to be a number of attempts -- both innocent and
malicious -- to circumvent the security mechanisms that Sun has built into the language In its
white paper on the Java language Sun expresses the following optimistic statement about Java
security Java is designed to operate in distributed environments which means that security is of
paramount importance With security features designed into the language and run-time system
Java lets you construct applications that cant be invaded from outside In the networked
environment applications written in Java are secure from intrusion by unauthorized code
attempting to get behind the scenes and create viruses or invade file systems For the security-
conscious organizations though the firewall protection mentioned above will be crucial -- at
least in the short term
Basics overview of programming paradigms
The term paradigm describes a set of techniques methods theories and standards that together represent
a way of thinking for problem solving According to [Wegner 1988] paradigms are ldquopatterns of
thought for problem solvingrdquo Language paradigms were associated with classes of languages First the
paradigms are defined Thereafter programming languages according to the different paradigms are
classified The language paradigms are divided into two parts imperative and declarative paradigms as
shown in the Figure 1 Imperative languages can be further classified into procedural and object
oriented approach Declarative languages can be classified into functional languages and logical
languages In Figure1 the examples of languages in each category are also given
Language Paradigms
Computer programmers have evolved from the early days of the bit processing first generation
languages into sophisticated logical designers of complex software applications A programming
paradigm is the logical approach used in software engineering that describes how a programming
language is implemented Programming paradigms are unique to each language within the
computer programming domain and many programming languages utilize multiple paradigms
The term paradigm is best described as a pattern or model Therefore a programming
paradigm can be defined as a pattern or model used within a software programming language to
create software applications
Programming languages are extremely logical and follow standard rules of mathematics Each
language has a unique method for applying these rules especially around the areas of functions
variables methods and objects There are many programming paradigms examples include
object oriented procedural and structured programming Each paradigm has unique
requirements on the usage and abstractions of processes within the programming language
Features of OOPS
Object oriented methods are favored because many experts agree that Object Oriented techniques
are more disciplined than conventional structured techniques (Martin and Odell 1992)
The main components of Object Oriented technology are lsquoobjects and classesrsquo lsquodata
abstraction and encapsulationrsquo lsquoinheritancersquo and lsquopolymorphismrsquo It is very important for
you to understand these concepts Further in this unit you can find the details of these concepts
a) Object oriented programming (OOP) is a programming model where Programs are organized around object and data rather than action and logic OOP allow decomposition of a problem into a number of entities called Object and then builds data and function around these objects
b) The Program is divided into number of small units called Object The data and function are build around these objects
c) The data of the objects can be accessed only by the functions associated with that objectd) The functions of one object can access the functions of other object
OOP has the following important features
ClassA class is the core of any modern Object Oriented Programming languageIn OOP languages it is must to create a class for representing data Class is a blueprint of an object that contains variables for storing data and functions to performing operations on these data Class will not occupy any memory space and hence it is only logical representation of data
To create a class you simply use the keyword class followed by the class nameclass Employee
Object
Objects are the basic run-time entities in an object oriented systemThey may represent a
persona place or any item that the program has to handle
Object is a Software bundle of related variable and methods
ldquoObject is an instance of a classrdquo
Class will not occupy any memory space Hence to work with the data represented by the class you must create a variable for the class which is called as an object When an object is created by using the keyword new then memory will be allocated for the class in heap memory area which is called as an instance and its starting address will be stored in the object in stack memory area
When an object is created without the keyword new then memory will not be allocated in heap Ie instance will not be created and object in the stack contains the value nullWhen an object contains null then it is not possible to access the members of the class using that object
class Employee
Syntax to create an object of class Employee-
Employee objEmp = new Employee()
Similarly the following can be treated as objects in different programming problems
Employees in a payroll system Customers and accounts in a banking system Salesman products customers in a sales tracking system Data structures like linked lists stacks etc Hardware devices like magnetic tape drive keyboard printer etc GUI elements like windows menus events etc in any window-based application
All the programming languages supporting object oriented Programming will be supporting these three main concepts
1 Encapsulation2 Inheritance3 Polymorphism
AbstractionAbstraction is To represent the essential feature without representing the back ground details
Abstraction lets you focus on what the object does instead of how it does it
Abstraction provides you a generalized view of your classes or object by providing relevant information
Abstraction is the process of hiding the working style of an object and showing the information of an object in understandable manner
Real world Example of Abstraction - Suppose you have an object Mobile Phone
Suppose you have 3 mobile phones as following-
Nokia 1400 (Features- Calling SMS)Nokia 2700 (Features- Calling SMS FM Radio MP3 Camera)Black Berry (Features-Calling SMS FM Radio MP3 Camera Video Recording Reading E-mails)
Abstract information (Necessary and Common Information) for the object Mobile Phone is make a call to any number and can send SMS
so that for mobile phone object you will have abstract class like following-
abstract class MobilePhone public void Calling() public void SendSMS()
public class Nokia1400 MobilePhone
public class Nokia2700 MobilePhone public void FMRadio() public void MP3() public void Camera()
public class BlackBerry MobilePhone public void FMRadio() public void MP3() public void Camera() public void Recording() public void ReadAndSendEmails()
Abstraction means putting all the variables and methods in a class which are necessaryFor example - Abstract class and abstract methodAbstraction is the common thingexample If somebody in your collage tell you to fill application form you will fill your details like name address data of birth which semester percentage you have got etcIf some doctor gives you an application to fill the details you will fill the details like name address date of birth blood group height and weight
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
This last point is crucial for there are likely to be a number of attempts -- both innocent and
malicious -- to circumvent the security mechanisms that Sun has built into the language In its
white paper on the Java language Sun expresses the following optimistic statement about Java
security Java is designed to operate in distributed environments which means that security is of
paramount importance With security features designed into the language and run-time system
Java lets you construct applications that cant be invaded from outside In the networked
environment applications written in Java are secure from intrusion by unauthorized code
attempting to get behind the scenes and create viruses or invade file systems For the security-
conscious organizations though the firewall protection mentioned above will be crucial -- at
least in the short term
Basics overview of programming paradigms
The term paradigm describes a set of techniques methods theories and standards that together represent
a way of thinking for problem solving According to [Wegner 1988] paradigms are ldquopatterns of
thought for problem solvingrdquo Language paradigms were associated with classes of languages First the
paradigms are defined Thereafter programming languages according to the different paradigms are
classified The language paradigms are divided into two parts imperative and declarative paradigms as
shown in the Figure 1 Imperative languages can be further classified into procedural and object
oriented approach Declarative languages can be classified into functional languages and logical
languages In Figure1 the examples of languages in each category are also given
Language Paradigms
Computer programmers have evolved from the early days of the bit processing first generation
languages into sophisticated logical designers of complex software applications A programming
paradigm is the logical approach used in software engineering that describes how a programming
language is implemented Programming paradigms are unique to each language within the
computer programming domain and many programming languages utilize multiple paradigms
The term paradigm is best described as a pattern or model Therefore a programming
paradigm can be defined as a pattern or model used within a software programming language to
create software applications
Programming languages are extremely logical and follow standard rules of mathematics Each
language has a unique method for applying these rules especially around the areas of functions
variables methods and objects There are many programming paradigms examples include
object oriented procedural and structured programming Each paradigm has unique
requirements on the usage and abstractions of processes within the programming language
Features of OOPS
Object oriented methods are favored because many experts agree that Object Oriented techniques
are more disciplined than conventional structured techniques (Martin and Odell 1992)
The main components of Object Oriented technology are lsquoobjects and classesrsquo lsquodata
abstraction and encapsulationrsquo lsquoinheritancersquo and lsquopolymorphismrsquo It is very important for
you to understand these concepts Further in this unit you can find the details of these concepts
a) Object oriented programming (OOP) is a programming model where Programs are organized around object and data rather than action and logic OOP allow decomposition of a problem into a number of entities called Object and then builds data and function around these objects
b) The Program is divided into number of small units called Object The data and function are build around these objects
c) The data of the objects can be accessed only by the functions associated with that objectd) The functions of one object can access the functions of other object
OOP has the following important features
ClassA class is the core of any modern Object Oriented Programming languageIn OOP languages it is must to create a class for representing data Class is a blueprint of an object that contains variables for storing data and functions to performing operations on these data Class will not occupy any memory space and hence it is only logical representation of data
To create a class you simply use the keyword class followed by the class nameclass Employee
Object
Objects are the basic run-time entities in an object oriented systemThey may represent a
persona place or any item that the program has to handle
Object is a Software bundle of related variable and methods
ldquoObject is an instance of a classrdquo
Class will not occupy any memory space Hence to work with the data represented by the class you must create a variable for the class which is called as an object When an object is created by using the keyword new then memory will be allocated for the class in heap memory area which is called as an instance and its starting address will be stored in the object in stack memory area
When an object is created without the keyword new then memory will not be allocated in heap Ie instance will not be created and object in the stack contains the value nullWhen an object contains null then it is not possible to access the members of the class using that object
class Employee
Syntax to create an object of class Employee-
Employee objEmp = new Employee()
Similarly the following can be treated as objects in different programming problems
Employees in a payroll system Customers and accounts in a banking system Salesman products customers in a sales tracking system Data structures like linked lists stacks etc Hardware devices like magnetic tape drive keyboard printer etc GUI elements like windows menus events etc in any window-based application
All the programming languages supporting object oriented Programming will be supporting these three main concepts
1 Encapsulation2 Inheritance3 Polymorphism
AbstractionAbstraction is To represent the essential feature without representing the back ground details
Abstraction lets you focus on what the object does instead of how it does it
Abstraction provides you a generalized view of your classes or object by providing relevant information
Abstraction is the process of hiding the working style of an object and showing the information of an object in understandable manner
Real world Example of Abstraction - Suppose you have an object Mobile Phone
Suppose you have 3 mobile phones as following-
Nokia 1400 (Features- Calling SMS)Nokia 2700 (Features- Calling SMS FM Radio MP3 Camera)Black Berry (Features-Calling SMS FM Radio MP3 Camera Video Recording Reading E-mails)
Abstract information (Necessary and Common Information) for the object Mobile Phone is make a call to any number and can send SMS
so that for mobile phone object you will have abstract class like following-
abstract class MobilePhone public void Calling() public void SendSMS()
public class Nokia1400 MobilePhone
public class Nokia2700 MobilePhone public void FMRadio() public void MP3() public void Camera()
public class BlackBerry MobilePhone public void FMRadio() public void MP3() public void Camera() public void Recording() public void ReadAndSendEmails()
Abstraction means putting all the variables and methods in a class which are necessaryFor example - Abstract class and abstract methodAbstraction is the common thingexample If somebody in your collage tell you to fill application form you will fill your details like name address data of birth which semester percentage you have got etcIf some doctor gives you an application to fill the details you will fill the details like name address date of birth blood group height and weight
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
Language Paradigms
Computer programmers have evolved from the early days of the bit processing first generation
languages into sophisticated logical designers of complex software applications A programming
paradigm is the logical approach used in software engineering that describes how a programming
language is implemented Programming paradigms are unique to each language within the
computer programming domain and many programming languages utilize multiple paradigms
The term paradigm is best described as a pattern or model Therefore a programming
paradigm can be defined as a pattern or model used within a software programming language to
create software applications
Programming languages are extremely logical and follow standard rules of mathematics Each
language has a unique method for applying these rules especially around the areas of functions
variables methods and objects There are many programming paradigms examples include
object oriented procedural and structured programming Each paradigm has unique
requirements on the usage and abstractions of processes within the programming language
Features of OOPS
Object oriented methods are favored because many experts agree that Object Oriented techniques
are more disciplined than conventional structured techniques (Martin and Odell 1992)
The main components of Object Oriented technology are lsquoobjects and classesrsquo lsquodata
abstraction and encapsulationrsquo lsquoinheritancersquo and lsquopolymorphismrsquo It is very important for
you to understand these concepts Further in this unit you can find the details of these concepts
a) Object oriented programming (OOP) is a programming model where Programs are organized around object and data rather than action and logic OOP allow decomposition of a problem into a number of entities called Object and then builds data and function around these objects
b) The Program is divided into number of small units called Object The data and function are build around these objects
c) The data of the objects can be accessed only by the functions associated with that objectd) The functions of one object can access the functions of other object
OOP has the following important features
ClassA class is the core of any modern Object Oriented Programming languageIn OOP languages it is must to create a class for representing data Class is a blueprint of an object that contains variables for storing data and functions to performing operations on these data Class will not occupy any memory space and hence it is only logical representation of data
To create a class you simply use the keyword class followed by the class nameclass Employee
Object
Objects are the basic run-time entities in an object oriented systemThey may represent a
persona place or any item that the program has to handle
Object is a Software bundle of related variable and methods
ldquoObject is an instance of a classrdquo
Class will not occupy any memory space Hence to work with the data represented by the class you must create a variable for the class which is called as an object When an object is created by using the keyword new then memory will be allocated for the class in heap memory area which is called as an instance and its starting address will be stored in the object in stack memory area
When an object is created without the keyword new then memory will not be allocated in heap Ie instance will not be created and object in the stack contains the value nullWhen an object contains null then it is not possible to access the members of the class using that object
class Employee
Syntax to create an object of class Employee-
Employee objEmp = new Employee()
Similarly the following can be treated as objects in different programming problems
Employees in a payroll system Customers and accounts in a banking system Salesman products customers in a sales tracking system Data structures like linked lists stacks etc Hardware devices like magnetic tape drive keyboard printer etc GUI elements like windows menus events etc in any window-based application
All the programming languages supporting object oriented Programming will be supporting these three main concepts
1 Encapsulation2 Inheritance3 Polymorphism
AbstractionAbstraction is To represent the essential feature without representing the back ground details
Abstraction lets you focus on what the object does instead of how it does it
Abstraction provides you a generalized view of your classes or object by providing relevant information
Abstraction is the process of hiding the working style of an object and showing the information of an object in understandable manner
Real world Example of Abstraction - Suppose you have an object Mobile Phone
Suppose you have 3 mobile phones as following-
Nokia 1400 (Features- Calling SMS)Nokia 2700 (Features- Calling SMS FM Radio MP3 Camera)Black Berry (Features-Calling SMS FM Radio MP3 Camera Video Recording Reading E-mails)
Abstract information (Necessary and Common Information) for the object Mobile Phone is make a call to any number and can send SMS
so that for mobile phone object you will have abstract class like following-
abstract class MobilePhone public void Calling() public void SendSMS()
public class Nokia1400 MobilePhone
public class Nokia2700 MobilePhone public void FMRadio() public void MP3() public void Camera()
public class BlackBerry MobilePhone public void FMRadio() public void MP3() public void Camera() public void Recording() public void ReadAndSendEmails()
Abstraction means putting all the variables and methods in a class which are necessaryFor example - Abstract class and abstract methodAbstraction is the common thingexample If somebody in your collage tell you to fill application form you will fill your details like name address data of birth which semester percentage you have got etcIf some doctor gives you an application to fill the details you will fill the details like name address date of birth blood group height and weight
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
OOP has the following important features
ClassA class is the core of any modern Object Oriented Programming languageIn OOP languages it is must to create a class for representing data Class is a blueprint of an object that contains variables for storing data and functions to performing operations on these data Class will not occupy any memory space and hence it is only logical representation of data
To create a class you simply use the keyword class followed by the class nameclass Employee
Object
Objects are the basic run-time entities in an object oriented systemThey may represent a
persona place or any item that the program has to handle
Object is a Software bundle of related variable and methods
ldquoObject is an instance of a classrdquo
Class will not occupy any memory space Hence to work with the data represented by the class you must create a variable for the class which is called as an object When an object is created by using the keyword new then memory will be allocated for the class in heap memory area which is called as an instance and its starting address will be stored in the object in stack memory area
When an object is created without the keyword new then memory will not be allocated in heap Ie instance will not be created and object in the stack contains the value nullWhen an object contains null then it is not possible to access the members of the class using that object
class Employee
Syntax to create an object of class Employee-
Employee objEmp = new Employee()
Similarly the following can be treated as objects in different programming problems
Employees in a payroll system Customers and accounts in a banking system Salesman products customers in a sales tracking system Data structures like linked lists stacks etc Hardware devices like magnetic tape drive keyboard printer etc GUI elements like windows menus events etc in any window-based application
All the programming languages supporting object oriented Programming will be supporting these three main concepts
1 Encapsulation2 Inheritance3 Polymorphism
AbstractionAbstraction is To represent the essential feature without representing the back ground details
Abstraction lets you focus on what the object does instead of how it does it
Abstraction provides you a generalized view of your classes or object by providing relevant information
Abstraction is the process of hiding the working style of an object and showing the information of an object in understandable manner
Real world Example of Abstraction - Suppose you have an object Mobile Phone
Suppose you have 3 mobile phones as following-
Nokia 1400 (Features- Calling SMS)Nokia 2700 (Features- Calling SMS FM Radio MP3 Camera)Black Berry (Features-Calling SMS FM Radio MP3 Camera Video Recording Reading E-mails)
Abstract information (Necessary and Common Information) for the object Mobile Phone is make a call to any number and can send SMS
so that for mobile phone object you will have abstract class like following-
abstract class MobilePhone public void Calling() public void SendSMS()
public class Nokia1400 MobilePhone
public class Nokia2700 MobilePhone public void FMRadio() public void MP3() public void Camera()
public class BlackBerry MobilePhone public void FMRadio() public void MP3() public void Camera() public void Recording() public void ReadAndSendEmails()
Abstraction means putting all the variables and methods in a class which are necessaryFor example - Abstract class and abstract methodAbstraction is the common thingexample If somebody in your collage tell you to fill application form you will fill your details like name address data of birth which semester percentage you have got etcIf some doctor gives you an application to fill the details you will fill the details like name address date of birth blood group height and weight
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
When an object is created without the keyword new then memory will not be allocated in heap Ie instance will not be created and object in the stack contains the value nullWhen an object contains null then it is not possible to access the members of the class using that object
class Employee
Syntax to create an object of class Employee-
Employee objEmp = new Employee()
Similarly the following can be treated as objects in different programming problems
Employees in a payroll system Customers and accounts in a banking system Salesman products customers in a sales tracking system Data structures like linked lists stacks etc Hardware devices like magnetic tape drive keyboard printer etc GUI elements like windows menus events etc in any window-based application
All the programming languages supporting object oriented Programming will be supporting these three main concepts
1 Encapsulation2 Inheritance3 Polymorphism
AbstractionAbstraction is To represent the essential feature without representing the back ground details
Abstraction lets you focus on what the object does instead of how it does it
Abstraction provides you a generalized view of your classes or object by providing relevant information
Abstraction is the process of hiding the working style of an object and showing the information of an object in understandable manner
Real world Example of Abstraction - Suppose you have an object Mobile Phone
Suppose you have 3 mobile phones as following-
Nokia 1400 (Features- Calling SMS)Nokia 2700 (Features- Calling SMS FM Radio MP3 Camera)Black Berry (Features-Calling SMS FM Radio MP3 Camera Video Recording Reading E-mails)
Abstract information (Necessary and Common Information) for the object Mobile Phone is make a call to any number and can send SMS
so that for mobile phone object you will have abstract class like following-
abstract class MobilePhone public void Calling() public void SendSMS()
public class Nokia1400 MobilePhone
public class Nokia2700 MobilePhone public void FMRadio() public void MP3() public void Camera()
public class BlackBerry MobilePhone public void FMRadio() public void MP3() public void Camera() public void Recording() public void ReadAndSendEmails()
Abstraction means putting all the variables and methods in a class which are necessaryFor example - Abstract class and abstract methodAbstraction is the common thingexample If somebody in your collage tell you to fill application form you will fill your details like name address data of birth which semester percentage you have got etcIf some doctor gives you an application to fill the details you will fill the details like name address date of birth blood group height and weight
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
All the programming languages supporting object oriented Programming will be supporting these three main concepts
1 Encapsulation2 Inheritance3 Polymorphism
AbstractionAbstraction is To represent the essential feature without representing the back ground details
Abstraction lets you focus on what the object does instead of how it does it
Abstraction provides you a generalized view of your classes or object by providing relevant information
Abstraction is the process of hiding the working style of an object and showing the information of an object in understandable manner
Real world Example of Abstraction - Suppose you have an object Mobile Phone
Suppose you have 3 mobile phones as following-
Nokia 1400 (Features- Calling SMS)Nokia 2700 (Features- Calling SMS FM Radio MP3 Camera)Black Berry (Features-Calling SMS FM Radio MP3 Camera Video Recording Reading E-mails)
Abstract information (Necessary and Common Information) for the object Mobile Phone is make a call to any number and can send SMS
so that for mobile phone object you will have abstract class like following-
abstract class MobilePhone public void Calling() public void SendSMS()
public class Nokia1400 MobilePhone
public class Nokia2700 MobilePhone public void FMRadio() public void MP3() public void Camera()
public class BlackBerry MobilePhone public void FMRadio() public void MP3() public void Camera() public void Recording() public void ReadAndSendEmails()
Abstraction means putting all the variables and methods in a class which are necessaryFor example - Abstract class and abstract methodAbstraction is the common thingexample If somebody in your collage tell you to fill application form you will fill your details like name address data of birth which semester percentage you have got etcIf some doctor gives you an application to fill the details you will fill the details like name address date of birth blood group height and weight
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
Nokia 1400 (Features- Calling SMS)Nokia 2700 (Features- Calling SMS FM Radio MP3 Camera)Black Berry (Features-Calling SMS FM Radio MP3 Camera Video Recording Reading E-mails)
Abstract information (Necessary and Common Information) for the object Mobile Phone is make a call to any number and can send SMS
so that for mobile phone object you will have abstract class like following-
abstract class MobilePhone public void Calling() public void SendSMS()
public class Nokia1400 MobilePhone
public class Nokia2700 MobilePhone public void FMRadio() public void MP3() public void Camera()
public class BlackBerry MobilePhone public void FMRadio() public void MP3() public void Camera() public void Recording() public void ReadAndSendEmails()
Abstraction means putting all the variables and methods in a class which are necessaryFor example - Abstract class and abstract methodAbstraction is the common thingexample If somebody in your collage tell you to fill application form you will fill your details like name address data of birth which semester percentage you have got etcIf some doctor gives you an application to fill the details you will fill the details like name address date of birth blood group height and weight
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
See in the above example what is the common thingAge name address so you can create the class which consist of common thing that is called abstract class That class is not complete and it can inherit by other class
Encapsulation Wrapping up data member and method together into a single unit (ie Class) is called Encapsulation
Encapsulation is like enclosing in a capsule That is enclosing the related operations and data related to an object into that object
Encapsulation is like your bag in which you can keep your pen book etc It means this is the property of encapsulating members and functions
class Bag book pen ReadBook()
Encapsulation means hiding the internal details of an object ie how an object does something
Encapsulation prevents clients from seeing its inside view where the behaviour of the abstraction is implemented
Encapsulation is a technique used to protect the information in an object from the other object
Hide the data for security such as making the variables as private and expose the property to access the private data which would be publicSo when you access the property you can validate the data and set it
Example
class Demo private int _mark
public int Mark get return _mark set if (_mark gt 0) _mark = value else _mark = 0
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
Real world Example of Encapsulation-Lets take example of Mobile Phone and Mobile Phone ManufacturerSuppose you are a Mobile Phone Manufacturer and you designed and developed a Mobile Phone design(class) now by using machinery you are manufacturing a Mobile Phone(object) for selling when you sell your Mobile Phone the user only learn how to use the Mobile Phone but not that how this Mobile Phone works
This means that you are creating the class with function and by making object (capsule) of it you are making availability of the functionality of you class by that object and without the interference in the original class
Example-2 TV operation It is encapsulated with cover and we can operate with remote and no need to open TV and change the channelHere everything is in private except remote so that anyone can access not to operate and change the things in TV
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
Inheritance Inheritance is the process by which objects of one class acquire the properties of
objects of another class in the hierarchy For example the scooter is a type of the class two-
wheelers which is again a type of (or kind of) the class motor vehicles As shown in the Figure 5
the principle behind it is that the derived class shares common characteristics with the class from
which it is derivedNew classes can be built from the existing classes It means that we can add
additional features to an existing class without modifying it The new class is referred as derived
class or sub class and the original class is known as base class or super class Therefore the
concept of inheritance provides the idea of reusability This inheritance mechanism allows the
programmer to reuse a class that is made almost but not exactly similar to the required one by
adding a few more features to it As shown in Figure 5 three classes have been derived from one
base class Feature A and Feature B of the base class are inherited in all the three derived classes
Also each derived class has added its own features according to the requirement
Therefore new classes use the concept of reusability and extend their functionality
When a class acquire the property of another class is known as inheritanceInheritance is process of object reusability
For example A Child acquires property of Parents
public class ParentClass public ParentClass() ConsoleWriteLine(Parent Constructor)
public void print() ConsoleWriteLine(Im a Parent Class)
public class ChildClass ParentClass public ChildClass() ConsoleWriteLine(Child Constructor)
public static void Main() ChildClass child = new ChildClass()
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
childprint()
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
Output Parent Constructor Child Constructor Im a Parent Class
Polymorphism
Polymorphism means one name many formsOne function behaves different formsIn other words Many forms of a single object is called Polymorphism
Real World Example of PolymorphismExample-1 A Teacher behaves to studentA Teacher behaves to hisher seniorsHere teacher is an object but attitude is different in different situationExample-2
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
Person behaves SON in house at the same time that person behaves EMPLOYEE in officeExample-3 Your mobile phone one name but many forms
As phone As camera As mp3 player As radio
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
Difference between Abstraction and Encapsulation-
Abstraction Encapsulation
1 Abstraction solves the problem in the
design level
1 Encapsulation solves the problem in the
implementation level
2 Abstraction is used for hiding the
unwanted data and giving relevant data
2 Encapsulation means hiding the code and
data into a single unit to protect the data from
outside world
3 Abstraction lets you focus on what the
object does instead of how it does it
3 Encapsulation means hiding the internal
details or mechanics of how an object does
something
4 Abstraction- Outer layout used in terms
of design
For Example-
Outer Look of a Mobile Phone like it has a
display screen and keypad buttons to dial a
number
4 Encapsulation- Inner layout used in
terms of implementation
For Example- Inner Implementation detail of
a Mobile Phone how keypad button and
Display Screen are connect with each other
using circuits
The easier way to understand Abstraction and encapsulation is as follows-
Real World Example-
Take an example of Mobile Phone-
You have a Mobile Phone you can dial a number using keypad buttons Even you dont know
how these are working internally This is called Abstraction You have the only information that
is needed to dial a number But not its internal working of mobile
But how the Mobile Phone internally working how keypad buttons are connected with internal
circuit is called Encapsulation
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
BENEFITS OF OOPS
OOP offers several benefits to both the program developer and the user The new technology provides
greater programmer productivity better quality of software and lesser maintenance cost The major
benefits are
o Ease in division of job Since it is possible to map objects of the problem domain to
those objects in the program the work can be easily partitioned based on objects
o Reduce complexity Software complexity can be easily managed
o Provide extensibility Object oriented systems can be easily upgraded from small to
large system
o Eliminate redundancy Through inheritance we can eliminate redundant code and
extend the use of existing classes
o Saves development time and increases productivity Instead of writing code from
scratch solutions can be built by using standard working modules
o Allows building secure programs Data hiding principle helps programmer to build
secure programs that cannot be accessed by code in other parts of the program
o Allows designing simpler interfaces Message passing techniques between objects
allows making simpler interface descriptions with external systems
Object Oriented Approach
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
The salient features of Object oriented programming are
More emphasis is on data rather than procedure
Programs are modularized into entities called objects
Data structures methods characterize the objects of the problem
Since the data is not global there is no question of any operations other than those
defined within the object accessing the data Therefore there is no scope of accidental
modification of data
It is easier to maintain programs The manner in which an object implements its
operations is internal to it Therefore any change within the object would not affect
external objects Therefore systems built using objects are resilient to change
Object reusability which can save many human hours of effort is possible An
application developer can use objects like lsquoarrayrsquo lsquolistrsquo lsquowindowsrsquo lsquomenusrsquo lsquoeventrsquo and
many other components which were developed by other programmers in her program
and thus reduce program development time
It employs bottom-up approach in program design
SUMMARY
OOP is a new way of organizing and developing programs It eliminates many pitfalls of the
conventional programming approach OOP programs are organized around objects which
contain data and functions that operate on that data A class is a template for a number of objects
The object is an instance of a class The major features of OOP are data abstraction data
encapsulation inheritance and polymorphism
Encapsulation is accomplished by using Class - Keeping data and methods that accesses
that data into a single unit
Abstraction is accomplished by using Interface - Just giving the abstract information
about what it can do without specifying the back ground details
InformationData hiding is accomplished by using Modifiers - By keeping the instance
variables private or protected
This new methodology increases programmer productivity delivers better quality of software
and lessens maintenance cost Languages that support several OOP concepts include C++
Smalltalk Object Pascal and Java
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
1048590 Check Your Progress 11) What do you understand by structured programminghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip2) What is the basic idea of Object Oriented approachhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Differentiate between Data abstraction and data hidinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip4) Differentiate between Inheritance and polymorphism
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 2
1) State True or False
a) In the procedure-oriented approach all data are shared by all functions
b) One of the major characteristics of OOP is the division of programs into objects that represent real-
world entities
c) Object Oriented programming language permit reusability of the existing code
d) Data is given a second-class status in procedural programming approach
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
e) OOP languages permit functional as well as data abstraction
2) Does procedure oriented language support the concept of class
helliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip3) Give the reason of accessing data of a class through its functions onlyhelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 Check Your Progress 3
1) State True or False
a) Protecting data from access by unauthorized functions is called data hiding
b) Wrapping up of data of different types and functions into a unit is known as encapsulation
c) Polymorphism can be used in implementing inheritance
d) A Class permits us to build user-defined data types
e) Object Oriented approach cannot be used to create databases
2) Explain the advantage of dynamic bindinghelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
3) Differentiate between object based and object oriented programming languageshelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphelliphellip
1048590 SOLUTIONSANSWERS
Check Your Progress 1
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
1) In structured programming a program is divided into functions or modules and each module has a
clearly defined purpose and a defined interface to the other functions in the program Dividing a program
into functions and modules is one of the major characteristics of structured programming Here we are
least bothered about the data of the problem provided Our main objective is to achieve control of the
execution of program correctly
2) In Object Oriented programming (OOP) the program is organized around the data being operated
upon rather than the operations performed The basic idea behind OOP is to combine both data and its
functions that operate on the data into a single unit called object
3) In data abstraction data structures are used without having to be concerned about the exact details of
implementation This insulation of the data from direct access by the other elements of the program is
known as data hiding It is achieved through classes in OOPs
4) Inheritance is the process by which objects of one class acquire the properties of objects of another
class in the hierarchy By using inheritance new classes can be built from the existing old classes It
means that we can add additional features to an existing class without modifying it This inheritance
mechanism allows the programmer to reuse a class that is almost but not exactly similar to the required
one by adding a few more features to it Polymorphism means the ability to take more than one form with
the same name
Using polymorphism we can have more than one function with the same name but with different
functionalities
Check Your Progress 21) False b) True c) True d) True e) True
2) Yes procedural languages also support the concept of class for example type (data type of the
language) is a class and is supported by procedural languagesYou know C language support several data
types But procedural languages donrsquot support the user-defined class that has data and functions together
3) Accessing data of a class through its functions is in basic philosophy of object orientation If data is not
having restrictive access and open to all the principle of data hiding is violated and emphasis on data get
reduced
Check Your Progress 3
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
1) True b) True c) True d) True e) False
2) It gives option of run-time selection of methods on the basis of current input during execution of
program Dynamic binding allows new objects and code to be interfaced with or added to a system
without affecting existing code
3) Object based languages support the notion of objects Object oriented languages support the concept of class and permit inheritance between classes
1048590 Multiple choiceobjective type questions
1) Which language is not a true object-oriented programming language
a) VBNET
b) VB 6
c) C++
d) C
e) Java
Answer b 2) A GUI
a) uses buttons menus and icons
b) should be easy for a user to manipulate
c) stands for Graphic Use Interaction
d) Both a and b
e) All of the above
Answer d 3) An object is composed of
a) properties
b) methods
c) events
d) Both a and b
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
e) All of the above
Answer e 4) Which statement about objects is true
a) One object is used to create one class
b) One class is used to create one object
c) One object can create many classes
d) One class can create many objects
e) There is no relationship between objects and classes
Answer d5) Which is a numeric data type
a) Floating point
b) Integer
c) Boolean
d) Both a and b
e) All of the above
Answer d
1048590 Exercise
Questions and Answers
1 What is the most important feature of Java
Ans Java is a platform independent language
2 What do you mean by platform independence
Ans Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (LinuxSolarisetc)
3 What is a JVM
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
Ans JVM is Java Virtual Machine which is a run time environment for the compiled java class files
4 Are JVMs platform independent
Ans JVMs are not platform independent JVMs are platform specific run time implementation provided by the vendor
5 What is the difference between a JDK and a JVM
Ans JDK is Java Development Kit which is for development purpose and it includes execution environment also But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM
6 What is a pointer and does Java support pointers
Ans Pointer is a reference handle to a memory location Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers
Answer the following questions
(Questions for short notes)
1 Can a private method of a super class be declared within a subclass
2 Why Java does not support multiple inheritance
3 In Systemoutprintln () what is Systemout and printlnpls explain
4 What is meant by Abstract Interface
5 Why Java does not support pointers
6 What is the main difference between Java platform and other platforms
(Questions for short Answer)
1 What is the base class of all classes
2 Does Java support multiple inheritance
3 Is Java a pure object oriented language
4 Are arrays primitive data types
5 What is difference between Path and Classpath
6 What are local variables
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-
Reference 1 Gosling James A brief history of the Green project[dead link] Javanet no date
[caQ11998] Retrieved April 29 2007
2 Gosling James A brief history of the Green project anonymous-insidernet no date [ca
Q11998] Retrieved September 4 2013
3 Gosling James Joy Bill Steele Guy L Jr Bracha Gilad (2005) The Java Language
Specification (3rd ed) Addison-Wesley ISBN 0-321-24678-0
4 Lindholm Tim Yelling Frank (1999) The Java Virtual Machine Specification (2nd ed)
Addison-Wesley ISBN 0-201-43294-3
5 The History of Java Technology Retrieved October 6 2012
6 Java 50 added several new language features C language Gosling James and
McGilton Henry (May 1996) The Java Language Environment
7 Gosling James Joy Bill Steele Guy and Bracha Gilad The Java Language
Specification 2nd Edition
8 The A-Z of Programming Languages Modula-3 Computerworldcomau Retrieved
2010-06-09
9 Tech Metrix Research (1999) History of Java Java Application Servers Report
ldquoByous Jon (ca 1998)Java technology The early years Sun Developer Network Sun
Microsystems
10 Object-oriented programming The History of Java Technology Sun Developer
Network ca 1995 Retrieved 2010-04-30
11 Java Community Process website Jcporg 2010-05-24 Retrieved 2010-06-09
12 Learn About Java Technology Oracle Retrieved 21 November 2011
- Questions and Answers
-