0% found this document useful (0 votes)
81 views

It - 506 - Advanced Java Lab Manual Updated

Here are the key points about queues in Java: - A queue is a First In First Out (FIFO) data structure - elements are removed from the queue in the same order they are added. - The Queue interface in Java extends the Collection interface and defines additional insertion (add/offer) and removal (remove/poll) operations. - Common queue implementations are LinkedList and PriorityQueue. - Elements can be added to the queue using add() or offer(). These methods return a boolean and may throw exceptions. - Elements can be removed from the queue using remove() or poll(). Remove() throws an exception if the queue is empty, while poll() returns null. - We can check if

Uploaded by

Chandni Sikarwar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

It - 506 - Advanced Java Lab Manual Updated

Here are the key points about queues in Java: - A queue is a First In First Out (FIFO) data structure - elements are removed from the queue in the same order they are added. - The Queue interface in Java extends the Collection interface and defines additional insertion (add/offer) and removal (remove/poll) operations. - Common queue implementations are LinkedList and PriorityQueue. - Elements can be added to the queue using add() or offer(). These methods return a boolean and may throw exceptions. - Elements can be removed from the queue using remove() or poll(). Remove() throws an exception if the queue is empty, while poll() returns null. - We can check if

Uploaded by

Chandni Sikarwar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

DEPARTMENT OF

INFORMATION TECHNOLOGY

LAB MANUAL

Name of Student : …………………..

Name of Lab : Advanced Java Lab

Subject Code : IT- 506

Branch : Information Technology

Year/Sem : III/V

Affiliated to Rajiv Gandhi Prodyogiki Vishwavidyalaya, Bhopal (MP)


INDEX
S. Name of Experiment Date Sign Remark
No.
1. Write a program to show the concept of Exception handling.
2. Write a program to create array list in collection , add, remove ,
check , & specified index of elements from the given list.
3. Write a java program to iterate through all elements in a hash list.
4. Write a java program to create a queue, add some colors & print
out the elements of the queue.
5. Write a program to show the concept of Map in collection.
6. Study of JDBC & its drivers.
7 Write the steps for database Connectivity & Implement a java
programs to access database using JDBC
8 Implement Login page using Servlet .
9 Implement Registration page using JSP.
10 Study the following: 1. RMI. 2. MVC Architecture.
List of Experiments
Advanced Java Lab (IT- 506)

1. Write a program to show the concept of Exception handling.


2. Write a program to create array list in collection , add, remove , check , & specified index of
elements from the given list.
3. Write a java program to iterate through all elements in a hash list.Create a web Page using Servlet.
4. Write a java program to create a queue, add some colors & print out the elements of the queue.
5. Write a program to show the concept of Map in collection.
6. Study of JDBC & its drivers.
7. Write the steps for database Connectivity & Implement a java programs to access database using
JDBC.
8. Implement Login page using Servlet .
9. Implement Registration page using JSP.
10. Study the following: 1. RMI. 2. MVC Architecture.
Lab Manual
Java Lab

Total number of
Experiments: 10
Total number of
Turns: 14

S. Name of Experiment Turns


No. needed to
complete

1. Write a program to show the concept of Exception handling. 1

2. Write a program to create array list in collection , add, remove , check , & specified 2
index of elements from the given list.
3. Write a java program to iterate through all elements in a hash list. 1

4. Write a java program to create a queue, add some colors & print out the elements of 1
the queue.
5 Write a program to show the concept of Map in collection. 1

6 Study of JDBC & its drivers. 1

7 Write the steps for database Connectivity & Implement a java programs to access 2
database using JDBC
8 Implement Login page using Servlet . 2

9 Implement Registration page using JSP. 2

10 Study the following: 1. RMI. 2. MVC Architecture. 1


EXPERIMENT NO.1
Unit/Topic: 1/Exception Handling

PROBLEM DEFINITION:
Write a program to show the concept of Exception handling.

OBJECTIVE:
To understand the concept of Exception handling.

THEORY:
Attached here with.

INPUT SET:

OUTPUT SET:
Attached.

EXPECTED VIVA QUESTIONS:


Q.1 What is Exception handling?
Q.2 What are the keywords in Exception handling?

NAME OF FACULTY: Prof. Priyanka Maheshwari


SIGNATURE:
DATE:
Exception Handling:

1. Exceptional(that is error) condition that has occurred in a piece of code of java program.

2. It will cause abnormal termination of program or wrong execution result.

3. Java provides an exception handling mechanism to handle exceptions.

4. Exception handling will improve the reliability of application program.

5. Java creates different type of objects in case of different exceptional conditions that describe the cause of
execution.

6. Treat exception as an object.

7. All exceptions are instances of a class extended from Throwable class or its subclass.

8. Generally, a programmer can make new exception by extending the Exception class which is subclass of
Throwable class.

9. Exception handling is managed by five keywords: try,catch, throw, throws and finally.

10. Exception can be generated by :

a. Java “run-time system” are called System-generated exceptions. It is automatically raised by java run-time
system.

b. Your code are called Programmatic Exceptions. It is raised by Throw keyword.

11. Handling is done with help of try-catch-finally block.

12. Exception raised in try block is caught by catch block.

13. Block finally is optional and always executed.

Exception Types:

Error Class: Abnormal conditions those can not be handled are called Errors.

Exception Class: Abnormal conditions those can be handled are called Exceptions.

Java Exception Class Hierarchy:


Checked Exception: try-catch block is mandatory.
Unchecked Exception: try- catch block is optional.
Program 1:
import java.util. Scanner;
class Division{
public static void main (String[] args){
int a,b,result;
Scanner sc=new Scanner(System.in);
System.out.println("Enter input two integers");
a=sc.nextInt();
b=sc.nextInt();
result =a/b;
System.out.println("Result=" +result);
}
}
Output:

Program 2:
import java.util. Scanner;
class Division{
public static void main (String[] args){
int a,b,result;
Scanner sc=new Scanner(System.in);
System.out.println("Enter input two integers");
a=sc.nextInt();
b=sc.nextInt();
try{
result =a/b;
System.out.println("Result=" +result);
}
catch(ArithmeticException e) {
System.out.println("Exception caught: Division by zero.");
}
}
}
Output:

Program 3:
class Exceptions{
public static void main(String[] args)
{
String languages[]={"C", "C++", "Java", "PHP","Python"};
try{
for(int i=1; i<=5; i++){
System.out.println(languages[i]);
}
}
catch (Exception e){
System.out.println(e);
}
}
}
Output:
Program 4:
/*Finally block is always executed , whether an exception is Thrown or not*/
class Allocate{
public static void main(String[] args){
try{
long data[]=new long[1000000000];
}
catch (Exception e){
System.out.println(e);
}
finally{
System.out.println("Block finally always execute.");
}
}
}
Output:
EXPERIMENT NO.2
Unit/Topic: 2/Collections

PROBLEM DEFINITION:
Write a program to create array list in collection , add, remove , check , & specified index of elements from
the given list.

OBJECTIVE:
To understand the concept of Collection Framework.

THEORY:
Attached here with.

INPUT SET:

OUTPUT SET:
Attached.

EXPECTED VIVA QUESTIONS:


Q.1 What is collections?
Q.2 Compare Collections Vs Collection.

NAME OF FACULTY: Prof. Priyanka Maheshwari


SIGNATURE:
DATE:
Collections in java:
 In traditional world there are so many examples i.e. coin collection, Postoffice ticket collection , Favourite car
collection (Mukesh Ambani) etc.
 Anitque collection : collection of diiferent type of objects /same type of objects.
 Java Is OOP (Object Oriented Programming), Basic unit of Java Is object.
 Collection: It is a collection of Objects.
 Java Collection framework provides many interfaces(Set, List, Queue,Deque) and classes (Arraylist,
Vector,LinkedList, PriorityQueue,HashSet,LinkedHashSet,TreeSet).
 Collection can Store different types of objects (Integer, Double, String, Boolean, Any).
Program:
import java.util.ArrayList;
public class TestArraylist2{
public static void main(String[] args){
ArrayList list=new ArrayList();
list.add(10);
list.add(20.5);
list.add("Ram");
list.add("true");
int i=(int)list.get(0);
double d=(double)list.get(1);
String s=(String)list.get(2);
System.out.println(i);
System.out.println(d);
System.out.println(s);
boolean flag=list.contains("Ram");
System.out.println(flag);
int ind=list.indexOf("Ram");
System.out.println("index of Ram: " +ind);
list.set(2,"Shyam");
String r=(String)list. remove(2);
System.out.println(r);
}
}

Output:
EXPERIMENT NO.3
Unit/Topic: 2/Hash list

PROBLEM DEFINITION:
Write a java program to iterate through all elements in a hash list.

OBJECTIVE:
To understand the concept of hash list in collections

THEORY:
Attached here with.

INPUT SET:

OUTPUT SET:
Attached.

EXPECTED VIVA QUESTIONS:


Q.1 What is Hash list?
Q.2 compare Array vs Collections?

NAME OF FACULTY: Prof. Priyanka Maheshwari


SIGNATURE:
DATE:
Program:
import java.util.HashSet;
import java.util.Iterator;
public class Iterator1{
public static void main (String[] args){
HashSet <String>s=new HashSet<String>();
s.add("CSE");
s.add("IT");
s.add("CSE with AIDS");
s.add("CSE with IOT");
s.add("ML with Data Science");
Iterator it =s.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
}
}
Output:
EXPERIMENT NO.4
Unit/Topic: 2/Queue

PROBLEM DEFINITION:
Write a java program to create a queue, add some colors & print out the elements of the queue.

OBJECTIVE:
To understand the concept of Queue in collection.

THEORY:
Attached here with.

INPUT SET:

OUTPUT SET:
Attached.

EXPECTED VIVA QUESTIONS:


Q.1 What is Queue?
Q.2 Compare queue & list?

NAME OF FACULTY: Prof. Priyanka Maheshwari


SIGNATURE:
DATE:
Program:
import java.util.PriorityQueue;
public class TestQueue1{
public static void main (String[] args){
PriorityQueue<String> queue=new PriorityQueue<String>();
queue.add("Red");
queue.add("Yellow");
queue.add("Green");
queue.add("Orange");
queue.add("Black");
System.out.println("Elements of the Priority Queue: ");
System.out.println(queue);
System.out.println("Size of queue :" +queue.size());
System.out.println( "Top element of queue:" + queue.peek());
System.out.println(" Delete element of queue:"+queue.poll());
System.out.println(" Delete element of queue:"+queue.poll());
System.out.println(" Delete element of queue:"+queue.poll());
}
}
Output:
EXPERIMENT NO.5
Unit/Topic: 2/Map

PROBLEM DEFINITION:
Write a program to show the concept of Map in collection.

OBJECTIVE:
To understand the concept of Map in collection.

THEORY:
Attached here with.

INPUT SET:

OUTPUT SET:
Attached.

EXPECTED VIVA QUESTIONS:


Q.1 What is Map?
Q.2 What are the types of Map?

NAME OF FACULTY: Prof. Priyanka Maheshwari


SIGNATURE:
DATE:
EXPERIMENT NO.6
Unit/Topic: 3/JDBC

PROBLEM DEFINITION:
Study of JDBC & its drivers.

OBJECTIVE:
To understand the concept of JDBC

THEORY:
Attached here with.

INPUT SET:

OUTPUT SET:
Attached.

EXPECTED VIVA QUESTIONS:


Q.1 What is JDBC?
Q.2 Compare the types of JDBC drivers?

NAME OF FACULTY: Prof. Priyanka Maheshwari


SIGNATURE:
DATE:
EXPERIMENT NO.7
Unit/Topic: 3/JDBC Connectivity

PROBLEM DEFINITION:
Write the steps for database Connectivity & Implement a java programs to access database using JDBC.

OBJECTIVE:
To understand the steps of JDBC Connectivity.

THEORY:
Attached here with.

INPUT SET:

OUTPUT SET:
Attached.

EXPECTED VIVA QUESTIONS:


Q.1 Write the steps of JDBC connectivity?
Q.2 Explain DDL, DML, DCL Statements?

NAME OF FACULTY: Prof. Priyanka Maheshwari


SIGNATURE:
DATE:
EXPERIMENT NO.8
Unit/Topic: 4/Servlet

PROBLEM DEFINITION:
Implement Login page using Servlet .

OBJECTIVE:
To understand the concept of Servlet.

THEORY:
Attached here with.

INPUT SET:

OUTPUT SET:
Attached.

EXPECTED VIVA QUESTIONS:


Q.1 What is Servlet?
Q.2 Explain life cycle of Servlet?

NAME OF FACULTY: Prof. Priyanka Maheshwari


SIGNATURE:
DATE:
EXPERIMENT NO.9
Unit/Topic: 4/JSP

PROBLEM DEFINITION:
Implement Registration page using JSP.

OBJECTIVE:
To understand the concept of JSP.

THEORY:
Attached here with.

INPUT SET:

OUTPUT SET:
Attached.

EXPECTED VIVA QUESTIONS:


Q.1 What is JSP?
Q.2 What are JSP literals?

NAME OF FACULTY: Prof. Priyanka Maheshwari


SIGNATURE:
DATE:
EXPERIMENT NO.10
Unit/Topic: 5/RMI& MVC

PROBLEM DEFINITION:
Study the following: 1. RMI. 2. MVC Architecture.

OBJECTIVE:
To understand the concept of RMI & MVC.

THEORY:
Attached here with.

INPUT SET:

OUTPUT SET:
Attached.

EXPECTED VIVA QUESTIONS:


Q.1 What is RMI?
Q.2 Explain MVC architecture.

NAME OF FACULTY: Prof. Priyanka Maheshwari


SIGNATURE:
DATE:

You might also like