If you have any queries please leave a message here
Your Message

Question 1 :

a) What is Object Oriented Programming? Explain advantages of Object Oriented Programming with the help of an example.

Answer : - Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts :

Advantage of Object Oriented Programming System (OOPs) -

b) Explain features of java programming language.

Answer : - The primary objective of Java programming language creation was to make it portable, simple and secure programming language. Apart from this, there are also some excellent features which play an important role in the popularity of this language.

A list of most important features of Java language is given below.

c) Write a program to explain use of Relational and Boolean operators in java.

Answer : -

Relational Operators - Relational operators in Java programming are mostly used either in If Conditions or Loops. Java Relational operators are commonly used to check the relationship between two variables.

The Relational Operators in Java Programming show in the table given below :

greater than
less than
greater than or equal to
less than or equal to
equal to
not equal to

public class RelationalOperators
public static void main(String args[])
int a=20, b=10;
System.out.println("Result of (a > b) is = "(a > b));
System.out.println("Result of (a < b) is = "(a < b));
System.out.println("Result of (a >= b) is = "(a >= b));
System.out.println("Result of (a <= b) is = "(a <= b));
System.out.println("Result of (a == b) is = "(a == b));
System.out.println("Result of (a != b) is = "(a != b));

Output :

Result of (a > b) is = true
Result of (a < b) is = false
Result of (a >= b) is = true
Result of (a <= b) is = false
Result of (a == b) is = false
Result of (a != b) is = true

Boolean Operators - The Boolean logical operators operates only on boolean operands. All of the binary logical operators combine two boolean values to form a resultant boolean value.

Logical AND
Logical OR
Logical XOR (exclusive OR)
Short-circuit AND
Short-circuit OR
Logical unary NOT

Question 2 :

a) Explain use of super and final keywords in java with the help of examples.

Answer : -

super Keyword - We can use super keyword to access the data member and methods of parent class. It is used if parent class and child class have same methods or variables.

//Parent Class
class Base
int fact;
void Factorial(int n)
for(int i=1;i<=n;i++)

//Child Class
class Derived extends Base
void Factorial(int n)
//Call the Overriding Method of Parent Class
System.out.println("Factorial = "+super.fact);

final Keyword

class Speed
//final variable
final int speedlimit=90;
void run()
public static void main(String args[])
Speed obj=new Speed();;

Output : Compile Time Error

b) Explain followings in context of java, with the help of examples.

Answer : -

i. Class and Objects

class Student
int id;
String name;

class TestStudent
public static void main(String args[])
Student s1=new Student();;"Debabrata";
//printing members with a white space
System.out.println(" ";

ii. Message Passing - JMS (Java Message Service) is an API that provides the facility to create, send and read messages. Messaging is a technique to communicate applications or software components. JMS is mainly used to send and receive message from one application to another.

Generally, user sends message to application. But, if we want to send message from one application to another, we need to use JMS API. Consider a scenario, one application A is running in INDIA and another application B is running in USA. To send message from A application to B, we need to use JMS.

iii. Garbage collection - In java, garbage means unreferenced objects.

Garbage Collection is process of reclaiming the runtime unused memory automatically. In other words, it is a way to destroy the unused objects. To do so, we were using free( ) function in C language and delete( ) in C++. But, in java it is performed automatically. So, java provides better memory management.

Advantage of Garbage Collection

An object be unreferenced in many ways

Simple Example of garbage collection in java

public class GarbageCollection
public void finalize()
System.out.println("object is garbage collected");
public static void main(String args[])
GarbageCollection s1=new GarbageCollection();
GarbageCollection s2=new GarbageCollection();

The finalize( ) method is invoked each time before the object is garbage collected. This method can be used to perform cleanup processing.

The gc( ) method is used to invoke the garbage collector to perform cleanup processing. The gc( ) is found in System and Runtime classes.

Question 3 :

a) What is static method? Explain why main method in java is always static.

Answer : -

In core Java program, execution starts from main method when you type java main-class-name, JVM search for public static void main(String args[ ]) method in that class and if it doesn't find that method it throws error NoSuchMethodError:main and terminates.

b) What is inheritance? How inheritance is implemented in java? Create a class Book and define display method to display book information. Inherit Reference_Book and Magazine classes from Book class and override display method of Book class in Reference_Book and Magazine classes. Make necessary assumptions required.

Answer : - Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a 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 the parent class. Moreover, you can add new methods and fields in your current class also.

Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class.

Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class.

class Book
void display()
System.out.println("Name - The Complete Reference Java 2");
System.out.println("Author - Herbert Schildt");

class Reference_Book extends Book
void display()
System.out.println("Name - Pure Java 2");
System.out.println("Author - Kenneth Litwak");

class Magazine extends Book
void display()
System.out.println("Name - Core Java");
System.out.println("Author - Cay S. Horstmann");

class TestInheritance
public static void main(String args[])
Book b;
b=new Book();
b=new Reference_Book();
b=new Magazine();

c) Explain the steps involved in creating a distributed application using Remote Method Invocation (RMI).

Answer : - The RMI (Remote Method Invocation) is an API that provides a mechanism to create distributed application in java. The RMI allows an object to invoke methods on an object running in another JVM.

The RMI provides remote communication between the applications using two objects stub and skeleton. RMI uses stub and skeleton object for communication with the remote object. A remote object is an object whose method can be invoked from another JVM.

Understanding requirements for the Distributed Applications

If any application performs these tasks, it can be distributed application.

The RMI application have all these features, so it is called the distributed application.

Question 4 :

a) What is polymorphism? Explain its advantages with the help of a program.

Answer : - Polymorphism in Java is a concept by which we can perform a single action in different ways. Polymorphism is derived from 2 Greek words : poly and morphs. The word "poly" means many and "morphs" means forms. So polymorphism means many forms.

There are two types of polymorphism in Java: compile-time polymorphism and runtime polymorphism. We can perform polymorphism in java by method overloading and method overriding.

If you overload a static method in Java, it is the example of compile time polymorphism.

Runtime polymorphism or Dynamic Method Dispatch is a process in which a call to an overridden method is resolved at runtime rather than compile-time.

Example of Polymorphism

class Bank
float getRateOfInterest() { return 0; }

class SBI extends Bank
float getRateOfInterest() { return 6.2f; }

class ICICI extends Bank
float getRateOfInterest() { return 7.2f; }

class AXIS extends Bank
float getRateOfInterest() { return 6.5f; }

class TestPolymorphism
public static void main(String args[])
Bank b;
b=new SBI();
System.out.println("SBI Rate of Interest: "+b.getRateOfInterest());
b=new ICICI();
System.out.println("ICICI Rate of Interest: "+b.getRateOfInterest());
b=new AXIS();
System.out.println("AXIS Rate of Interest: "+b.getRateOfInterest());

b) What is constructor overloading? Explain advantage of constructor overloading with the help of an example.

Answer : - In Java, a constructor is a block of codes similar to the method. It is called when an instance of the object is created, and memory is allocated for the object. It is a special type of method which is used to initialize the object.

In Java, a constructor is just like a method but without return type. It can also be overloaded like Java methods.

Constructor overloading in Java is a technique of having more than one constructor with different parameter lists. They are arranged in a way that each constructor performs a different task. They are differentiated by the compiler by the number of parameters in the list and their types.

Example of Constructor Overloading

class Employee
int emp_id;
String emp_name;
long emp_phone;

//creating two argument constructor
Employee(int id, String name)
emp_id = id;
emp_name = name;

//creating three argument constructor
Employee(int id, String name, int phone)
emp_id = id;
emp_name = name;

void display()
System.out.println(emp_id+" "+emp_name+" "+emp_phone);

public static void main(String args[])
Employee e1 = new Employee(10,"Debabrata");
Employee e2 = new Employee(20,"Rahul",9073919231);

c) What is rule of accessibility? Explain different level of accessibility in java.

Answer : - The access modifiers in java specifies accessibility (scope) of a data member, method, constructor or class. There are 4 types of java access modifiers :

Within same classYesYesYesYes
Within other class of same packageNoYesYesYes
Within derived class of other packageNoNoYesYes
Within external class of other packageNoNoNoYes

Question 5 :

a) What is abstract class? Explain situations in which abstract classes are used.

Answer : - A class that is declared with abstract keyword, is known as abstract class in java. It can have abstract and non-abstract methods (method with body).

Abstract Method

Method that are declared without any body within an abstract class are called abstract method. The method body will be defined by its subclass. Abstract method can never be final and static. Any class that extends an abstract class must implement all the abstract methods declared by the super class.

Abstraction in Java

Abstraction is a process of hiding the implementation details and showing only functionality to the user.

Another way, it shows only important things to the user and hides the internal details. For example sending sms, you just type the text and send the message. You don't know the internal processing about the message delivery.

Abstraction lets you focus on what the object does instead of how it does.

There are two ways to achieve abstraction in Java

  1. Abstract class (0 to 100%)
  2. Interface (100%)

b) What is an exception? Explain how an exception is handled in Java. Create your own exception class to handle a situation when age of a person is given in negative. Make necessary assumptions.

Answer : - Exceptions are events that occur during the execution of programs that distrup the normal flow of instructions (example - divide by zero, array access out of bound, etc.).

In Java, an exception is an object that wraps an error event that occurred within a method and contains :

Exception objects can be thrown and caught.

Exception Handling in Java

There are 5 keywords which are used in handling exceptions in Java.

tryThe "try" keyword is used to specify a block where we should place exception code. The try block must be followed by either catch or finally. It means, we can't use try block alone.
catchThe "catch" block is used to handle the exception. It must be preceded by try block which means we can't use catch block alone. It can be followed by finally block later.
finallyThe "finally" block is used to execute the important code of the program. It is executed whether an exception is handled or not.
throwThe "throw" keyword is used to throw an exception.
throwsThe "throws" keyword is used to declare exceptions. It doesn't throw an exception. It specifies that there may occur an exception in the method. It is always used with method signature.

Create Custom Exception in Java

class InvalidAgeException extends Exception
InvalidAgeException(String s)

class TestCustomException
static void validate(int age)throws InvalidAgeException
if(age < 0)
throw new InvalidAgeException("Negative value not allow");
public static void main(String args[])
catch(Exception e)
System.out.println("Rest of the code...");

Output :

InvalidAgeException:Negative value not allow
Rest of the code . . .

c) Explain how threads are created in java. Write a java program to display threads priority.

Answer : - A thread is a lightweight sub-process, the smallest unit of processing. There are two ways to create a thread :

Commonly used Constructors of Thread class :

Each thread have a priority. Priorities are represented by a number between 1 and 10. In most cases, thread schedular schedules the threads according to their priority (known as preemptive scheduling). But it is not guaranteed because it depends on JVM specification that which scheduling it chooses.

3 constants defined in Thread class :

Default priority of a thread is 5 (NORM_PRIORITY). The value of MIN_PRIORITY is 1 and the value of MAX_PRIORITY is 10.

Example of priority of a Thread

class TestMultiPriority extends Thread
public void run()
System.out.println("running thread name : "+Thread.currentThread().getName());
System.out.println("running thread priority : "+Thread.currentThread().getPriority());
public static void main(String args[])
TestMultiPriority p1=new TestMultiPriority();
TestMultiPriority p2=new TestMultiPriority();

Output :

running thread name : Thread-0
running thread priority : 10
running thread name : Thread-1
running thread priority : 1

Question 6 :

a) What is I/O stream in java? Write a program in java to create a file and copy the content of an already existing file into it.

Answer : - An I/O Stream represents an input source or an output destination. A stream can represent many different kinds of sources and destinations, including disk files, devices, other programs, and memory arrays.

Streams support many different kinds of data, including simple bytes, primitive data types, localized characters, and objects. Some streams simply pass on data; others manipulate and transform the data in useful ways.

There are two types of streams :

Copy the Content of a File into another File

class CopyFile
public static void main(String args[])throws IOException
FileInputStream Fread =new FileInputStream("File1.txt");
FileOutputStream Fwrite=new FileOutputStream("File2.txt");
int c;
while(( != -1)
System.out.println("File is Copied");

b) Create an Applet program to display your brief profile with photograph. Make necessary assumptions and use appropriate GUI and layout in your program.

Answer : -

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Profile extends Applet
Image picture;
public void init()
picture = getImage(getDocumentBase(),"img167405892.jpg");
public void paint(Graphics g)
g.drawString("Enrolment No.", 10, 20);
g.drawString("Name", 10, 40);
g.drawString("Address", 10, 60);
g.drawString("E-mail", 10, 80);
g.drawString("Phone", 10, 100);
g.drawString("Date-of-Birth", 10, 120);
g.drawString("Gender", 10, 140);
g.drawString("Nationality", 10, 160);
g.drawString(": 167405892", 100, 20);
g.drawString(": Debabrata Panchadhyay", 100, 40);
g.drawString(": 12/18 Padmapukur Road, Kolkata-700092", 100, 60);
g.drawString(":", 100, 80);
g.drawString(": 9073919231", 100, 100);
g.drawString(": 26-Aug-2018", 100, 120);
g.drawString(": Male", 100, 140);
g.drawString(": Indian", 100, 160);
g.drawImage(picture, 350, 10, 120, 150, this);

c) Differentiate between String and StringBuffer classes. Also write a program to reverse a given string.

Answer : -

String is slow and consumes more memory when you concat too many strings because every time it creates new instance.StringBuffer is fast and consumes less memory when you cancat strings.
String class overrides the equals() method of Object class. So you can compare the contents of two strings by equals() method.StringBuffer class doesn't override the equals() method of Object class.

String Reverse

import java.util.*;
class ReverseString
public static void main(String args[])
String original, reverse = "";
Scanner in = new Scanner(;
System.out.println("Enter a string to reverse...");
original = in.nextLine();
int length = original.length();
for (int i = length - 1 ; i >= 0 ; i--)
reverse = reverse + original.charAt(i);
System.out.println("Reverse of the string : " + reverse);

Question 7 :

a) What is need of layout manager? Explain different layouts available in java for GUI programming.

Answer : - The LayoutManagers are used to arrange components in a particular manner. LayoutManager is an interface that is implemented by all the classes of layout managers. There are following classes that represents the layout managers :

b) Explain FilterInputStream and FilterOutputStream in detail.

Answer : -

FilterInputStream - Java FilterInputStream class implements the InputStream. It contains different sub classes as BufferedInputStream, DataInputStream for providing additional functionality. So it is less used individually.

declaration for class -
public class FilterInputStream extends InputStream

Java FilterInputStream class Methods

int available( )It is used to return an estimate number of bytes that can be read from the input stream.
int read( )It is used to read the next byte of data from the input stream.
int read(byte[ ] b)It is used to read up to b.length bytes of data from the input stream.
long skip(long n)It is used to skip over and discards n bytes of data from the input stream.
boolean markSupported( )It is used to test if the input stream support mark and reset method.
void mark(int readlimit)It is used to mark the current position in the input stream.
void reset( )It is used to reset the input stream.
void close( )It is used to close the input stream.

FilterOutputStream - Java FilterOutputStream class implements the OutputStream class. It provides different sub classes such as BufferedOutputStream and DataOutputStream to provide additional functionality. So it is less used individually.

declaration for class
public class FilterOutputStream extends OutputStream

Java FilterOutputStream class Methods

void write(int b)It is used to write the specified byte to the output stream.
void write(byte[ ] b)It is used to write b.length byte to the output stream.
void write(byte[ ] b, int off, int len)It is used to write len bytes from the offset off to the output stream.
void flush( )It is used to flushes the output stream.
void close( )It is used to close the output stream.

c) Explain File class and its methods.

Answer : - The File class is an abstract representation of file and directory pathname. A pathname can be either absolute or relative.

The File class have several methods for working with directories and files such as creating new directories or files, deleting and renaming directories or files, listing the contents of a directory etc.


File(File parent, String child)This constructor creates a new File instance from a parent abstract pathname and a child pathname string.
File(String pathname)This constructor creates a new File instance by converting the given pathname string into an abstract pathname.
File(String parent, String child)This constructor creates a new File instance from a parent pathname string and a child pathname string.
File(URI uri)This constructor creates a new File instance by converting the given file: URI into an abstract pathname.

Useful Methods

public String getName( )Returns the name of the file or directory denoted by this abstract pathname.
public String getParent( )Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.
public boolean canRead( )It tests whether the application can read the file denoted by this abstract pathname.
public boolean canWrite( )It tests whether the application can modify the file denoted by this abstract pathname.
public boolean canExecute( )It tests whether the application can execute the file denoted by this abstract pathname.
public boolean mkdir( )It creates the directory named by this abstract pathname.
public boolean isDirectory( )It tests whether the file denoted by this abstract pathname is a directory.
public boolean isFile( )It tests whether the file denoted by this abstract pathname is a normal file.
public File[ ] listFiles( )It returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.
public File[ ] listFiles(FileFilter filter)It returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
public boolean createNewFile( ) throws IOExceptionIt atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.
public static File createTempFile(String prefix, String suffix) throws IOExceptionIt creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.
public static File createTempFile(String prefix, String suffix, File directory) throws IOExceptionIt creates an empty file in the specified directory, using the given prefix and suffix strings to generate its name.

Question 8 :

a) Explain UDP in context of java programming.

Answer : -

b) Explain different ways of session handling.

Answer : - Session is a conversional state between client and server and it can consists of multiple request and response between client and server. Since HTTP and Web Server both are stateless, the only way to maintain a session is when some unique information about the session (session id) is passed between server and client in every request and response.

There are several ways through which we can provide unique identifier in request and response.

c) What is JDBC? Explain how select statements are executed and ResultSet are accessed in JDBC programming.

Answer : - JDBC stands for Java Database Connectivity. JDBC is a Java API to connect and execute the query with the database. It is a part of JavaSE (Java Standard Edition). JDBC API uses JDBC drivers to connect with the database. There are four types of JDBC drivers :

Example of SQL select Query

import java.sql.*;
import oracle.jdbc.driver.*;
public class ShowEmployeeDetails
public static void main(String args[])
// Oracle Database Connection
String url="jdbc:oracle:thin:@localhost:1521:xe";
String user="Admin";
String password="Admin1234";
Connection con=DriverManager.getConnection(url,user,password);

// Query Execution
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT * FROM employee");
catch(Exception e)

ABOUT US is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, provides solutions to your questions and assignments also.


Windows Command

UNIX Command

IGNOU Assignment Solution

IGNOU Question Paper Solution

Solutions of Different Questions


Website Devlopment


Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


Follow Us