Lab Programs & Viva Questions:
1.Design a Java
interface for ADT Stack. Develop two different classes that implement this
interface, one using array and the other using linked-list. Provide necessary exception
handling in both the implementations.
ALGORITHM
STEP 1: Create an
interface which consists of three methods namely PUSH, POP and
DISPLAY
STEP 2: Create a
class which implements the above interface to implement the concept
of stack
through Array
STEP 3: Define
all the methods of the interface to push any element, to pop the top
element
and to display the elements present in the stack.
STEP 4: Create
another class which implements the same interface to implement the
concept
of stack through linked list.
STEP 5: Repeat
STEP 4 for the above said class also.
STEP 6: In the
main class, get the choice from the user to choose whether array
implementation
or linked list implementation of the stack.
STEP 7: Call the
methods appropriately according to the choices made by the user in the
previous
step.
STEP 8: Repeat
step 6 and step 7 until the user stops his/her execution
2.Implement a java program to
implement the reflection concept for java.lang.String class
ALGORITHM:
STEP 1: Import
all necessary packages.
STEP 2: create a
class “TestreReflect”
STEP 3: In the
main function use class Class and use
the Class class method forName()
for declaring the class.
for declaring the class.
STEP 4: Use the
Constructors[],Fields[] and Methods[] class for getting information
about the class.
about the class.
STEP 5: Print all
information about the class.
3.Consider a class person with attributes firstname,lastname and personid.Implement a java program to create and clone instances of the Person class.
ALGORITHM:
STEP 1: Import
all necessary packages.
STEP 2: create a
class “CloneTest” which implements Clonable interface
STEP 3: Using
parameterized constructor get the input values specified in the main().
STEP 4: Use
default method
Public
Object clone()
To
return the superv class clone and use exception handling mechanism.
STEP 5: In the
main function,get the input values using scanner class
STEP 6: Create
object for CloneTest class and call methods for it.
STEP 7: Use
typecasting, and create another object for the same class.
STEP 8:Display the
original and cloned variable value.
4.Develop a java interface for implement the multiple inheritance for student mark analysis system.(Define 2 interface-one interface method for reading student basic information(name{String},rollno{int},register number{long},phone num{long},second interface method for reading 5 sub marks{use array} and calculate total,avg).
viva questions:
2.Define marker interface.
3.Write down the syntax for defining interface?
4.What is meant by reflection?
5.What is object cloning? Why it is needed?
6.why do we need static members and how to access them?
7.What is a string buffer class and how does it differs from string class?
8.How to create one dimensional array?
9.What is dynamic binding?
10.What is the difference between static and non-static variables?