212CSE2403 - JP Lab Manual
212CSE2403 - JP Lab Manual
JAVA PROGRAMMING
(Integrated Course
Practical) LabManual
(212CSE2403)
Student Name : ……………………………………………………….
Section : ………………………………………………………..
1
TABLE OF CONTENTS
1 Bonafide Certificate
3 Course Plan
4 Introduction
Experiments
15 Additional Experiments
2
SCHOOL OF COMPUTING
BONAFIDE CERTIFICATE
REGISTER NUMBER
3
EXPERIMENT EVALUATION SUMMARY
Class: Faculty:
Marks Faculty
S.No Date Experiment
(100) Signature
10
11
12
4
COURSE PLAN
Pre-Requisite:
Java still has its importance and popularity in the software industry, in spite of recent
development of several high level languages. It has an excellent support of high-level as well as
low-level functionality, which makes it suitable for many applications. Emphasis is placed on
event-driven programming methods, including creating and manipulating objects, classes, and
using object-oriented tools such as the class debugger. This course has been approved to satisfy
5
the Comprehensive Articulation Agreement for transferability as a pre-major and/or elective
course requirement. This course provides students with a comprehensive study of the Java
programming language. Classroom lectures stress the strengths of Java, which provide the
students with the means of writing efficient, maintainable, and portable code. The lectures are
supplemented with lab exercises. This course will also help the students during their placement sittings,
as most of the companies test proficiency in programming using Java.
Career Opportunities:
Java is typically used for fairly High-level development. It is used in embedded systems, which
is often listed as a computer engineering position (rather than computer science, or software
engineering.). Java is also used for device drivers and Graphical math utility code for larger projects
and used for development of browsers, instant messengers, server daemons, and network
code. Graduates may work as team members to analyze business requirements, design, develop,
and implement appropriate web solutions to the user community. The graduates of this
program will find employment in both small-size and mid-size business as well in larger
enterprises. Graduates may find jobs that involve developing or designing web pages, and
working with computer programming languages. These skills may be used to supplement a
career choice, or may be used to obtain the following entry-level job titles:
● Software developer
● Programmer
● Network administrator
● Web developer
Course Objectives:
PEO1: The Graduates will be technically competent to excel in IT industry and to pursue higher
studies.
6
PEO2: The Graduates will possess the skills to design and develop economically and technically
feasible computing systems using modern tools and techniques.
PEO3: The Graduates will have effective communication skills, team spirit, ethical principles
and the desire for self learning to succeed in their professional career.
PSO1: Problem-Solving Skills: The ability to apply mathematics, science and computer
engineering knowledge to analyze, design and develop cost effective computing solutions for
complex problems with environmental considerations.
PSO2: Professional Skills: The ability to apply modern tools and strategies in software project
development using modern programming environments to deliver a quality product for
business accomplishment.
PSO3: Communication and Team Skill: The ability to exhibit proficiency in oral and written
communication as individual or as part of a team to work effectively with professional
behaviors and ethics.
PSO4: Successful Career and Entrepreneurship: The ability to create a inventive career path by
applying innovative project management techniques to become a successful software
professional, an entrepreneur or zest for higher studies.
PO1: Ability to apply knowledge of mathematics, science and computer engineering to solve
computational problems.
PO2: Ability to identify, formulates, Analyse and derives conclusions in complex computing
problems.
PO3: Capability to design and develop computing systems to meet the requirement of industry
and society with due consideration for public health, safety and environment.
PO4: Ability to apply the knowledge of design of experiment and data analysis to derive
solutions in complex computing problems.
PO5: Ability to develop and apply modeling, simulation and prediction tools and techniques to
engineering problems.
7
PO6: Ability to assess and understand the professional, legal, security and societal
responsibilities relevant to computer engineering practice.
PO7: Ability to understand the impact of computing solutions in economic, environmental and
societal context for sustainable development.
PO8: Applying ethical principles and commitment to ethics of IT and software profession.
PO9: Ability to work effectively as an individual as well as in teams.
PO10: Ability to communicate effectively with technical community and with society.
PO11: Demonstrating and applying the knowledge of computer engineering and management
principles in software project development and in multidisciplinary areas.
PO12: Understanding the need for technological changes and engage in life-long learning.
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO1 PO1 PO1
0 1 2
PEO1 S S S S S L L S S
PEO2 L S S S S S S
PEO3 S S S S S S L S
CO and PO Mapping
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1 S S S S S M L M S S
8
CO2 S S S S S M M M S S
CO3 S S S S S M M M S S
CO4 S S S S S M M M S S
CO5 S S S S S M M M S S
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
PSO1 S S S S
PSO2 S S S M S
PSO3 S M S S S
PSO4 M S M M M S S
CO CO CO CO CO CO CO
1 2 3 4 5 6 7
PSO1 S S S S S S S
PSO2 S S S S S S S
PSO3 S S S S S S S
PSO4 M M M M M M M
ABET -CSO:
CSO1 - Analyze a complex computing problem and to apply principles of computing and
CSO2 – Design, implement, and evaluates a computing-based solution to meet a given set
of computing requirements in the context of the program’s discipline.
CSO6 – Apply Computer Science theory and software development fundamentals to produce
computing-based solutions.
ABET- ESO:
ESO2 - Ability to apply engineering design to produce solutions that meet specified needs
with consideration of public health, safety, and welfare, as well as global, cultural,
social, environmental, and economic factors.
ESO7 - Ability to acquire and apply new knowledge as needed, using appropriate learning
strategies.
CSO1 CSO2 CSO3 CSO4 CSO5 CSO6 ESO1 ESO2 ESO3 ESO4 ESO5 ESO6 ESO7
CO1 S M M S L
CO2 S M S M
CO3 S M M S M L
15
CO4 S L L S M
CO5 S M S
CO6 S M S M
CO7 S M S
List of Experiments:
Experi Cumulati
No. of
ment Name of the Experiment ve No. of
periods
No. periods
16
Rubrics for Internal and External Experiment Assessment:
1. 25 25 20 20 10
Basic Java Programs
2. Program using Objects and 25 30 15 20 10
Classes
3. 25 30 15 20 10
Program using Inheritance
4. 30 30 10 20 10
Program using Interfaces
5. 30 30 10 20 10
Program using Array List and String
6. 30 25 15 20 10
Program using Exception Handling
7. Program using Reading and Writing 30 25 15 20 10
Files
8. 25 25 15 25 10
Program using Multithreading
17
9. 30 30 20 10 10
Program using Generic Programming
10. Program using Event Handling, 30 30 20 10 10
Swing and AWT
11 Program using Network Socket TCP 25 30 25 10 10
and UDP
12. Program Using Database 25 30 25 10 10
Connectivity(JDBC)
INTRODUCTION
Java is a general-purpose computer-programming language that is concurrent, class-
based, object-oriented, and specifically designed to have as few implementation dependencies
as possible. It is intended to let application developers "write once, run anywhere"
(WORA), meaning that compiled Java code can run on all platforms that support Java without
the need for recompilation. Java applications are typically compiled to bytecode that can run on
any Java virtual machine (JVM) regardless of computer architecture. As of 2016, Java is one of
the most popular programming languages in use, particularly for client-server web
applications, with a reported 9 million developers. Java was originally developed by James
Gosling at Sun Microsystems (which has since been acquired by Oracle Corporation) and
released in 1995 as a core component of Sun Microsystems' Java platform. The language derives
much of its syntax from C and C++, but it has fewer low-level facilities than either of them.
The main objective of this course is to identify and apply suitable data structures and
algorithms for problem solving using Java. Also students may need to make time and space
complexity analysis for writing programs efficiently. The laboratory course is integrated with
theory contents; hence students can use their theoretical strength and apply the same in
practical to upgrade their knowledge.
The laboratory contents include the following categories of programs: Basic OOP
concepts, Inheritance and Interfaces, Exception Handling, Threads and Synchronization, File
Handling, Generics, Applets and Event Handlers to solve various classes of problems. The contents
will be dealt in theory classes before being implemented in laboratory. This helps students
in mastering problem solving and also able to provide efficient solution in terms of time and
space.
Being a core course of Computer Science and Engineering, Java Programming course is more
18
useful in qualifying certification courses like Oracle Certified Java Professional (OCJP). Through
this integrated course, student can get more knowledge and be able to solve problems using Java
programming.
19
Ex .No 1 Basic Java Programs
Objective:
Theory:
Variable is a name of memory location. There are three types of variables in java: local, instance
and static. There are two types of data types in java: primitive and non-primitive.
Types of Variable
local variable
instance variable
static variable
1) Local Variable
2) Instance Variable
A variable which is declared inside the class but outside the method, is called instance variable .
It is not declared as static.
3) Static variable
The buffer size may be specified, or the default size may be used.
Each read request made of a Reader causes a corresponding read request to be made of
the underlying character or byte stream.
Class declaration
Field
protected Object lock -- This is the object used to synchronize operations on this stream.
Creating Objects
In Java, you create an object by creating an instance of a class or, in other words, instantiating a
class. Often, you will see a Java object created with a statement like the following, which creates
a new Rectangle object from the Rectangle class given in the previous section:
ARRAYS
Creating Arrays:
There are three steps to creating an array, declaring it, allocating it and initializing it.
Declaring Arrays:
Like other variables in Java, an array must have a specific type like byte, int, String or double.
Like all other variables in Java an array must be declared. When you declare an array variable
you suffix the type with [] to indicate that this variable is an array. Here are some examples:
21
int k[];
float yt[];
String names[];
In other words you declare an array like you'd declare any other variable except you
append brackets to the end of the variable type.
Allocating Arrays
Declaring an array merely says what it is. It does not create the array. To actually
create the array (or any other object) use the new operator.
k = new int[3];
yt = new float[7];
names = new String[50];
The numbers in the brackets specify the dimension of the array; i.e. how many slots it
has to hold values. With the dimensions above k can hold three ints, yt can hold seven
floats and names can hold fifty Strings.
Initializing Arrays
Individual elements of the array are referenced by the array name and by an integer
which represents their position in the array. You can use array elements wherever you'd use
a similarly typed variable that wasn't part of an array. Here's how we'd store values in the
arrays we've been working with
k[0] = 2;
k[1] = 5;
k[2] = -2;
yt[6] = 7.5f;
names[4] = "Fred"; This step is called initializing the array or, more precisely, initializing the
elements of the array.
Two dimensional arrays are declared, allocated and initialized much like one
dimensional arrays. However we have to specify two dimensions rather than one, and we
typically use two nested for loops to fill the array. The array examples above are filled with
the sum of their row and column indices. Here's some code that would create and fill such
an array:
class FillArray
22
{
public static void main (String args[])
{int M[][];
M = new int[4][5];
for (int row=0; row < 4; row++)
{
for (int col=0; col < 5; col++)
{
M[row][col] = row+col;
} }
}}
In two-dimensional arrays Array Index Out Of Bounds errors occur whenever you exceed
the maximum column index or row index. Unlike two-dimensional C arrays, two-
dimensional Java arrays are not just one-dimensional arrays indexed in a funny way.
Multidimensional Arrays
You don't have to stop with two dimensional arrays. Java lets you have arrays of three,
four or more dimensions. The syntax for three dimensional arrays is a direct extension of
that for two-dimensional arrays. Here's a program that declares, allocates and initializes a three-
dimensional array:
class Fill3DArray
{
public static void main (String args[])
{int M[][][];
M = new int[4][5][3];
for (int row=0; row < 4; row++)
Sample Program:
Output:
G.C.D = 9
Output:
G.C.D = 9
List of Exercise:
Additional Programs
1. Write a program called Harmonic Sum to compute the sum of a harmonic series, as shown
below, where n=50000. The program shall compute the sum from left-to-right as well as
from the right-to-left. Are the two sums the same? Obtain the absolute difference between
these two sums and explain the difference. Which sum is more accurate?
2. Write a program which prompts user for the number of students in a class (a non- negative
integer), and saves it in an int variable called numStudents. It then prompts user for the
grade of each of the students (integer between 0 to 100) and saves them in an int array called
grades. The program shall then compute and print the average (in double rounded to 2
decimal places) and minimum/maximum (in int).
3. Write a Java program to separate 0s on left side and 1s on right side of an array of 0s and 1s
in random order.
4. Write a Java program to add and remove a specific element from an array.
5. Write a program that prompts user for the mark (between 0-100 in int) of 3 students;
computes the average (in double); and prints the result rounded to 2 decimal places. Your
program needs to perform input validation.
6. Write a program to computer SalesTaxCalculator
7. Write a program to compute income tax for a given gross salary
8. Write a program called CozaLozaWoza which prints the numbers 1 to 110, 11 numbers per
line. The program shall print "Coza" in place of the numbers which are multiples of 3, "Loza"
for multiples of 5, "Woza" for multiples of 7, "CozaLoza" for multiples of 3 and 5, and so on.
The output shall look like:
1 2 Coza 4 Loza Coza Woza 8 Coza Loza 11
Coza 13 Woza CozaLoza 16 17 Coza 19 Loza CozaWoza 22
23 Coza Loza 26 Coza Woza 29 CozaLoza 31 32 Coza
9. Write a program that can convert degrees Fahrenheit to degrees Celsius, or vice versa
22
10. Given the size, return a square matrix of numbers in spiral order.
11. Write a program that prints a conversion table from miles to kilometers.
12. Develop a Java application to generate Electricity bill. Create a class with the following
members: Consumer no., consumer name, previous month reading, current month
reading, type of EB connection (i.e domestic or commercial). Compute the bill amount
using the following tariff.
If the type of the EB connection is domestic, calculate the amount to be paid as follows:
a. First 100 units - Rs. 1 per unit
b. 101-200 units - Rs. 2.50 per unit
c. 201 -500 units - Rs. 4 per unit
d. > 501 units - Rs. 6 per unit
If the type of the EB connection is commercial, calculate the amount to be paid as follows:
e. First 100 units - Rs. 2 per unit
f. 101-200 units - Rs. 4.50 per unit
g. 201 -500 units - Rs. 6 per unit
h. > 501 units - Rs. 7 per unit
13. Develop a java application to implement currency converter (Dollar to INR, EURO to INR,
Yen to INR and vice versa), distance converter (meter to KM, miles to KM and vice versa), time
converter (hours to minutes, seconds and vice versa) using packages.
23
Viva questions
Faculty Signature
Result:
24
Ex .No 2 Program Using Object and Classes
Objective
Theory:
OBJECT:
Objects are key to understanding object-oriented technology. Look around right now and you'll
find many examples of real-world objects: your dog, your desk, your television set, your bicycle.
Real-world objects share two characteristics: They all have state and behavior. These real-world
observations all translate into the world of object-oriented programming. Software objects are
conceptually similar to real-world objects: they too consist of state and related behavior. An
object stores its state in fields (variables in some programming languages) and exposes its
behavior through methods (functions in some programming languages).
Creating Objects
In Java, you create an object by creating an instance of a class or, in other words, instantiating a
class. Often, you will see a Java object created with a statement like the following, which creates
a new Rectangle object from the Rectangle class given in the previous section:
Rectangle rect = new Rectangle();
CLASS:
In the real world, you'll often find many individual objects all of the same kind. There may be
thousands of other bicycles in existence, all of the same make and model. Each bicycle was built
from the same set of blueprints and therefore contains the same components.
Object is the physical as well as logical entity whereas class is the logical entity only. Object is
an instance of a class. Class is a template or blueprint from which objects are created. So object
is the instance(result) of a class.
Write the java program to create linked list implementation using classes and objects
import java.util.*;
public class LinkedListExample {
public static void main(String args[]) {
25
/*add(String Element) is used for adding
* the elements to the linked list*/
linkedlist.add("Item1");
linkedlist.add("Item5");
linkedlist.add("Item3");
linkedlist.add("Item6");
linkedlist.add("Item2");
Output:
Linked List Content: [Item1, Item5, Item3, Item6, Item2]
LinkedList Content after addition: [First Item, Item1, Item5, Item3, Item6, Item2, Last Item]
LinkedList after deletion of first and last element: [Item1, Item5, Item3, Item6, Item2]
26
Final Content: [Newly added item, Item1, Item3, Item6, Item2]
List of Experiments
28
29
30
31
32
33
34
Viva questions
Faculty Signature
Result:
35
Ex .No 3 Program Using Inheritance
Objective:
Theory
Different kinds of objects often have a certain amount in common with each
other. Mountain bikes, road bikes, and tandem bikes, for example, all share the
characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also
defines additional features that make them different: tandem bicycles have two seats
and two sets of handlebars; road bikes have drop handlebars; some mountain bikes
have an additional chain ring, giving them a lower gear ratio. Object-oriented
programming allows classes to inherit commonly used state and behavior from other
classes. In this example, Bicycle now becomes the superclass of MountainBike, RoadBike,
and TandemBike. In the Java programming language, each class is allowed to have one
direct superclass, and each superclass has the potential for an unlimited number of
subclasses:
The syntax for creating a subclass is simple. At the beginning of your class declaration,
use the extends keyword, followed by the name of the class to inherit from:
This gives Mountain Bike all the same fields and methods as Bicycle, yet allows its code
to focus exclusively on the features that make it unique. This makes code for your subclasses
easy to read. However, you must take care to properly document the state and behavior
that each superclass defines, since that code will not appear in the source file of each
subclass. Java Inheritance defines a relationship between a superclass and its
36
subclasses. This means that an object of a subclass can be used wherever an object of the
superclass can be used. Class Inheritance in java mechanism is used to build new
classes from existing classes. The inheritance relationship is transitive: if class x extends
class y, then a class z, which extends class x, will also inherit from class y.
Single Inheritance.
Multiple Inheritance (Through Interface)
Multilevel Inheritance.
Hierarchical Inheritance.
Hybrid Inheritance (Through Interface)
Below are Various types of inheritance in Java. We will see each one of them one by one with the
help of examples and flow diagrams.
1) 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.
Class A
{
public void methodA()
{
System.out.println("Base class method");
}}
Class B extends A
{
public void methodB()
{
37
System.out.println("Child class method");
}
public static void main(String args[])
{
B obj = new B();
obj.methodA(); //calling super class method
obj.methodB(); //calling local method
}}
2) Multiple Inheritance
“Multiple Inheritance” refers to the concept of one class extending (Or inherits) more than one
base class. The inheritance we learnt earlier had the concept of one base class or parent. The
problem with “multiple inheritance” is that the derived class will have to manage the
dependency on two base classes.
Note 1: Multiple Inheritance is very rarely used in software projects. Using Multiple inheritance
often leads to problems in the hierarchy. This results in unwanted complexity when further
extending the class.
Note 2: Most of the new OO languages like Small Talk, Java, C# do not support Multiple
inheritance. Multiple Inheritance is supported in C++.
3) 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.
38
Multilevel Inheritance example program in Java
Class X
{
public void methodX()
{
System.out.println("Class X method");
}}
Class Y extends X
{
public void methodY()
{
System.out.println("class Y method");
}}
Class Z extends Y
{
public void methodZ()
{
System.out.println("class Z method");
}
public static void main(String args[])
{
Z obj = new Z();
obj.methodX(); //calling grand parent class method
obj.methodY(); //calling parent class method
obj.methodZ(); //calling local method
}
}
4) Hierarchical Inheritance
39
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.
5) 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.
Write a java program to create an abstract class named shape that contains two integers and
an empty method named print Area(). Provide three classes named Rectangle,, Triangle and
Circle such that each one of the classes extends the class shape. Each one of the class contains
only the method print Area() that print the area of the given shape
class Shape
{
//define a length which is public and can be used in square,
//rectangle and circle classes
public int length = 10;
}
40
//inherit the properties of Shape class with the use of extends keyword
Output:
Area of Rectangle: 70
List of Experiments:
Program:
42
43
44
45
46
47
48
49
Viva questions
Faculty Signature
Result:
50
Ex .No 4 Program Using Interfaces
Objective:
Theory
Interface in Java
An interface in java is a blueprint of a class. It has static constants and abstract methods
only. The interface in java is a mechanism to achieve fully abstraction. There can be only abstract
methods in the java interface not method body. It is used to achieve fully abstraction and
multiple inheritance in Java. Java Interface also represents IS-A relationship. It cannot be
instantiated just like abstract class.
There are mainly three reasons to use interface. They are given below.
The java compiler adds public and abstract keywords before the interface method and public,
static and final keywords before data members. In other words, Interface fields are public,
static and final bydefault, and methods are public and abstract.
51
Understanding relationship between classes and interfaces
As shown in the figure given below, a class extends another class, an interface extends another
interface but a class implements an interface.
interface printable
{
void print();
}
class A6 implements printable
{
public void print()
{
System.out.println("Hello");
}
public static void main(String args[])
{
A6 obj = new A6();
obj.print();
}
}
Output: Hello
If a class implements multiple interfaces, or an interface extends multiple interfaces i.e. known
as multiple inheritance.
52
interface Printable
{
void print();
}
interface Showable
{
void show();
}
class A7 implements Printable,Showable
{
public void print()
{
System.out.println("Hello");
}
public void show()
{
System.out.println("Welcome");
}
public static void main(String args[])
{
A7 obj = new A7();
obj.print();
obj.show();
}
}
Output:Hello
Welcome
Multiple inheritance is not supported through class in java but it is possible by interface,
why?
As we have explained in the inheritance chapter, multiple inheritance is not supported in case
of class. But it is supported in case of interface because there is no ambiguity as
implementation is provided by the implementation class. For example:
interface Printable
{
void print();
53
}
interface Showable
{
void print();
}
class TestTnterface1 implements Printable,Showable
{
public void print()
{
System.out.println("Hello");
}
public static void main(String args[])
{
TestTnterface1 obj = new TestTnterface1();
obj.print();
}
}
Hello
As you can see in the above example, Printable and Showable interface have same methods but
its implementation is provided by class TestTnterface1, so there is no ambiguity.
Interface inheritance
interface Printable
{
void print();
}
interface Showable extends Printable
{
void show();
}
class Testinterface2 implements Showable
{
public void print()
{
System.out.println("Hello");
}
public void show()
{
System.out.println("Welcome");
}
public static void main(String args[]) 54
{
Testinterface2 obj = new Testinterface2();
obj.print();
obj.show();
}
}
List of Experiments
Program
55
56
57
58
59
Viva questions
Faculty Signature
Result:
60
Ex .No 5 Program Using Array List and String
Objective:
Theory:
Java Array List
Java ArrayList class uses a dynamic array for storing the elements. It inherits AbstractList class
and implements List interface.
Program:
import java.util.*;
class ArrayList1{
public static void main(String args[]){
ArrayList<String> list=new ArrayList<String>();//Creating arraylist
list.add("Ravi");//Adding object in arraylist
list.add("Vijay");
list.add("Ravi");
list.add("Ajay");
//Invoking arraylist object
System.out.println(list);
}
}
Sample Output:
List of Experiments:
1. Write a program called PhoneKeyPad, which prompts user for a String (case insensitive),
and converts to a sequence of keypad digits
2. Write a program called CountVowelsDigits, which prompts the user for a String, counts
the number of vowels (a, e, i, o, u, A, E, I, O, U) and digits (0-9) contained in the string,
and prints the counts and the percentages
3. Write a program called ReverseString, which prompts user for a String, and prints the
reverse of the String by extracting and processing each character.
4. Write a Java Program that reads a line of integers, and then displays each integer, and the
sum of all the integers (Use StringTokenizer class of java.util)
5. Write a Java program to return the sum of the digits present in the given string. If there is
no digits the sum return is 0.
6. Write a Java program to return a new string using every characters of even positions from
a given string. ( Java Programming)
7. Write a Java program that checks whether a given string is palindrome or not.
8. Write a Java program to sort a list of names in ascending order.
9. Write a Java program to concatenate a given string with itself of a given number of times.
10. Write a Java program to counts occurrences of a certain character in a given string.
Program:
62
63
64
65
66
67
Viva Questions
Faculty Signature
Result:
68
Ex .No 6 Program Using Exception Handling
Objective
Theory
The exception handling in java is one of the powerful mechanism to handle the runtime errors so
that normal flow of the application can be maintained.In this page, we will learn about java
exception, its type and the difference between checked and unchecked exceptions.
What is exception
Exception Handling is a mechanism to handle runtime errors such as ClassNotFound, IO, SQL,
Remote etc.
The core advantage of exception handling is to maintain the normal flow of the application.
Exception normally disrupts the normal flow of the application that is why we use exception
handling. Let's take a scenario:
1. statement 1;
2. statement 2;
3. statement 3;
4. statement 4;
5. statement 5;//exception occurs
6. statement 6;
7. statement 7;
8. statement 8;
9. statement 9;
10. statement 10;
Suppose there is 10 statements in your program and there occurs an exception at statement 5,
rest of the code will not be executed i.e. statement 6 to 10 will not run. If we perform exception
handling, rest of the statement will be executed. That is why we use exception handling in java.
69
Hierarchy of Java Exception classes
Types of Exception
There are mainly two types of exceptions: checked and unchecked where error is considered as
unchecked exception. The sun microsystem says there are three types of exceptions:
1. Checked Exception
2. Unchecked Exception
3. Error
1) Checked Exception
The classes that extend Throwable class except RuntimeException and Error are known as
checked exceptions e.g.IOException, SQLException etc. Checked exceptions are checked at compile-
time.
2) Unchecked Exception
70
The classes that extend RuntimeException are known as unchecked exceptions e.g.
ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc. Unchecked
exceptions are not checked at compile-time rather they are checked at runtime.
3) Error
There are given some scenarios where unchecked exceptions can occur. They are as follows:
1. int a=50/0;//ArithmeticException
If we have null value in any variable, performing any operation by the variable occurs an
NullPointerException.
1. String s=null;
2. System.out.println(s.length());//NullPointerException
The wrong formatting of any value, may occur NumberFormatException. Suppose I have a
string variable that have characters, converting this variable into digit will occur
NumberFormatException.
1. String s="abc";
2. int i=Integer.parseInt(s);//NumberFormatException
If you are inserting any value in the wrong index, it would result
ArrayIndexOutOfBoundsException as shown below:
Program
public class
int data=100/0;
}catch(ArithmeticException e){System.out.println(e);}
Output:
List of Experiments
1. Write a program that creates a user interface to perform integer divisions. The user
enters two numbers in the textfields, Num1 and Num2. The division of Num1 and
Num2 is displayed in the Result field when the Divide button is clicked. If Num1
or Num2 were not an integer, the program would throw NumberFormatException.
If Num2 were Zero, the program would throw an ArithmeticException.Display
theexception in a message dialog box (co3)
2. Java programs to create an bank account with minimum balance, deposit amount,
withdraw amount and throws LessBalanceException, create a
LessBalanceException class which returns a statement says withdraw amount is
not valid, creates 2 accounts and try to withdraw more money than account and see
which type of exception occurs. (CO3)
72
3. Write a Java program to implement user defined exception handling.
4. Write a Java program that reads a file name from the user, displays information
about whether the file exists, whether the file is readable, or writable, the type of
file and the length of the file in bytes
Program:
73
74
75
76
Viva Questions
What is Exception handling
Types of Exception handling
Advantages of exception handling
What are the Java Exception Handling Keywords?
Difference between checked and unchecked exceptions
Faculty Signature
Result:
77
Ex .No 7 Program Using Reading and Writing File
Objective:
Theory
Java I/O (Input and Output) is used to process the input and produce the output based on
the input. Java uses the concept of stream to make I/O operation fast. The java.io package
contains all the classes required for input and output operations. We can perform file
handling in java by java IO API.
Stream
A stream is a sequence of data.In Java a stream is composed of bytes. It's called a stream
because it's like a stream of water that continues to flow.In java, 3 streams are created for us
automatically. All these streams are attached with console.
Let's see the code to print output and error message to the console.
System.out.println("simple message");
System.err.println("error message");
As described earlier, a stream can be defined as a sequence of data. The InputStream is used to
read data from a source and the OutputStream is used for writing data to a destination. Here is
a hierarchy of classes to deal with Input and Output streams.
78
FileInputStream
This stream is used for reading data from the files. Objects can be created using the
keyword new and there are several types of constructors available.Following constructor takes
a file name as a string to create an input stream object to read the file –
Following constructor takes a file object to create an input stream object to read the file. First we
create a file object using File() method as follows –
Once you have InputStream object in hand, then there is a list of helper methods which can be
used to read to stream or to do other operations on the stream.
79
Sr.No. Method & Description
2 This method cleans up the connection to the file. Ensures that the close
method of this file output stream is called when there are no more references
to this stream. Throws an IOException.
3 This method reads the specified byte of data from the InputStream.
Returns an int. Returns the next byte of data and -1 will be returned if it's
the end of the file.
4 This method reads r.length bytes from the input stream into an array.
Returns the total number of bytes read. If it is the end of the file, -1 will
be returned.
FileOutputStream
FileOutputStream is used to create a file and write data into it. The stream would create a file, if
it doesn't already exist, before opening it for output.
Here are two constructors which can be used to create a FileOutputStream object.
Following constructor takes a file name as a string to create an input stream object to write the
file −
Following constructor takes a file object to create an output stream object to write the file. First,
we create a file object using File() method as follows −
80
File f = new File("C:/java/hello");
OutputStream f = new FileOutputStream(f);
Once you have OutputStream object in hand, then there is a list of helper methods, which can be
used to write to stream or to do other operations on the stream.
Directories in Java
A directory is a File which can contain a list of other files and directories. You use File object to
create directories, to list down files available in a directory. For complete detail, check a list of
all the methods which you can call on File object and what are related to directories.
Creating Directories
There are two useful File utility methods, which can be used to create directories −
The mkdir( ) method creates a directory, returning true on success and false on failure.
Failure indicates that the path specified in the File object already exists, or that the
directory cannot be created because the entire path does not exist yet.
The mkdirs() method creates both a directory and all the parents of the directory.
Listing Directories
You can use list( ) method provided by File object to list down all the files and directories
available in a directory as follows
You have a Path instance representing a file or directory, but does that file exist on the file
system? Is it readable? Writable? Executable?
The methods in the Path class are syntactic, meaning that they operate on the Path instance. But
eventually you must access the file system to verify that a particular Path exists, or does not
exist. You can do so with the exists(Path, LinkOption...) and the notExists(Path,
LinkOption...) methods. Note that !Files.exists(path) is not equivalent to Files.notExists(path).
When you are testing a file's existence, three results are possible:
81
If both exists and not Exists return false, the existence of the file cannot be verified.
List of Experiments:
1. Write a Java program that reads a file name from the user, and then displays
information about whether the file exists, whether the file is readable, whether the
file is writable, the type of file and the length of the file in bytes.
2. Write a Java program that reads a file and displays the file on the screen, with a
line number before each line.
3. Write a Java program that displays the number of characters, lines and words in a
text file.
4. Write a Java program to illustrate collection classes like (i) Array List, (ii) Iterator,
(iii)Hash map.
5. Convert the content of a given file into the uppercase content of the same file. (co3)
Program:
82
83
84
85
86
Viva Questions
Faculty Signature
Result:
87
Ex .No 8 Program using Multithreading
Objective:
Theory:
A thread goes through various stages in its life cycle. For example, a thread is born, started,
runs, and then dies. The following diagram shows the complete life cycle of a thread.
88
New − A new thread begins its life cycle in the new state. It remains in this state until the
program starts the thread. It is also referred to as a born thread.
Runnable − After a newly born thread is started, the thread becomes runnable. A thread
in this state is considered to be executing its task.
Waiting − Sometimes, a thread transitions to the waiting state while the thread waits for
another thread to perform a task. A thread transitions back to the runnable state only
when another thread signals the waiting thread to continue executing.
Timed Waiting − A runnable thread can enter the timed waiting state for a specified
interval of time. A thread in this state transitions back to the runnable state when that
time interval expires or when the event it is waiting for occurs.
Terminated (Dead) − A runnable thread enters the terminated state when it completes its
task or otherwise terminates.
Thread Priorities
Every Java thread has a priority that helps the operating system determine the order in which
threads are scheduled.
Java thread priorities are in the range between MIN_PRIORITY (a constant of 1) and
MAX_PRIORITY (a constant of 10). By default, every thread is given priority
NORM_PRIORITY (a constant of 5).
Threads with higher priority are more important to a program and should be allocated
processor time before lower-priority threads. However, thread priorities cannot guarantee the
order in which threads execute and are very much platform dependent.
If your class is intended to be executed as a thread then you can achieve this by implementing
a Runnable interface. You will need to follow three basic steps −
Step 1
Step 2
As a second step, you will instantiate a Thread object using the following constructor −
Thread(Runnable threadObj, String threadName); Where, threadObj is an instance of a class
that implements the Runnableinterface and threadName is the name given to the new thread.
89
Step 3
Once a Thread object is created, you can start it by calling start() method, which executes
a call to run( ) method. Following is a simple syntax of start() method − void start();
The second way to create a thread is to create a new class that extends Thread class using the
following two simple steps. This approach provides more flexibility in handling multiple
threads created using available methods in Thread class.
Step 1
You will need to override run( ) method available in Thread class. This method provides an
entry point for the thread and you will put your complete business logic inside this method.
Following is a simple syntax of run() method −public void run( )
Step 2
Once Thread object is created, you can start it by calling start() method, which executes a call to
run( ) method. Following is a simple syntax of start() method void start( );
Output:thread is running...
91
Thread t1 =new Thread(m1);
t1.start();
}
}
List of Experiments:
1. Write a java program that implements a multi-threaded application that has threethreads.
First thread generates a random integer every 1 second and if the value is even, second
thread computes the square of the number and prints. If the value is odd, the third thread
will print the value of cube of the number.
2. A program to illustrate the concept of multi-threading that creates three threads. First
thread displays ―Good Morning‖ every one second, the second thread displays ―Hello‖
every two seconds and the third thread displays ―Welcome‖ every three seconds
Program:
92
93
94
95
Viva Questions
1) What is multithreading?
2) What is a difference between a preemptive scheduling and time slicing?
3) What is synchronization?
4) What is the difference between the notify() and notifyall()?
5) What is the use of join()?
6) What is thread?
7) What is difference between wait() and sleep() method?
8) When should we interrupt a thread?
Faculty Signature
Result:
96
Ex .No 9 Program Using Generic Programming
Objective
To write a program using Generic Class
Theory
Java Generic methods and generic classes enable programmers to specify, with a single method
declaration, a set of related methods, or with a single class declaration, a set of related types,
respectively.
Generics also provide compile-time type safety that allows programmers to catch invalid types
at compile time.
Using Java Generic concept, we might write a generic method for sorting an array of objects,
then invoke the generic method with Integer arrays, Double arrays, String arrays and so on, to
sort the array elements.
Generic Methods
You can write a single generic method declaration that can be called with arguments of different
types. Based on the types of the arguments passed to the generic method, the compiler handles
each method call appropriately. Following are the rules to define Generic Methods −
All generic method declarations have a type parameter section delimited by angle
brackets (< and >) that precedes the method's return type ( < E > in the next example).
Each type parameter section contains one or more type parameters separated by commas.
A type parameter, also known as a type variable, is an identifier that specifies a generic
type name.
The type parameters can be used to declare the return type and act as placeholders for the
types of the arguments passed to the generic method, which are known as actual type
arguments.
A generic method's body is declared like that of any other method. Note that type
parameters can represent only reference types, not primitive types (like int, double and
char).
Example
Following example illustrates how we can print an array of different type using a single Generic
method −
Output
Array integerArray contains:
12345
Example
Following example illustrates how extends is used in a general sense to mean either "extends"
(as in classes) or "implements" (as in interfaces). This example is Generic method to return the
largest of three Comparable objects −
98
if(y.compareTo(max) > 0) {
max = y; // y is the largest so far
}
if(z.compareTo(max) > 0) {
max = z; // z is the largest now
}
return max; // returns the largest object
}
Output
Max of 3, 4 and 5 is 5
Generic Classes
A generic class declaration looks like a non-generic class declaration, except that the class name
is followed by a type parameter section.
As with generic methods, the type parameter section of a generic class can have one or more
type parameters separated by commas. These classes are known as parameterized classes or
parameterized types because they accept one or more parameters.
Example
Following example illustrates how we can define a generic class −
99
public void add(T t) {
100
this.t = t;
}
public T get()
{return t;
}
integerBox.add(new Integer(10));
stringBox.add(new String("Hello World"));
Output
Integer Value :10
String Value :Hello World
List of Experiments:
Program:
101
102
103
104
Viva Questions
Faculty Signature
Result:
105
Ex .No 10 Program using Event handling, Swing and AWT
Objective
To design a Java program with necessary event handlers, Swing and AWT
Theory
106
3. public void stop(): is used to stop the Applet. It is invoked when Applet is stop or
browser is minimized.
4. public void destroy(): is used to destroy the Applet. It is invoked only once.
java.awt.Component class
The Component class provides 1 life cycle method of applet.
1. public void paint(Graphics g): is used to paint the Applet. It provides Graphics class
object that can be used for drawing oval, rectangle, arc etc.
Ways to run an applet
There are two ways to run an applet
By html file.
By appletViewer tool (for testing purpose).
Simple example of Applet
//First.java
import java.applet.Applet;
import java.awt.Graphics;
public class First extends Applet
{
public void paint(Graphics g)
{
g.d rawString("welcome",150,150);
}
}
Myaplet.html
<html>
<body>
<applet code="First.class" width="300" height="300">
</applet>
</body>
</html>
Java AWT:
Java AWT (Abstract Window Toolkit) is an API to develop GUI or window-based applications in
java.
Java AWT components are platform-dependent i.e. components are displayed according to the view
of operating system. AWT is heavyweight i.e. its components are using the resources of OS.
The java.awt package provides classes for AWT api such as TextField, Label, TextArea,
RadioButton, CheckBox, Choice, List etc.
Java AWT (Abstract Window Toolkit) is an API to develop GUI or window-based applications
in java.
Java AWT components are platform-dependent i.e. components are displayed according
to the view of operating system. AWT is heavyweight i.e. its components are using the
resources of OS.
107
The java.awt package provides classes for AWT api such as TextField, Label, TextArea,
RadioButton, CheckBox, Choice, List etc.
108
Container
The Container is a component in AWT that can contain another components like buttons,
textfields, labels etc. The classes that extends Container class are known as container such as
Frame, Dialog and Panel.
Window
The window is the container that have no borders and menu bars. You must use frame, dialog or
another window for creating a window.
109
Panel
The Panel is the container that doesn't contain title bar and menu bars. It can have other
components like button, textfield etc.
Frame
The Frame is the container that contain title bar and can have menu bars. It can have other
components like button, textfield etc.
110
Event Handling
Event Handling is the mechanism that controls the event and decides what should
happen if an event occurs. This mechanism has the code which is known as event handler that is
executed when an event occurs.
Components of Event Handling
Event handling has three main components,
Events: An event is a change in state of an object.
Events Source: Event source is an object that generates an event.
Listeners: A listener is an object that listens to the event. A listener gets notified when an
event occurs.
Event Handling provides four types of classes; they are:
1. Event Adapters
2. Event classes
3. Event Sources
4. Event Listeners
1.EventAdapters
In a program, when a listener has many abstract methods to override, it becomes complex
for the programmer to override all of them. For example, for closing a frame, we must override
seven abstract methods of WindowListener, but we need only one method of them.
For reducing complexity, Java provides a class known as "adapters" or adapter class. Adapters
are abstract classes, that are already being overriden.
2. Eventclasses
Every event source generates an event and is named by a Java class. An event is generated when
something changes within a graphical user interface.
For example the event generated by a:
Button is known as an ActionEvent
Checkbox is known as an ItemEvent
All the events are listed in the java.awt.event package.
111
3. EventSources
Event Sources are responsible for generating events and are called components.
The source for an event can be a button, TextField or a Frame etcetera.
4. EventListeners
Events are handled by a special group of interfaces known as "listeners".
Events are supported by a number of Java packages, like java.util, java.awt and java.awt.event.
112
TextField tf;
AEvent(){
//create components
tf=new TextField();
tf.setBounds(60,50,170,20);
Button b=new Button("click me");
b.setBounds(100,120,80,30);
//register listener
b.addActionListener(this);//passing current instance
115
Example - 2
import java.awt.*;
import java.awt.event.*;
public class MouseListenerExample2 extends Frame implements
MouseListener{MouseListenerExample2(){
addMouseListener(this);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public void mouseClicked(MouseEvent e)
{Graphics g=getGraphics();
g.setColor(Color.BLUE);
g.fillOval(e.getX(),e.getY(),30,30);
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
Output:
116
java MouseMotionListener Interface
The Java MouseMotionListener is notified whenever you move or drag mouse. It is
notified against MouseEvent. The MouseMotionListener interface is found in java.awt.event
package. It has two methods.
setSize(300,300);
setLayout(null);
setVisible(true);
}
public void mouseDragged(MouseEvent e)
{Graphics g=getGraphics();
g.setColor(Color.BLUE);
g.fillOval(e.getX(),e.getY(),20,20);
}
public void mouseMoved(MouseEvent e) {}
l=new Label();
l.setBounds(20,50,100,20);
area=new TextArea();
area.setBounds(20,80,300, 300);
area.addKeyListener(this);
add(l);add(area);
setSize(400,400);
setLayout(null);
setVisible(true);
}
public void keyPressed(KeyEvent e)
{l.setText("Key Pressed");
118
}
public void keyReleased(KeyEvent e)
{l.setText("Key Released");
}
public void keyTyped(KeyEvent e)
{l.setText("Key Typed");
}
setSize(400,400);
setLayout(null);
setVisible(true);
}
120
java.awt.event Adapter classes
Adapter class Listener interface
WindowAdapter WindowListener
KeyAdapter KeyListener
MouseAdapter MouseListener
MouseMotionAdapter MouseMotionListener
FocusAdapter FocusListener
ComponentAdapter ComponentListener
ContainerAdapter ContainerListener
HierarchyBoundsAdapter HierarchyBoundsListener
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true); }
public void mouseClicked(MouseEvent e)
{Graphics g=f.getGraphics();
g.setColor(Color.BLUE);
g.fillOval(e.getX(),e.getY(),30,30);
}
public static void main(String[] args)
{new MouseAdapterExample();
121
}}
List of Experiments:
1. Write a temperature conversion applet that converts from Fahrenheit to Celsius. The
Fahrenheit temperature should be entered from the keyboard (via a JTextField). A JLabel
should be used to display the converted temperature. Use the following formula for the
conversion: Celcius = ((5/9)*(Ferenheit‐32)). Enhance the temperature conversion applet
of Q1 by adding the Kelvin temperature scale. The applet should also allow the user to
make conversions between any two scales. Use the following formula for the conversion
between Kelvin and Celsius (in addition to the formulain Q1): Kelvin = Celcius + 273.15
2. Calculator using AWT controls
3. Authentication check using AWT controls
4. Design a calculator using event-driven programming paradigm of Java with the
following options.
a) Decimal manipulations
b) Scientific manipulations
Program:
122
123
124
125
Viva Questions
Faculty Signature
Result:
126
Ex .No 11 Program using Network Socket
AIM:
Theory:
Java Socket programming is used for communication between the applications running on
different JRE. Java Socket programming can be connection-oriented or connection-less. Socket
and ServerSocket classes are used for connection-oriented socket programming and
DatagramSocket and DatagramPacket classes are used for connection-less socket
programming.
Here, we are going to make one-way client and server communication. In this application, client
sends a message to the server, server reads the message and prints it. Here, two classes are being
used: Socket and ServerSocket. The Socket class is used to communicate client and server. Through
this class, we can read and write message. The ServerSocket class is used at server-side. The accept()
method of ServerSocket class blocks the console until the client is connected. After the successful
connection of client, it returns the instance of Socket at server-side.
127
Socket class
A socket is simply an endpoint for communications between the machines. The Socket class can be
used to create a socket.
Important methods
Method Description
ServerSocket class
The ServerSocket class can be used to create a server socket. This object is used to establish
communication with the clients.
Important methods
Method Description
1) public Socket accept() returns the socket and establish a connection between server
and client.
Creating Server:
To create the server application, we need to create the instance of ServerSocket class. Here, we are
using 6666 port number for the communication between the client and server. You may also
choose any other port number. The accept() method waits for the client. If clients connects with the
given port number, it returns an instance of Socket.
128
Example:
Creating Client:
To create the client application, we need to create the instance of Socket class. Here, we need to
pass the IP address or hostname of the Server and a port number. Here, we are using "localhost"
because our server is running on same system.
Example:
Sample Code:
MyServer.java
import java.io.*;
import java.net.*;
public class MyServer {
public static void main(String[] args){
try{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();//establishes connection
DataInputStream dis=new DataInputStream(s.getInputStream());
String str=(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}catch(Exception e){System.out.println(e);}
}
}
129
MyClient.Java
import java.io.*;
import java.net.*;
public class MyClient {
public static void main(String[] args) {
try{
Socket s=new Socket("localhost",6666);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
}catch(Exception e){System.out.println(e);}
}
}
List of Experiments:
Program:
130
131
132
Additional Experiments
133
134
135
136
Viva Questions
1. Define Network Socket.
2. What is URL Class?
3. Difference between TCP and UDP Socket.
4. What is use of SMTP Socket?
5. Define POP3.
6. List out URL Class Method.
Faculty Signature
Result:
137
Ex .No 12 Program using Database Connectivity(JDBC)
AIM:
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:
We can use JDBC API to access tabular data stored in any relational database. By the help of JDBC
API, we can save, update, delete and fetch data from the database. It is like Open Database
Connectivity (ODBC) provided by Microsoft.
The current version of JDBC is 4.3. It is the stable release since 21st September, 2017. It is based on
the X/Open SQL Call Level Interface. The java.sql package contains classes and interfaces for JDBC
API. A list of popular interfaces of JDBC API are given below:
o Driver interface
o Connection interface
o Statement interface
138
o PreparedStatement interface
o CallableStatement interface
o ResultSet interface
o ResultSetMetaData interface
o DatabaseMetaData interface
o RowSet interface
Before JDBC, ODBC API was the database API to connect and execute the query with the database.
But, ODBC API uses ODBC driver which is written in C language (i.e. platform dependent and
unsecured). That is why Java has defined its own API (JDBC API) that uses JDBC drivers (written in
Java language).
We can use JDBC API to handle database using Java program and can perform the following
activities:
139
1) Register the driver class
The forName() method of Class class is used to register the driver class. This method is used to
dynamically load the driver class.
The getConnection() method of DriverManager class is used to establish connection with the
database.
140
3) Create the Statement object
The createStatement() method of Connection interface is used to create statement. The object of
statement is responsible to execute queries with the database.
Statement stmt=con.createStatement();
The executeQuery() method of Statement interface is used to execute queries to the database.
This method returns the object of ResultSet that can be used to get all the records of a table.
By closing connection object statement and ResultSet will be closed automatically. The close()
method of Connection interface is used to close the connection.
141
To connect Java application with the MySQL database, we need to follow 5 following steps.
In this example we are using MySql as the database. So we need to know following informations
for the mysql database:
1. Driver class: The driver class for the mysql database is com.mysql.jdbc.Driver.
2. Connection URL: The connection URL for the mysql database
is jdbc:mysql://localhost:3306/sonoo where jdbc is the API, mysql is the database,
localhost is the server name on which mysql is running, we may also use IP address, 3306 is
the port number and sonoo is the database name. We may use any database, in such case,
we need to replace the sonoo with our database name.
3. Username: The default username for the mysql database is root.
4. Password: It is the password given by the user at the time of installing the mysql database.
In this example, we are going to use root as the password.
List of Experiments:
Write a java program to implement Course Registeration system with Data base Connectivity.
Write a java program to implement Examination System with Database Connectivity.
Write a program to establish the connection between Java program to database.
Write a program to create a database table by using Java program.
Develop an application to perform insert, update, retrieve and delete the record from the
database in JDBC.
Program:
143
Additional Experiments
144
Additional Experiments
145
146
Additional Experiments
147
148
149
Viva Questions
1. Define JDBC.
2. List out the Database driver ?
3. Define Prepared Statement?
4. Define Callable`Statement?
5. How to load Database driver in a Program.
Faculty Signature
Result:
150
Additional Experiments
151
152
153
154
Additional Experiments
155
References
1. https://www.tutorialspoint.com/java/
2. http://www.java2novice.com/java-fundamentals/
3. https://newcircle.com/bookshelf/java_fundamentals_tutorial/index
4. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/
5. https://www.quora.com/Why-is-threading-suitable-for-I-O-bound-operation
6. http://www.drdobbs.com/parallel/multithreaded-file-io/220300055
7. https://www.quora.com/Why-is-threading-suitable-for-I-O-bound-operation
8. https://www.mailinator.com/tymaPaulMultithreaded.pdf
9. http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.85.7032&rep=rep1&type=pd
f
10. http://www.javatpoint.com/Graphics-in-applet
11. http://www.landofcode.com/java-tutorials/java-graphics.php
12. http://cs.lmu.edu/~ray/notes/javagraphics/
13. https://www.tutorialspoint.com/javaexamples/gui_text.htm
14. http://www.javatpoint.com/event-handling-in-java
15. https://www.tutorialspoint.com/awt/awt_event_handling.html
16. http://way2java.com/awt-events/java-event-handling/
17. http://java-demos.blogspot.in/2013/11/event-handling-in-java.html
134