Experiment No 1 Aim: Software Used: Theory:: Object Oriented Programming
Experiment No 1 Aim: Software Used: Theory:: Object Oriented Programming
AIM:
THEORY:
Abstraction
Encapsulation
Inheritance
Polymorphism
Abstraction
Abstraction denotes the essential characteristics of an object that distinguish it from all other
kinds of objects and thus provide crisply defined conceptual boundaries, relative to the
perspective of the viewer.
Encapsulation
Inheritance
Inheritance is the process by which one object acquires the properties of another object.
Polymorphism
Polymorphism is the existence of the classes or methods in different forms or single name
denoting different implementations.
Introduction to java :
Earlier java was only used to design and program small computing devices but later adopted
as one of the platform independent programming language and now according to Sun, 3
billion devices run java.
JSP Java is used to create web applications like PHP and ASP, JSP(Java Server
Pages) used with normal HTML tags, which helps to create dynamic web pages.
Applets This is another type of Java program that used within a web page to add
many new features to a web browser.
J2EE The software Java 2 Enterprise Edition are used by various companies to
transfer data based on XML structured documents between one another.
JavaBeans This is something like Visual Basic, a reusable software component that
can be easily assemble to create some new and advanced application.
Mobile Besides the above technology, Java is also used in mobile devices, many
kind of games and services built-in Java. Today, all leading mobile service provider
like Nokia, Siemens, Vodafone are using Java technology.
Loads code
Verifies code
Executes code
Provides runtime environment
Experiment No. 2
Theory :-
1) What is Array?
Normally, array is a collection of similar type of elements that have contiguous
memory location. Java array is an object the contains elements of similar data type. It is a
data structure where we store similar elements. We can store only fixed set of elements in a
java array. Array in java is index based, first element of the array is stored at 0 index.
If we consider the real-world, we can find many objects around us, cars, dogs, humans, etc.
All these objects have a state and a behaviour.If we consider a dog, then its state is - name, breed,
color, and the behaviour is - barking, wagging the tail, running.If you compare the software
object with a real-world object, they have very similar characteristics.
Software objects also have a state and a behaviour. A software object's state is stored
in fields and behaviour is shown via methods.So in software development, methods operate
on the internal state of an object and the object-to-object communication is done via
methods.
4) Array Of Objects
An array of objects is created just like an array of primitive type data items in the following
way :
The above statement creates the array which can hold references to seven Student
objects. It doesn't create the Student objects themselves. They have to be created separately
using the constructor of the Student class. The studentArray contains seven memory spaces in
which the address of seven Student objects may be stored. If we try to access the Student
objects even before creating them, run time errors would occur. For instance, the following
statement throws a NullPointerException during runtime which indicates that studentArray[0]
isn't yet pointing to a Student object.
studentArray[0].marks = 100;
The Student objects have to be instantiated using the constructor of the Student class
and their references should be assigned to the array elements in the following way.
In this way, we create the other Student objects also. If each of the Student objects have
to be created using a different constructor, we use a statement similar to the above several
times. However, in this particular case, we may use a for loop since all Student objects are
created with the same default constructor.
THEORY:
Constructor in java is a special type of method that is used to initialize the object. Java
constructor is invoked at the time of object creation. It constructs the values i.e. provides data
for the object that is why it is known as constructor.
Default constructor:
<class_name>(){}
Paramaterized constructor:
Constructor overloading is a technique in Java in which a class can have any number of
constructors that differ in parameter lists.The compiler differentiates these constructors by
taking into account the number of parameters in the list and their type.
There is no copy constructor in java. But, we can copy the values of one object to another
like copy constructor in C++.
There are many ways to copy the values of one object into another in java. They are:
By constructor
By assigning the values of one object into another
By clone() method of Object class
Super Keyword
Syntax:
super.<method-name>();
return
super.overriden_String_Method();
}
EXPERIMENT NO 4
THEORY:
Inheritance in java is a mechanism in which one object acquires all the properties and
behaviors of parent object.
The idea behind inheritance in java is that you can create new classes that are built upon
existing classes. When you inherit from an existing class, you can reuse methods and fields of
parent class, and you can add new methods and fields also.
The extends keyword indicates that you are making a new class that derives from an existing
class. The meaning of "extends" is to increase the functionality.In the terminology of Java, a
class which is inherited is called parent or super class and the new class is called child or
subclass.Types of inheritance in java
1. Single Inheritance
2. Multilevel Inheritance
3. Hierarchical Inheritance
4. Hybrid Inheritance
Single Inheritance
Single inheritance is damn easy to understand. When a class extends another one class only
then we call it a single inheritance. The below flow diagram shows that class B extends only
one class which is A. Here A is a parent class of B and B would be a child class of A.
Multilevel Inheritance
Multilevel inheritance refers to a mechanism in OO technology where one can inherit from a
derived class, thereby making this derived class the base class for the new class. As you can
see in below flow diagram C is subclass or child class of B and B is a child class of A.
Hierarchical Inheritance
In such kind of inheritance one class is inherited by many sub classes. In below example
class B,C and D inherits the same class A. A is parent class (or base class) of B,C & D.
Hybrid Inheritance
In simple terms you can say that Hybrid inheritance is a combination of Single and Multiple
inheritance. A typical flow diagram would look like below. A hybrid inheritance can be
achieved in the java in a same way as multiple inheritance can be!! Using interfaces. yes you
heard it right. By using interfaces you can have multiple as well as hybrid inheritance in
Java.
EXPERIMENT NO 5
AIM:
THEORY:
Interface in Java
An interface is a blueprint of class. It is a java core part and a way to achieve data abstraction
in Java along with abstract class. Since multiple inheritance is not allowed in Java, interface is
only way to implement multiple inheritance. At in basic level interface in java is a keyword
but that time it is an object oriented term to define contracts and abstraction, This contract is
followed by any implementation of Interface in Java.
Defining Interfaces:
}
Where, Access-specifier is either public or it is not given.When no access specifier is used, it
results into default access specifier and if interface has default access specifier then it is only
available to other members of the same package.When it is declared as public, the interface
can be used by any other code of other package.
The methods which are declared having no bodies they end with a semicolon after the
parameter list. Actually they are abstract methods;Any class that includes an interface must
implement all of the methods. Variables can be declared inside interface declarations.They
are implicitly final and static, means they can not be changed by implementing it in a class.
Once an interface has been defined, one or more classes can implement that interface.To
implement an interface, include the implements clause in a class definition, and then create
the methods declared by the interface.
The general form of a class that includes the implements clause looks like this:
// class body
If a class implements from more than one interface, names are separated by comma.If a class
implements two interfaces that declare the same method, then the same method will be used
by clients of either interface.