Вы находитесь на странице: 1из 4

PRAGATI ENGINEERING COLLEGE

# 1-378, ADB Road, Surampalem, E.G.Dist., A.P. – 533 437


(Approved by AICTE, New Delhi & Affiliated to JNT University, Kakinada)
Ph: (08852) – 252233, 252234, 252235 ,Fax: (08852) – 252232
(Sponsored by Gayatri Educational Society, Kakinada)

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


2015-2016 II Year II Semester CSE Branch
STUDY MATERIAL
UNIT I – Object Oriented Programming
[ Part – A ]
1 Q) Explain the importance of Object-oriented programming languages? [4 M]
Answer:-
Object oriented programming (OOP) is one of the most interesting and useful innovations
in software development. OOP has strong historical roots in programming paradigms and
practices.
In the physical world, we deal with objects like person, plane, or car. Such objects are not
like data and functions. In the complex real-world situations, we have objects which have some
attributes and behavior. We deal with similar objects in OOP. Objects are defined by their unique
identity, state and behavior. The state of an object is identified by the value of its attributes and
behavior by methods.
Attributes :
Attributes define the data for an object. Every object has some attributes. Different types
of objects contain different attributes or characteristics. For example, the attributes of a student
object are name, roll number and subject, etc.,
Behaviour:
The response of an object when subjected to stimulation is called its behavior. Behavior
defines what can be done with the objects and may manipulate the attributes of an object. For
example, if a manager orders an employee to do some task, then he responds either by doing it or
not doing it. Behavior actually determines the way an object interacts with other objects. We can
say that behavior is synonym to functions or methods: we call a function to perform some task.
2 Q) Explain the difference between class and object. [4 M]
Answer:-
Classes :
A class is defined as the blue print for an object. It serves as a plan or a template. The
description of a number of similar objects is also called a class. An object is not created by just
defining a class. It has to be created explicitly. Classes are logical in nature. For example,
furniture does not have any existence but tables and chairs do exist. A class is also defined as a
new data type, a user defined type which contains two things: data members and methods.
Objects :
Objects are defined as the instances of a class. Objects of a class will have same attributes
and behavior which are defined in that class. The only difference between objects would be the
value of attributes, which may vary.
Objects can be physical , conceptual, or software. Objects have unique identity, state, and
behavior. There may be several types of objects :
 Creator objects : Humans, Employees, Students, Animals
 Physical Objects: Car, Bus, Plane
 Objects in computer system: Monitor, Keyboard, Mouse, CPU, Memory
PRAGATI ENGINEERING COLLEGE
# 1-378, ADB Road, Surampalem, E.G.Dist., A.P. – 533 437
(Approved by AICTE, New Delhi & Affiliated to JNT University, Kakinada)
Ph: (08852) – 252233, 252234, 252235 ,Fax: (08852) – 252232
(Sponsored by Gayatri Educational Society, Kakinada)

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


3 Q) Differentiate between procedural languages and OOP languages? [4 M]
Answer:-
Procedural Language Object oriented Programming
Separate data from functions that operate on
Encapsulate data and methods in a class
them.
Not suitable for defining abstract types Suitable for defining abstract types.
Debugging is difficult Debugging is easier
Not suitable for larger programs and Suitable for larger programs and
applications applications
Analysis and design not so easy Analysis and design made easier
Less Flexible More Flexible
Data and procedure based Object oriented based
Less reusable More reusable
Inheritance, encapsulation and
Only data and procedures are there
polymorphism are the key features.
Use top-down approach Use bottom-up approach
Only a function call another. Object communication is there
Example: C,Basic, FORTRAN Example: Java, C++, VB.NET, C#.NET

4 Q) Differentiate between runtime and compile-time polymorphism


[4 M]
Answer:-
In programming, polymorphism is of two types: compile-time and runtime polymorphism.
Runtime polymorphism also known as dynamic binding or late binding, is used to determine
which method to invoke at runtime. The binding of method call to its method is done at runtime
and hence the term late binding is used. In case of compile time polymorphism, the compiler
determines which method ( from all the overloaded methods) will be executed. The binding of
method call to the method is done at compile time. So the decision is made early and hence the
term early binding. Compile-time polymorphism in Java is implemented by overloading and
runtime polymorphism by overriding. In overloading , a method has the same name with
different signatures. In overriding, a method is defined in subclass with the same name and same
signature as that of parent class. This distinction between compile-time and runtime
polymorphism is of method invocation.

5 Q) Why is Java known to be multithreading ? How does it help Java in its performance
[4 M]
Answer:-
This can be explained well with the help of an example:
Consider a four-gas burner on which food is cooked. The cook, in order to save time, puts
milk to boil on one gas burner, rice on the other, makes chapattis on the third, and vegetable on
the fourth. The cook switches between all the items to be cooked so that neither of the items are
red-heated to lose their taste. He may lower/brighten up the gas as and when required. Here the
cook is the processor and the four items being cooked are threads. The processor (cook) switches
from one thread to another.
PRAGATI ENGINEERING COLLEGE
# 1-378, ADB Road, Surampalem, E.G.Dist., A.P. – 533 437
(Approved by AICTE, New Delhi & Affiliated to JNT University, Kakinada)
Ph: (08852) – 252233, 252234, 252235 ,Fax: (08852) – 252232
(Sponsored by Gayatri Educational Society, Kakinada)

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


A thread can be loosely defined as a separate stream of execution that takes place
simultaneously and independent of everything else that might be happening. Threads are
independent parts of a process that run concurrently. Using threads, a program cannot hold the
CPU for a long duration intentionally. The beauty of multithreading is that the other tasks that
are not stuck in the loop can continue processing without having to wait for the struck task to
finish. Threads in Java can place locks on shared resources so that while one thread is using it,
no other thread is allowed to access it. This is achieved with the help of synchronization.

6 Q) Discuss the tools available in JDK. How do they help in application development? [4
M]
Answer:-
TOOLS in JDK :
The tools available in JDK are split into the following categories :
 Basic tools ( javac, java, javadoc, apt, appletviewer, jar, jdb, javah, javap, extcheck )
 Security tools ( keytool, jarsigner, policytool, kinit, klist, ktab )
 Internationalization tools ( native2ascii )
 Remote Method Invocation (RMI ) tools ( rmic, rmiregistry, rmid, serialver )
 JAVA IDL and RMI-IIOP tools ( tnameserv, idlj, ordb, servertool )
 Java deployment tools ( pack200, unpack200 )
 Java plug-in tools ( html converter )
 Java Web start tools ( javaws )
 Java Monitoring and Management Console ( jconsole )
 Java Web services tools ( schemagen, wsgen, wsimport, xjc )

[ Part – B ]

7 Q) what is the importance of setting environment variables such as Path and Classpath?
[8 M]
Answer:-
It is not possible to run a Java program without modifying system environment variables ( such as
path and classpath ) or modifying the autoexec.bat.
Why to set Path variable?
The PATH environment variables needs to be set if you want to run the executables (
javac.exe, java.exe, javadoc.exe, etc) from any directory. If you want to find out the current value
of your PATH, then type the following at the DOS prompt:
C:\> path
Windows NT/XP/Vista/7 : It is preferable to make the following environment variables changes
in the Control Panel instead of the autoexec.bat file. Start the Control Panel, Select System, and
the edit the environment variables. In case of other recent versions of Windows, right click on the
MyComputer icon and select Properties, click on Environment. The System Properties window
appears. Select Path from the list of system variables and append the following path to existing
path : C:\PROGRAM FILES\JAVA\JDK.1.7\bin ( complete path of \bin ).
PRAGATI ENGINEERING COLLEGE
# 1-378, ADB Road, Surampalem, E.G.Dist., A.P. – 533 437
(Approved by AICTE, New Delhi & Affiliated to JNT University, Kakinada)
Ph: (08852) – 252233, 252234, 252235 ,Fax: (08852) – 252232
(Sponsored by Gayatri Educational Society, Kakinada)

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


Classpath --- What it does?
The classpath tells the JVM and other Java applications where to find the class libraries
and user-defined classes. You need to set the classpath for locating class libraries, user-defined
classes and packages.
Setting the Classpath :
The same procedure can be followed for setting the classpath environment variable with
the exception that now you will not look for the path variable but for the classpath variable.

8 Q) Write short notes on:


a) Inheritance b) Polymorphism c) Encapsulation? [8 M]
Answer:-
a) Inheritance :
Inheritance is the way to adopt the characteristics of one class into another class. Here we
have two types of classes : base class and sub class. There exists a parent-child relationship
among the classes. When a class inherits another class, it has all the properties of the base
class and it adds some new properties of its own. We can categorize vehicles into car, bus,
bike , ships, planes etc.,
The principle of dividing a class into subclass is that each subclass shares common
characteristics with the class from where they are inherited or derived. Cars, scooters, planes
and ships all have an engine and a speedometer. These are the characteristics of vehicles.
Inheritance aids in reusability. When we create a class, it can be distributed to other
programmers which they can use in their programs. This is called reusability.
b) Polymorphism:
Polymorphism simple means many forms. It can be defined as the same thing being used in
different forms. For example, there are certain bacteria that exhibit in more than one morphological
form. In programming, polymorphism is of two types : compile-time and run time polymorphism.
c) Encapsulation

Encapsulation is one of the features of object-oriented methodology. The process of binding


the data procedures into objects to hide them from the outside world is called Encapsulation.
It provides us the power to restrict anyone from directly altering the data. Encapsulation
is also known as data hiding. An access to the data has to be through the methods of the
class. The data is hidden from the outside world and as a result, it is protected. The details
that are not useful for the other objects should be hidden from them. This is called
encapsulation.

Вам также может понравиться