Download as pdf or txt
Download as pdf or txt
You are on page 1of 51

ABS VIDHYA MANDHIR,

THIRUVALLUR

CLASS 12

INFORMATION TECHNOLOGY

PRACTICAL RECORD FILE


2024 - 2025
SQL QUERIES

S.No DATE TOPIC

1
Creation of a database using mysql command
2
Show the databases using mysql command
3
Deletion of databases using mysql command
DATA DEFINITION LANGUAGE (DDL)
4
CREATE command
5
ALTER command
6
DROP command
7
TRUNCATE command
DATA MANIPULATION LANGUAGE (DML)
8
INSERT command
9
UPDATE command
10
DELETE command
11
SELECT command
12
JOIN Condition
13
ORDER BY Clause
14
AGGREGATE FUNCTION
15 GROUP BY Clause
JAVA PROGRAMS
S.No DATE TOPIC
Sum of Two Numbers Using Scanner
16

Program to check whether a number is Even or


17
ODD
Generate Multiplication table using for loop
18

Program to find the Area of Rectangle


19

Generate Fibonacci series


20

Print the Factorial of given number


21

Program to identify whether the given character


22
is Vowel, Consonant or not an alphabet.
Constructor in Java
23

Array Manipulation
24

Array using Binary Search


25

String Manipulation
26

Exception Handling in Java


27

Implement Assertion
28

Implements Threads by Extending Thread class


29

Implement Threads by Implementing Runnable


30
Interface
SQL QUERIES
1.CREATE DATABASE

1. Write down syntax and mysql command to create a database STUDENT and
its Output.

AIM

To write a mysql command to create a Database STUDENT listing out its


SYNTAX and its Output.

SYNTAX

CREATE DATABASE dbname;

QUERY

mysql> CREATE DATABASE student;

OUTPUT
mysql> CREATE DATABASE student
Query OK, 1 row affected <0.00 sec>

RESULT

Queries executed successfully and output verified.


2. SHOW DATABASES

2. Write down mysql command to show the databases.

AIM

To write a mysql command to show the databases and its output.

QUERY

mysql> SHOW databases;

OUTPUT

mysql> SHOW databases;

Database

Information_ schema
Mysql
Performance_schema
Stud
Student
test
6 rows in set <0.00 sec>

RESULT

Queries executed successfully and output verified.


3.DELETE DATABASES
3. Write down syntax and mysql command to delete a database STUDENT and
its Output.

AIM

To write a MySQL command to delete a database STUDENT listing out its


syntax, and its output.

SYNTAX

DROP DATABASE dbname;

QUERY

mysql> DROP DATABASE student;

OUTPUT

mysql> DROP DATABASE student;


Query OK, 1 row affected <0.64 sec>

RESULT

Queries executed successfully and output verified.


DATA DEFINITION LANGUAGE (DDL)
4. CREATE COMMAND

4. Write down a mysql command to create a table TEACHER with the following
field names given below and its Output.
 Teacher_ID,
 First_Name,
 Last_Name,
 Gender,
 Salary,
 Date_of_Birth,
 Dept_No
AIM

To write a mysql command to create a table TEACHER with the given field
names
 Teacher_ID,
 First_Name,
 Last_Name,
 Gender,
 Salary,
 Date_of_Birth,
 Dept_No
and its Output.

QUERY
mysql> CREATE TABLE Teacher
(
Teacher_ID INTEGER,
First_Name VARCHAR(20),
Last_Name VARCHAR(20),
Gender CHAR(1),
Salary DECIMAL(10,2),
Date_of_Birth DATE,
Dept_No INTEGER
);
OUTPUT
mysql> CREATE TABLE Teacher
(
 Teacher_ID INTEGER,
 First_Name VARCHAR(20),
 Last_Name VARCHAR(20),
 Gender CHAR(1),
 Salary DECIMAL(10,2),
 Date_of_Birth DATE,
 Dept_No INTEGER
 );
Query OK, 0 rows affected <0.25 sec>

RESULT

Queries executed successfully and output verified.


5. ALTER COMMAND

5. Write down mysql command to set a default value for the field
SALARY as 30000 to the table name Teacher whose field names are
listed below
 Teacher_ID,
 First_Name,
 Last_Name,
 Gender,
 Salary,
 Date_of_Birth,
 Dept_No
AIM
To write a mysql command to set a default value for the field SALARY as 3000
in table Teacher.

QUERY
mysql> ALTER TABLE Teacher ALTER Salary SET DEFAULT 30000;

OUTPUT
mysql> DESC Teacher;
Field Type Null Key Default Extra
Teacher_ID int<11> YES NULL
First_Name varchar<20> NO NULL
Last_Name varchar<20> YES NULL
Gender char<1> YES NULL
Salary decimal<10,2> YES NULL
Date_of_Birth date YES NULL
Dept_No int<11> YES 30000.00
7 rows in set <0.01 sec>

RESULT
Queries executed successfully and output verified.
6. DROP COMMAND
6. Write down syntax and mysql command to delete the single and multiple
tables and its Output.

AIM

To write a mysql command to delete the single and multiple tables


listing out its Syntax and its Output.

SYNTAX

DROP TABLE <table_name>;

DROP TABLE IF EXISTS <table_name1>, <table_name2>…….;

QUERY

DROP TABLE Customers;

DROP TABLE IF EXISTS Customers, Books;

OUTPUT
mysql> DROP TABLE Customers;
Query OK, 0 rows affected <0.05 sec>

mysql> DROP TABLE IF EXISTS Customers,Books;


Query OK, 0 rows affected <0.07 sec>

RESULT
Queries executed successfully and output verified.
7. TRUNCATE COMMAND
7. Write down syntax and mysql command to Truncate the table.

AIM

To write a mysql command to Truncate the table and its Output.

SYNTAX

TRUNCATE TABLE <table_name>;

QUERY
TRUNCATE TABLE Students;

OUTPUT
mysql> TRUNCATE TABLE Students;

RESULT
Queries executed successfully and output verified.
DATA MANIPULATION LANGUAGE (DML)
8. INSERT COMMAND
8. Write a mysql command to INSERT VALUES INTO table TEACHER in its field
Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No.

AIM

To write a mysql command to INSERT VALUES INTO table TEACHER in its


field Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth,
Dept_No.

QUERY
mysql> INSERT INTO Teacher(Teacher_ID, First_Name, Last_Name, Gender,
Salary, Date_of_Birth, Dept_No) VALUES (101, “Shanaya”, “Batra”, ‘F’, 50000,
‘1984-08-11’, 1);

OUTPUT

mysql> INSERT INTO Teacher(Teacher_ID, First_Name, Last_Name, Gender,


Salary, Date_of_Birth, Dept_No) VALUES (101, “Shanaya”, “Batra”, ‘F’, 50000,
‘1984-08-11’, 1);
Query OK, 1 row affected <0.05 sec>

mysql> select * from teacher;

Teacher_ID First_Name Last_Name Gender Salary Date_of_Birth Dept_No

101 Shanaya Batra F 50000.00 1984-08-11 1

RESULT
Queries executed successfully and output verified.
9. UPDATE COMMAND
9. Write a mysql command to UPDATE the details of Salary as 60000 in
Teacher table whose Teacher_ID=101.

The field names in Teacher Table is listed below.

 Teacher_ID,
 First_Name,
 Last_Name,
 Gender,
 Salary,
 Date_of_Birth,
 Dept_No

AIM
To write a mysql command to display the UPDATED details of Salary as 60000
for Teacher_ID=101 in table TEACHER with its field names listed below.

 Teacher_ID,
 First_Name,
 Last_Name,
 Gender,
 Salary,
 Date_of_Birth,
 Dept_No

QUERY

mysql> UPDATE Teacher SET Salary =60000 WHERE Teacher_ID= 101;


OUTPUT
mysql> select *from teacher;

Teacher_ID First_Name Last_Name Gender Salary Date_of_Birth Dept_No

101 Shanaya Batra F 50000.00 1984-08-11 1


102 Alice Walton F 45000.00 1983-09-03 3
103 Surbhi Bansal F 55000.00 1987-01-21 4
104 Megha Khanna F 40000.00 1979-04-06 3

4 rows in set <0.23 sec>

mysql> UPDATE Teacher SET Salary =60000 WHERE Teacher_ID= 101;


Query OK, 1 row affected <0.12 sec>
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select *from teacher;

Teacher_ID First_Name Last_Name Gender Salary Date_of_Birth Dept_No

101 Shanaya Batra F 60000.00 1984-08-11 1


102 Alice Walton F 45000.00 1983-09-03 3
103 Surbhi Bansal F 55000.00 1987-01-21 4
104 Megha Khanna F 40000.00 1979-04-06 3

4 rows in set <0.00 sec>

RESULT
Queries executed successfully and output verified.
10. DELETE COMMAND
10. Write down the syntax and mysql command to delete the single tuple and
all the tuples in Teacher table.

AIM
To write a mysql command to delete the single tuple and all the tuples in
Teacher table.

SYNTAX
DELETE FROM <Table_Name> WHERE <Condition>;
DELETE FROM <Table_Name>;

QUERY
DELETE FROM Teacher WHERE Teacher_ID=101;
DELETE FROM Teacher;

OUTPUT
mysql> DELETE FROM Teacher WHERE Teacher_ID=101;
Query Ok, 1 row affected(0.02 sec)

mysql> DELETE FROM Teacher;


Query Ok, 3 row affected(0.02 sec)

RESULT
Queries executed successfully and output verified.
11. SELECT COMMAND

11. (i) Write a mysql command to display all the details of a Teacher table.

(ii) Write a mysql command to display the details of a Teacher whose


Teacher_ID =101.

AIM

(i) To write a mysql command to display all the details of a Teacher table.

(ii)To write a mysql command to display the details of a Teacher whose


Teacher_ID =101 with its field names listed below.

 Teacher_ID,
 First_Name,
 Last_Name,
 Gender,
 Salary,
 Date_of_Birth,
 Dept_No

QUERY
mysql> SELECT * FROM Teacher;

mysql> SELECT * FROM Teacher WHERE Teacher_ID=101;

OUTPUT

mysql> SELECT * FROM Teacher;

Teacher_ID First_Name Last_Name Gender Salary Date_of_Birth Dept_No

101 Shanaya Batra F 60000.00 1984-08-11 1


102 Alice Walton F 45000.00 1983-09-03 3
103 Surbhi Bansal F 55000.00 1987-01-21 4
104 Megha Khanna F 40000.00 1979-04-06 3
mysql> SELECT * FROM Teacher WHERE Teacher_ID=101;

Teacher_ID First_Name Last_Name Gender Salary Date_of_Birth Dept_No

101 Shanaya Batra F 50000.00 1984-08-11 1

RESULT
Queries executed successfully and output verified.
JOIN CONDITION
&
ORDER BY CLAUSE
12. JOIN CONDITION

1. Write a query to joining rows from Teachers and Department


Table based on the equality between Dept_No and Dept_ID.

2. Write a Query to retrieve names of all the teachers who belongs


to Hindi Department.

3. Write a Query to retrieve names of all the teachers starting from


letter ‘S’.

4. Write a Query to retrieve names of all the teachers having 6


characters in the first name and starting with ‘S’.

5. Write a query to retrieve names of all the teachers having at least


6 characters in the first name.

DEPARTMENT TABLE

Dept_ID Dept_Name
1 Chemistry
2 Computer Science
3 English
4 Hindi
5 Physics
6 Commerce
7 Biology
8 Mathematics
9 Economics
TEACHER TABLE
Teacher_ID First_Name Last_Name Gender Salary Date_of_Birth Dept_No
101 Shanaya Batra F 50000 1984-08-11 1
102 Alice Watson F 48000 1983-02-12 3
103 Surbhi Bansal F 34000 1985-06-11 4
104 Megha Khanna F 38000 1979-04-06 4
105 Tarannum Malik F 54000 1978-04-22 5
106 Tarun Mehta M 50000 1980-08-21 2
107 Puneet NULL M 52000 1976-09-25 3
108 Namit Gupta M 49750 1981-10-19 1
109 Neha Singh F 49000 1984-07-30 7
110 Divya Chaudhary F 39000 1983-12-11 6
111 Saurabh Pant M 40000 1982-01-11 8
112 Sumita Arora F 40000 1981-10-10 9
113 Vinita Ghosh F 51500 1980-09-09 9
114 Vansh NULL M 53500 1982-05-04 2

AIM

1. To write a query to joining rows from Teachers and Department


Table based on the equality between Dept_No and Dept_ID

2. To retrieve names of all the teachers who belongs to Hindi


Department.

3. To retrieve names of all the teachers starting from letter ‘s’.

4. To retrieve names of all the teachers having 6 characters in the


first name and starting with ‘S’.

5. To retrieve names of all the teachers having at least 6 characters in


the first name.
QUERY 1
mysql> SELECT First_Name, Last_Name, Dept_ID, Dept_Name
FROM Teacher, Department
WHERE Dept_ID=Dept_No;

OUTPUT 1
First_Name Last_Name Dept_ID Dept_Name
Shanaya Batra 1 Chemistry
Namit Gupta 1 Chemistry
Tarun Mehta 2 Computer Science
Vansh NULL 2 Computer Science
Alice Watson 3 English
Puneet NULL 3 English
Surbhi Bansal 4 Hindi
Megha Khanna 4 Hindi
Tarannum Malik 5 Physics
Divya Chaudhary 6 Commerce
Neha Singh 7 Biology
Saurabh Pant 8 Mathematics
Sumita Arora 9 Economics
Vinita Ghosh 9 Economics

QUERY 2
mysql> SELECT First_name AS Fname, Last_Name As Lname
FROM Teacher As T, Department AS D
WHERE D.Dept_ID=T.Dept_ID AND Dept_Name=”Hindi”;

OUTPUT 2
Fname Lname
Surbhi Bansal
Megha Khanna
QUERY 3
mysql> SELECT First_name
FROM Teacher WHERE First_Name LIKE “S%”;

OUTPUT 3
First_Name
Shanaya
Surbhi
Saurabh
Sumita

QUERY 4
mysql> SELECT First_name
FROM Teacher WHERE First_Name LIKE “S- - - - -”;

OUTPUT 4
First_Name
Surbhi
Sumita

QUERY 5
mysql> SELECT First_name FROM Teacher
WHERE First_Name LIKE “- - - - - - %”;

OUTPUT 5
First_Name
Shanaya
Surbhi
Tarannum

RESULT
Queries executed successfully and output verified.
13.ORDER BY CLAUSE
1. Write a sql command to list the names of teachers in alphabetical order.
2. Write a sql command to retrieve the names and department numbers of all
the teachers ordered by the Department number and within each department
ordered by the names of the teachers in Descending order.
3. Write a sql command to retrieve all the details of those employees whose
last is not specified.

AIM
1. To list the names of teachers in alphabetical order.
2. To retrieve the names and department numbers of all the teachers ordered
by the Department number and within each department ordered by the names
of the teachers in Descending order.
3. To retrieve all the details of those employees whose last is not specified.

QUERY 1:
mysql> SELECT First_name, Last_Name FROM Teacher
ORDER BY First_Name, Last_Name;

OUTPUT 1
First_Name Last_Name
Alice Walton
Divya Chaudhary
Megha Khanna
Namit Gupta
Neha Singh
Puneet NULL
Saurabh Pant
Shanaya Batra
Sumita Arora
Surbhi Bansai
Tarannum Malik
Tarun Mehta
Vansh NULL
Vinita Ghosh
QUERY 2:

mysql> SELECT First_name, Last_Name FROM Teacher


ORDER BY Dept_No ASC, First_Name DESC, Last_Name DESC;

OUTPUT 2
First_Name Last_Name Dept_No
Shanaya Batra 1
Namit Gupta 1
Tarun Mehta 2
Vansh NULL 2
Alice Walton 3
Puneet NULL 3
Surbhi Bansal 4
Megha Khanna 4
Tarannum Malik 5
Divya Chaudhary 6
Neha Singh 7
Saurabh Pant 8
Sumita Arora 9
Vinita Ghosh 9

QUERY 3:

mysql> SELECT *FROM Teacher WHERE Last_Name IS NULL;

OUTPUT 3

Teacher_ID First_Name Last_Name Gender Salary Date_of_Birth Dept_No

107 Puneet NULL M 52500.00 1976-09-25 3


104 Vansh NULL M 53500.00 1982-05-04 2

RESULT
Queries executed successfully and output verified.
AGGREGATE
FUNCTION
14. AGGREGATE FUNCTION
1. Write a Sql command to find total salary of all the teachers.

2. Write a Sql command to find the maximum and minimum salary.

3. Write a Sql command to count the number of teachers earning more than
Rs. 40000.

4. Write a Sql command to retrieve the number of teachers in “Computer


Science” Department.

AIM

1.To find total salary of all the teachers.

2. To find the maximum and minimum salary.

3. To count the number of teachers earning more than Rs. 40000.

4. To retrieve the number of teachers in “Computer Science” Department.

QUERY 1
mysql> SELECT SUM(Salary) AS Total_Salary FROM Teacher;

OUTPUT 1
Total_Salary
203250.00

QUERY 2
mysql> SELECT MAX(Salary) AS Max_Salary, Min_Salary AS Min_Salary
FROM Teacher;

OUTPUT 2

Max_Salary Min_Salary
54000.00 34000.00
QUERY 3
mysql> SELECT COUNT(Salary) FROM Teacher WHERE Salary > 40000;

OUTPUT 3
COUNT(Salary)
9

QUERY 4

mysql> SELECT COUNT(*) AS No_of_Computer_Science_Teachers


FROM Department, Teacher
WHERE Dept_Name=”Computer Science” AND Dept_No=Dept_ID;

OUTPUT 4
No_of_Computer_Science_Teachers

RESULT
Queries executed successfully and output verified.
15.GROUP BY CLAUSE

1. Write a sql query to find the number of teachers teaching in each


department.

2. Write a sql query to find the number of teachers teaching in each


department and group the result based on the Department and for
each department and count the number of teachers who teach in
that department.

3. Write a Sql query to find the departments which have more than
one teacher.

AIM

1. To write a sql query to find the number of teachers teaching in


each department.

2. To write a sql query to find the number of teachers teaching in


each department and group the result based on the Department and
for each department and count the number of teachers who teach in
that department.

3. To write a sql query to find the departments which have more


than one teacher.

QUERY 1
mysql> SELECT Dept_No, COUNT(*) AS No_of_Teachers
FROM Teacher
GROUP BY Dept_No;
OUTPUT 1

Dept_No No_of_Teachers
1 2
2 2
3 2
4 2
5 1
6 1
7 1
8 1
9 2

QUERY 2
mysql> SELECT Dept_No, Dept_Name, COUNT(*) AS No_of_Teachers
FROM Teacher, Department WHERE Dept_ID = Dept_No;
GROUP BY Dept_No;

OUTPUT 2

Dept_No Dept_Name No_of_Teachers


1 Chemistry 2
2 Computer Science 2
3 English 2
4 Hindi 2
5 Physics 1
6 Commerce 1
7 Biology 1
8 Mathematics 1
9 Economics 2
QUERY 3
mysql> SELECT Dept_No, Dept_Name, COUNT(*) AS No_of_Teachers
FROM Teacher, Department WHERE Dept_ID = Dept_No;
GROUP BY Dept_No HAVING COUNT(*) > 1;

OUTPUT 3

Dept_No Dept_Name No_of_Teachers


1 Chemistry 2
2 Computer Science 2
3 English 2
4 Hindi 2
9 Economics 2

RESULT
Queries executed successfully and output verified.
JAVA PROGRAMS
16. SUM OF TWO NUMBERS USING SCANNER

AIM
To write a program for sum of two Numbers using scanner.

PROGRAM CODE:

import java.util.Scanner;
public class addtwonumbers;
{
public static void main(string[] args)
{
int num1,num1,sum;
Scanner sc=new Scanner(System.in);
System.out.println(“Enter First Number:”);
num1=sc.nextInt();
System.out.println(“Enter Second Number:”);
num2=sc.next.Int();
sc.close();
sum=num1+num2;
System.out.println(“Sum of two numbers:” +sum);
}
}

OUTPUT
Enter First Number:
120
Enter Second Number:
30
Sum of two numbers: 150

RESULT
Program executed successfully and Output verified.
17. PROGRAM TO CHECK WHETHER A NUMBER IS EVEN OR ODD
AIM
To write a java program to check whether a number is even or odd.

PROGRAM CODE:
import java.util.Scanner;
public class EvenOdd;
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
System.out.print(“Enter a number:”);
int num = reader.nextInt();
if(num % 2 ==0)
System.out.println(num + “is even”);
else
System.out.println(num + “is odd”);
}
}

OUTPUT 1
Enter a number: 5
5 is odd
OUTPUT 2
Enter a number: 8
8 is even

RESULT
Program executed successfully and Output verified.
18. GENERATE MULTIPLICATION TABLE USING FOR LOOP
AIM
To write a Java program to Generate Multiplication Table using for loop.

PROGRAM CODE

import java.util.Scanner;
public class MultiplicationTable
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
System..out.print(“Enter the Multiplication Table Number:”);
int num = reader.nextInt();
for(int i=1; i<=10; i++)
{
System.out.print(“%d * %d = %d \n”, num, i, num *i);
}
}
}

OUTPUT
Enter the Multiplication Table Number: 10
10 * 1 = 10
10 * 2 = 20
10 * 3 = 30
10 * 4 = 40
10 * 5 = 50
10 * 6 = 60
10 * 7 = 70
10 * 8 = 80
10 * 9 = 90
10 * 10 = 100

RESULT
Program executed successfully and Output verified.
19. PROGRAM TO FIND THE AREA OF RECTANGLE
AIM
To write a Java program to find the Area of Rectangle by getting the
input of length and breadth from the user during run time.

PROGRAM CODE
import java.util.Scanner;
public class AreaOf Rectangle
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println(“Enter the length of the Rectangle:”);
double l = s.nextDouble();
System.out.println(“Enter the width of the Rectangle:”);
double b = s.nextDouble();
double area = l *b;
System.out.println(“Area of Rectangle is:” + area);
}
}

OUTPUT
Enter the length of the Rectangle:
5
Enter the width of the Rectangle:
6
Area of Rectangle is: 30.0

RESULT
Program executed successfully and Output verified.
20. GENERATE FIBONACCI SERIES

AIM
To write a java program to print the FIBONACCI Series .

PROGRAM CODE
import java.util.Scanner;
class Fibonacci
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println(“Enter number of terms”);
int n=s.nextInt();
int num1=-1, num2=1; num3=0;
System.out.println(“Fibonacci series is”);
for(int i=0; i<n; i++)
{
num3 = num1+num3;
num1=num2;
num2=num3;
System.out.println(num3);
System.out.println(“\t”);
}
}
}
OUTPUT
Enter number of terms
10
Fibonacci series is
0 1 1 2 3 5 8 13 21 34

RESULT
Program executed successfully and Output verified.
21.PRINT THE FACTORIAL OF A GIVEN NUMBER
AIM
To write a Java program to print the factorial of a given number

PROGRAM CODING
import java.util.Scanner;
public class Factorial
{
public static void main(String[] args)
{
int n,fact=1;
Scanner s=new Scanner(System.in);
System.out.println(“Enter a number:”);
n=s.nextInt();
for(int i=1; i<=n; i++)
{
fact=fact*i;
}
System.out.println(“Factorial of the given number”+n + ”is” +fact);
}
}

OUTPUT
Enter a number:
5
Factorial of the given number is 120

RESULT
Program executed successfully and Output verified.
22. PROGRAM TO IDENTIFY WHETHER THE GIVEN CHARACTER IS
VOWEL, CONSONANT OR NOT AN ALPHABET.

AIM

To write a program to identify whether the given character is vowel,


consonant or not an alphabet.

PROGRAM CODE
import java.util.Scanner;
class JavaExample
{
public static void main(String[]arg)
{
boolean isvowel=false;
Scanner scanner=new scanner(System.in);
System.out.println(“Enter a Character:”);
Char ch=Scanner.next(), charAt(0);
Scanner close();
Switch(ch)
{
case ‘a’:
case ‘e’:
case ‘i’:
case ‘o’:
case ‘u’:
case ‘A’:
case ‘E’:
case ‘I’:
case ‘O’:
case ‘U’:
isvowel=true;
}
if(isvowel==true)
{
System.out.println(ch +”is a Vowel”);
else
{
if((ch>=’a’ && ch<=’z’) || (ch>=’A’ && ch<=’Z’))
System.out.println(ch+ “is a consonant”);
else
System.out.println(“Input is not an alphabet”);
}
}
}

OUTPUT 1
Enter a Character:
A
A is a Vowel

OUTPUT 2
Enter a Character:
p
p is a consonant

OUTPUT 3
Enter a Character:
7
Input is not an alphabet

RESULT
Program executed successfully and Output verified.
23. CONSTRUCTOR IN JAVA
AIM

To write a Java program to implement constructor.

PROGRAM CODE:
package helloworld;
public class Constructor
{
String studentName;
int studentAge;
Constructor( )
{
studentName = “Ankit”;
studentAge = 25;
}
public static void main(String args[])
{
Constructor s1 = new Constructor();
System.out.println(s1.studentName);
System.out.println(s1.studentAge);
}
}

OUTPUT
Ankit
25

RESULT
Program executed successfully and Output verified.
24. ARRAY MANIPULATION
AIM
To write a program to implement Array manipulation

PROGRAM CODE
package javaprograms;
import java.util.Arrays;
public class ArraySortDemo2
{
public static void main(String[] args)
{
String*+ names = (“Sleepy”, “Doc”, ”Happy” , “Grumpy’, “Bashful”);
System.out.println(“Names Array before sorting’);
for(int i = 0; i<names.length; i++)
System.out.print(names*i+ + “ , “);
System.out.println();
Arrays.sort(names);
System.out.println(“Names Array after sorting”);
for(int i = 0; i<names.length; i++)
System.out.print(names*i+ + “ , “);
System.out.println();
}
}

OUTPUT
Names Array before sorting:
Sleepy, Doc, Happy, Grumpy, Bashful
Names Array after sorting:
Bashful, Doc, Grumpy, Happy, Sleepy

RESULT
Program executed successfully and Output verified.
25. ARRAY USING BINARY SEARCH
AIM

To write a Java code to search an element from the array using binary
search technique.

PROGRAM CODE

package javaprograms;
import java.util.Arrays;
import java.util.Scanner;
public class ArraySearchDemo
{
public static void main(String[] args)
{
double[] marks = {36, 144, 103, 256.5, 387.5};
Scanner user_input = new Scanner(System.in);
System.out.printl(“Enter number to search:”);
int key = Integer.parseInt(user_input.next());
int index = Arrays.binarySearch(marks,key);
if(index != -1)
System.out.println(“Element found at position “+ (index+1));
else
System.out.println(“Element not found”);
}
}

OUTPUT
Enter number to search: 103
Element found at position 3

RESULT
Program executed successfully and Output verified.
26. STRING MANIPULATION
AIM
To write a Java program to implement String manipulation.

PROGRAM CODE

package javaprograms;
public class StringDemo
{
public static void main(String[] args)
{
String mysting = “Hello World”;
System.out.println(“Given String: “ +mystring);
System.out.println(“charAt position 6: “ +mystring.charAt(6));
System.out.println(“Concat ‘Today’: “ +mystring.concat(“Today”));
System.out.println(“Contains ‘Hell’: “ +mystring.contains(“Hell”));
System.out.println(“endsWith ‘old’: “ +mystring.endsWith(“old”));
System.out.println(“equals ‘Goodbye World’: “
+mystring.equals(“Goodbye world”));
System.out.println(“equalsIgnoreCase ‘hello world’ : “
+mystring.equalsIgnoreCase(“hello world”));
System.out.println(“indexOf W: “ +mystring.indexOf(“W”));
System.out.println(“indexOf ‘rld’: “ +mystring.indexOf(“rld”));
System.out.println(“isEmpty: “ +mystring.isEmpty());
System.out.println(“length: “ +mystring.length());
System.out.println(“replace 1 with * :” +mystring.replace(‘l’ , ’*’));
System.out.println(“replace ‘Hello’ with ‘Yellow’: “
+mystring.replace(“Hello”, “Yellow”));
System.out.println(“Lowercase: “ +mystring.toLowercase());
System.out.println(“UpperCase:” +mystring.toUppercase());
}
}
OUTPUT

Given String: Hello World


CharAt position 6: W
Concat ‘Today’: Hello World Today
Contains ‘Hell’: true
endsWith ‘old’: false
equals ‘Goodbye World’: false
equalsIgnoreCase ‘hello world’: true
indexOf W: 6
indexOf ‘rld’: 8
isEmpty: false
length: 11
replace l with * : He**o Wor*d
replace ‘Hello’ with Yellow’ : Yellow world
LowerCase : hello world
UpperCase: HELLO WORLD

RESULT
Program executed successfully and Output verified.
27. EXCEPTION HANDLING IN JAVA
AIM
To write a program to implement concept of Exception Handling.
PROGRAM CODE
import java.util.Scanner;
public class BookTest
{
static int divide(int dividend, int divisor)
{
return dividend/divisor;
}
public static void main(String[] args)
{
System.out.println(“Enter the Dividend and Divisor: “);
Scanner user_input = new Scanner(System.in);
int divid = user_input.nextInt();
int divis = user_input.nextInt();
try
{
int number = divide(divid,divis);
System.out.println(number);
}
catch(Exception e)
{
System.out.println(“Caught Exception while trying to divide 100 by zero : “+e.getmessage());
}
}
}
OUTPUT
Enter the Dividend and Divisor:
40
0
Caught Exception while trying to divide 100 by zero : / by zero

RESULT: Program executed successfully and Output verified.


28. IMPLEMENT ASSERTION
AIM
To write a program to implement assertion.
PROGRAM CODE
package javaprograms;
import java.util.Scanner;
public class AssertDemo
{
public static void main (String args[])
{
Scanner scanner = new Scanner(System.in);
System.out.print(“Enter the age of the client:”);
int age = scanner.nextInt();
assert age >= 18:”Age not Valid”;
System.out.println(“Age is “+ age);
}
}

OUTPUT
Enter the age of the client: 13
Exception in thread “main” java.lang.AssertionError: Age not Valid
At javaprograms.AssertionDemo.main(AssertionDemo.java:11
Java Result: 1

RESULT
Program executed successfully and Output verified.
29. IMPLEMENT THREADS BY EXTENDING THREAD CLASS
AIM
To Write a program to implement Threads by extending thread class.
PROGRAM CODE
package javaprograms;
public class ExtendThread extends Thread
{
public void run()
{
System.out.println(“Created a Thread”);
for(int count = 1; count<=3; count++)
System.out.println(“Count”+count);
}
public static void main(String args[])
{
ExtendThread t1 = new ExtendThread();
ExtendThread t2=new ExtendThread();
t1.start();
t2. Start();
}
}

OUTPUT
Created a Thread
Created a Thread
Count=1
Count=1
Count=2
Count=2
Count=3
Count=3

RESULT
Program executed successfully and Output verified.
30. IMPLEMENT THREADS BY IMPLEMENTING RUNNABLE INTERFACE
AIM
To write a program to implement Threads by implementing Runnable
interface.
PROGRAM CODE
package javaprograms;
public class BookTest implements Runnable
{
public void run()
{
System.out.println(“Created a Thread”);
for(int count = 1; count<=3; count++)
System.out.println(“Count”+count);
}
public static void main(String args[])
{
BookTest r =new BookTest();
Thread t1 = new Thread(r);
Thread t2=new Thread(r);
t1.start();
t2. Start();
}
}
OUTPUT
Created a Thread
Created a Thread
Count=1
Count=1
Count=2
Count=2
Count=3
Count=3

RESULT
Program executed successfully and Output verified.

You might also like