Java Week13
Java Week13
NAME : T.SHRAVAN
ROLLNO : 20075A1207
UNIT-1
WEEK-1 UNIT-I
SL.NO DESCRIPTION OF THE PROGRAM
1. Steps for installation of Java
2. Write a java program to display a simple message
3. Write a java program to display multiple lines (may be
student details) using +
4. Write a java program to display addition of two numbers
5. Write a java program to display area of circle
6. Write a java program to display factorial of a number
7. Write a java program to read an integer value using
Scanner Class
8. Write a java program to reverse a number
9. Write a java program to read float, long int, char, string
value using Scanner Class
10. Write a Java program that uses both recursive and non-
recursive functions to print the nth value in the Fibonacci
sequence
WEEK-2 UNIT-I
SL.NO DESCRIPTION OF THE PROGRAM
11. Write a Java program to print all the twin primes below
1000. (A twin prime is a Prime number that differs from
another prime number by two. (3, 5), (5, 7), (11, 13),(17,
19), (29, 31), (41, 43), .821, 823), etc.
12. Write a Java program that prompts the user for an integer
and then prints out all prime Numbers up to that integer.
13. Write a Java program that prints all real solutions to the
quadratic equation ax2 + bx +C = 0. Read in a, b, c and use
the quadratic formula. If the discriminant b2 - 4ac is
Negative, display a message stating that there are no real
solutions.
14. Write a java program to display ASCII characters.
15. Write a java program to illustrates if and switch selection
statements.
16. Write a java program to simulate a calculator.
17. Write a java program to demonstrate Arithmetic, Bitwise,
and relational operators.
18. Write a java program to demonstrate Assignment and?
Operators.
19. Write a java program to demonstrate iteration statement-
while.
20. Write a java program to demonstrate iteration statement-
DO while.
21. Write a java program to demonstrate iteration statement
– for.
22. Write a java program to demonstrate jump statements
break, continue and return.
WEEK-3 UNIT-I
SL.NO DESCRIPTION OF THE PROGRAM
23. Write a java program to demonstrates scope and lifetime
of a variable.
24. Write a java program to evaluate any mathematical
expression to illustrate operator precedence and its
associativity.
25. Write a java program to demonstrates widening
conversion for all data types.
26. Write a java program to demonstrates narrowing
conversion for all data types.
27. Write a java program to demonstrates type promotion.
28. Write a java program to display the following output using
two dimensional array
0123
4567
8 9 10 11.
29. Write a java program to compute sum of array elements
using for each.
30. Write a java program to implement matrix addition (Use
Scanner Class).
31. Write a java program to implement matrix multiplication
(Use Scanner Class).
32. Write a java program to demonstrate ‘Wrapper classes’ .
WEEK-4 UNIT-II
SL.NO. DESCRIPTION OF THE PROGRAM
33. Write a java program that shows how to declare an object
for a class and adding methods.
34. Write a java program that shows how to declare an object
for a class and adding multiple methods that also take
arguments.
35. Write a java program to add some methods with
parameters and return values.
36. Write a java program which shows accessibility of private
and public methods.
37. Write a java program to demonstrate nested functions.
38. Write a java program to create array of objects .
39. Write a java program to demonstrate access specifiers-
private ,public and default .
40. Write a java program to demonstrate the keyword ‘this’.
41. Write a java program to demonstrate the usage of ‘this’
keyword -to refer current class instance variable .
42. Write a java program to demonstrate the usage of ‘this’
keyword -to invoke current class method.
43. Write a java program to demonstrate the usage of ‘this’
keyword -to invoke current class constructor.
44. Write a java program to demonstrate the usage of ‘this’
keyword – reusing constructor .
WEEK-5 UNIT-II
SL.NO. DESCRIPTION OF THE PROGRAM
45. Write a java program that shows deallocation of memory
using System. gc () method.
46. Write a java program to demonstrates method
overloading.
47. Write a java program to implement.
A) Default Constructor b) Parameterized Constructor
48. Write a java program to demonstrates copy constructor
(object as a parameter to the constructor).
49. Write a java program to implement constructor
overloading.
50. Write a java program to demonstrates static variables .
51. Write a java program to demonstrates static methods.
52. Write a java program to demonstrates static blocks.
53. Write a java program to demonstrates static nested
classes .
54. Write a java program to implement the use of inner
classes(non-static classes).
55. Write a java program to demonstrates call by value .
56. Write a java program to demonstrates call by reference .
57. Write a java program to implements variable length
arguments.
WEEK-6 UNIT-II
SL.NO DESCRIPTION OF THE PROGRAM
58. Write a java program that uses the methods valueOf() and
String().
59. Write a java program that uses the methods
length(),getChar() and equals().
60. Write a java program that uses the methods
compareTo(),regionMatches(),indexOf() and lastIndexOf()
61. Write a java program that uses the methods
substring(),startsWith() and endsWith().
62. Write a java program that uses the methods
concat(),replace() and trim()
63. Write a java program that uses the methods
toLowerCase(),toUpperCase() and toCharArray()
64. Write a java program to check the input characters for
uppercase,lowercase,no.of digits ,whether any white
space characters and other characters
65. Write a java program that performs operations on
StringBuffer class.
66. Write a java program that uses the methods append() and
insert() on StringBuilder class
67. Write a java program for sorting a given list of names in
ascending order .
68. Write a java program that checks whether a given string is
a palindrome or not.
Ex:MALAYALAM is palindrome.
WEEK-7 UNIT-II
SL.NO. DESCRIPTION OF THE PROGRAM
69. Write a java program to implement single inheritance
70. write a java program to implement multilevel inheritance
71. write a java program to implement hierarchical
inheritance
72. write a java program that shows how constructors are
executed in inheritance
73. Write a java program that shows how to call superclass
constructors using ‘super’
74. Write a java program that shows how to call superclass
variable using ‘super’
75. Write a java program that overrides the methods
76. Write a java program that shows how a superclass variable
can refer a subclass object
77. Write a java program to demonstrate the keyword ‘final’
78. Write a java program that shows how to prevent
overriding with final keyword
79. Write a java program to demonstrate Dynamic Method
Dispatch / Runtime Polymorphism
80. Write a java program that uses Abstract Classes
WEEK-8 UNIT-III
SL.NO. DESCRIPTION OF THE PROGRAM
81. Write a java program that illustrates Creation of package
&Accessing a package
82. Write a java program that shows how to access variables
in same class in same package
83. Write a java program that shows how to access variables
in same package subclass
84. Write a java program that shows how to access variables
in same package non-subclass
85. Write a java program that shows how to access variables
in different package subclass
86. Write a java program that shows how to access variables
in different package non-subclass
87. Write a java program to implement interfaces
88. Write a java program to illustrate nested interfaces
89. Write a java program to extend interfaces
WEEK-9 UNIT-III
SL.NO. DESCRIPTION OF THE PROGRAM
90. Write a java program to display description of an
exception
Write a Java program that illustrates built in exceptions
91. Write a java program to demonstrate multiple catch
statements
92. Write a java program to demonstrate nested try
statements
93. Write a java program to demonstrate the keyword
„throw‟
94. Write a java program to rethrow an exception object
95. Write a java program to demonstrate the keyword
„throws‟
96. Write a java program to demonstrate the keyword
„finally‟
97. Write a java program to create our own exception subclass
98. Write a Java program to throw an exception “Insufficient
Funds” while withdrawing the amount in the user account.
WEEK-10 UNIT-IV
SL.NO DESCRIPTION OF THE PROGRAM
99. Write a Java program to perform the following operations
on ArrayList.
a)Insertion b)Deletion c)Retrieval
100. Write a Java program to perform the following operations
on LinkedList.
a)Insertion b)Deletion c)Retrieval
101. Write a Java program to perform the following operations
on Vector.
a)Insertion b)Deletion c)Retrieval
102. Write a Java program to perform the following operations
on Stack.
a)Insertion b)Deletion c)Retrieval
103. Write a Java program to perform the following operations
on PriorityQueue.
a)Insertion b)Deletion c)Retrieval
104. Write a Java program to perform the following operations
on ArrayDeque.
a)Insertion b)Deletion c)Retrieval
105. Write a Java program to perform the following operations
on Deque with LinkedList.
a)Insertion b)Deletion c)Retrieval
106. Write a Java program to perform the following operations
on HashSet.
a)Insertion b)Deletion c)Retrieval
107. Write a Java program to perform the following operations
on LinkedHashSet.
a)Insertion b)Deletion c)Retrieval
108. Write a Java program to perform the following operations
on TreeSet.
a)Insertion b)Deletion c)Retrieval
109. Write a Java program to perform the following operations
on HashMap.
a)Insertion b)Deletion c)Retrieval
110. Write a Java program to perform the following operations
on LinkedHashMap.
a)Insertion b)Deletion c)Retrieval
111. Write a Java program to perform the following operations
on TreeMap.
a)Insertion b)Deletion c)Retrieval
112. Write a Java program to perform the following operations
on HashTable.
a)Insertion b)Deletion c)Retrieval
113. Write a program to store Employee objects in a TreeSet
and sort the objects based on employee salary using
Comparator/Comparable.
114. Write a java program to illustrates the usage of
StringTokenizer class.
115. Write a java program to illustrates the usage of Arrays
class.
WEEK-11 UNIT-V
SL.NO DESCRIPTION OF THE PROGRAM
116. Write a java program for creating multiple threads using
Thread class.
117. Write a java program for creating multiple threads using
Runnable Interface.
118. Write a java program for creating multiple threads.The
main method sleep for 10 seconds at the end of which all
threads should be terminated.
119. Write a java program about thread priorities.
120. Write a java program that creates two threads. First
thread displays even numbers and second thread displays
odd numbers upto 20 for a sleep of 1 second.
121. Write a java program 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.
122. Write a java program that uses the methods isAlive() and
join().
123. Write a java program to demonstrate synchronized
method.
124. Write a java program to demonstrate synchronized block.
125. Write a java program about producer consumer problem
without using wait() and notify() methods.
126. Write a Java program that correctly implements producer
consumer problem using the concept of inter thread
communication.
127. Write a java program to demonstrate Thread Group class.
128. Write a java program to demonstrate Daemon Threads.
129. Write a java program to illustrates Deadlock in
Multithreading.
WEEK-12 UNIT-V
SL.NO. DESCRIPTION OF THE PROGRAM
130. Write a Java program that reads on file name from the
user then displays information about whether the file
exists, whether the file is readable/writeable/executable,
the absolute and relative path, the contents of file and the
length of the file in bytes.
131. Write a java program to list out files in a directory.
132. Write a java program to read your name, roll number,
address and marks obtaining in Java,FLAT,CO,SE….. from
keyboard and place it in the file.
133. Write a Java program that uses the class FileInputStream
and FileOutputStream.
134. Write a Java program that uses the class ByteInputStream
and ByteOutputStream.
135. Write a Java program on FileReader and FileWriter.
136. Write a Java program to create a file and write data into
the file using Character Stream.
137. Write a java program to illustrates Serialization.
WEEK-13 UNIT-VI
SL.NO DESCRIPTION OF THE PROGRAM
138. Write a Java program to establish the connection to mysql
database.
139. Write a Java program to create
Student/Employee/Bookshop database in Mysql.
140. Write a Java program to establish the connection to the
database and perform the following operations.
a)Retrieval b)Insertion c)Deletion
141. Write a Java program to illustrates Prepared Statement
Interface.
142. Write a Java program to illustrates Callable Statement
Interface.
143. Write a Java program that demonstrates Transactions in
JDBC.
144. Write a Java program that demonstrates Batch Processing
in JDBC.
WEEK-1
1) Steps for installation of Java
i)For installing Java and setting up Java environment , we have to download JDK
which stands for Java Development Kit which consists of JRE and JVM.
ii)For downloading JDK, we have to go on to Google and search “Java JDK download” and
then it will show the relevant results.
iii)Then click on the first result which is of oracle website and shows JAVA-SE Downloads
page by which Java is maintained By Oracle Company.
iv)Then the downloads page of Java SE will open showing jdk download links.
v)Click on jdk 16 which is the latest version of jdk download And this will open up several jdk
download links depending upon your operating systems either Windows,Mac or Linux.
vi)Select your desired operating system jdk file and this will download your desired jdk file.
vii)After completion of downloading jdk file, double click on jdk file or either open the file in
order to install into the operating system.
viii)This will show dialog box containing program files and jre libraries and other class
libraries and then click on next and click another next.
ix)Next if we go to our C drive and check the program files we can see that there is a folder
named Java which consists of jdk 16 and other java files including bin.
x)That’s it we have installed Java into our operating system. But we have to set path to our
Java files to run it from command line because Java follows “Write Once Run Anywhere”
principle.
xi)Go to Search bar and type “advanced system settings”.This will show up “View advanced
system settings” result.
xii)Click on that search result and this will show up a dialog box containing advanced settings
to our computer and there is a button at the end named “Environment Variables”.Click on
that button to see the System variables and User defined variables dialog box.
xiii)In this dialog box go to System variables and this will contain different types of system
variables.Click on “Path” System Variable and click on Edit.
xiv)To this Path Variable We have to add Our java path. So, we will go to C drive and then
Program Files And then go to Java and then next go to jdk 16 and then next select bin folder
and then finally copy the path which will be shown in the address bar like ”C:\Program
Files\Java\jdk 16\bin”.
xv)Finally,add this path to our Path System Variable in Environment Variables dialog box,
So,we go to Environment Variables -> System Variables -> Path and then click on Edit.This
Will open a new dialog box consisting of existing paths to the System Path Variable.Now
Click on New button and this will open a text box.Here we add our Java path which we have
Copied and then click on Ok button.
xvi)This has added our java path to the Path Variable.Now we have to create another
System Variable and add the path of java except bin folder.
xvii)So, in System Variables click on New button which will open a new dialog box containing
variable name and variable value.In,Variable name section give the name as “%JAVA_HOME
%” and in the variable value section paste our java path which we have copied earlier and
remove the bin folder section from it. Now click on OK to apply the changes of new System
Variable.The path will be like : ”C:\Program Files\Java\jdk 16”.
xvii)Now click on Ok button in the environment variables to save all the changes that we
have made in our System Variables section.Now,our Java installation has been setup and we
can run any java file using javac command which invokes Java Compiler to compile the given
java file.
xix)Now go to command prompt and then type javac command and this will show several
options that we can include with javac command verifying that java is installed.
xx)To compile Java file, “ javac filename.java”
To run Java file , ‘’ java filename “
This will run our java programs from command line ,but make sure that we go to the
directory where we have saved the java files using cd commands by which we can jump to a
specific folder otherwise system will not locate java files.
2) Write a java program to display a simple message
Program:
OUTPUT:
3)Write a java program to display multiple lines (may be student details ) using +
Program:
Output :
4)Write a java program to display addition of two numbers.
Program:
Output :
Output :
7) Write a java program to read an integer value using Scanner class
Program :
Output :
9)Write a java program to read float ,long ,int ,char , string value using Scanner class
Program :
Output :
10)Write a java program that uses both recursive and non-recursive functions to print the
nth value in the Fibonacci Sequence.
Program :
Outputs :
Program :
Output :
WEEK-2
11) Write a java program to print all the twin primes below 1000.(A twin prime is a prime
number that differs from another prime number by two.(3,5),(5,7),(11,13),(17,19),(29,31),
(41,43),(821,823), etc.
Program :
Output:
12) Write a java program that prompts the user for an integer and then prints out all
prime numbers upto that integer.
Program :
Output:
13)Write a java program that prints all real solutions to the quadratic equation
ax2+bx+c=0.Read in a , b, c and use the quadratic formula. If the discriminant b2-4ac is
negative ,display a message stating that there are no real solutions.
Program:
Output :
Program:
Output:
Output:
16) Write a java program to simulate a calculator.
Program:
Output:
Output:
18) Write a java program to demonstrate Assignment and ? operators.
Program:
Output:
Output:
21)Write a java program to demonstrate iteration statement – for.
Program:
Output:
22)Write a java program to demonstrate jump statements break , continue and return.
Program:
Output:
WEEK-3
23)Write a java program to demonstrate scope and lifetime of a variable .
Program:
Output:
25)write a java program to demonstrates widening conversion for all data types.
Program:
Output:
26)write a java program to demonstrate narrowing conversion for all data types.
Program:
Output:
28)write a java program to display the following output using two dimensional array
0123
4567
8 9 10 11
Program:
Output:
WEEK-4
33) Write a java program that shows how to declare an object for a class and adding
methods.
Program:
Output:
34) Write a java program that shows how to declare an object for a class and adding
multiple methods that also take arguments.
Program:
Output:
35) Write a java program to add some methods with parameters and return values.
Program:
Output:
36) Write a java program which shows accessibility of private and public methods.
Program:
Output:
37) Write a java program to demonstrate nested functions.
Program:
Output:
38) Write a java program to create array of objects .
Program:
Output:
39) Write a java program to demonstrate access specifiers-private, public and default .
Program:
Output:
Output:
42) Write a java program to demonstrate the usage of ‘this’ keyword -to invoke current
class method.
Program:
Output:
43) Write a java program to demonstrate the usage of ‘this’ keyword -to invoke current
class constructor.
Program:
Output:
44) Write a java program to demonstrate the usage of ‘this’ keyword – reusing
constructor .
Program:
Output:
WEEK-5
45) Write a java program that shows deallocation of memory using System. gc () method ?
Program:
Output:
Output:
b) Parameterized Constructor
Program:
Output:
48) Write a java program to demonstrates copy constructor (object as a parameter to the
constructor) ?
Program:
Output:
Output:
Output:
54) Write a java program to implement the use of inner classes(non-static classes) ?
Program:
Output:
Output:
WEEK-6
58) Write a java program that uses the methods valueOf() and String().
Program:
Output:
59) Write a java program that uses the methods length(),getChar(),and equals().
Program:
Output:
Output:
61) Write a java program that uses the methods substring(),startsWith() and endsWith().
Program:
Output:
62) Write a java program that uses the methods concat(),replace() and trim().
Program:
Output:
63) Write a java program that uses the methods toUpperCase(),toLowerCase(),and
CharArray().
Program:
Output:
64)write a java program to check the input characters for uppercase , lowercase , no. of
digits ,whether any white space characters and other characters.
Program:
Output:
65) Write a java program that performs operations on stringBuffer class.
Program:
Output:
66) Write a java program that uses the methods append() and insert() on stringBuilder
class.
Program:
Output:
67) Write a java program for sorting a given list of names in ascending order.
Program:
Output:
68)write a java program that checks whether a given string is palindrome or not.
Program:
Output;
Week-7
69)Write a java program to implement single inheritance.
Program:
Output:
Output:
73) Write a java program that shows how to call superclass constructors using ‘super’
Program:
Output:
74) Write a java program that shows how to call superclass variable using ‘super’
Program:
Output:
76) Write a java program that shows how a superclass variable can refer a subclass object
Program:
Output:
78) Write a java program that shows how to prevent overriding with final keyword
Program:
Output:
WEEK-8
81)Write a java program that illustrates Creation of package &Accessing a package
Program:
Creation of package:
Accessing a package:
Output:
82)Write a java program that shows how to access variables in same class in same
package
Program:
Output:
83)Write a java program that shows how to access variables in same package subclass
Program:
Output:
84)Write a java program that shows how to access variables in same package non-subclass
Program:
Output:
85)Write a java program that shows how to access variables in different package subclass
Program:
Output:
86)Write a java program that shows how to access variables in different package non-
Subclass.
Program:
Output:
WEEK-9
90) Write a java program to display description of an exception
Program:
Output:
98) Write a Java program to throw an exception “Insufficient Funds” while withdrawing
the amount in the user account.
Program:
Output:
WEEK-10
99)Write a Java program to perform the following operations on ArrayList.
a) Insertion operation
Program:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation
Program:
Output:
c)Retrieval operation
Program:
Output:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation
Program:
Output:
102)Write a Java program to perform the following operations on Stack.
a)Insertion operation
Program:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation
Program:
Output:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation
Program:
Output:
104)Write a Java program to perform the following operations on ArrayDeque.
a)Insertion operation
Program:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation
Program:
Output:
105)Write a Java program to perform the following operation on Deque with LinkedList.
a)Insertion operation
Program:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation
Program:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation
Program:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation
Program:
Output:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation
Program:
Output:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation
Program:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation:
Program:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation
Program:
Output:
Output:
b)Deletion operation
Program:
Output:
c)Retrieval operation:
Program:
Output:
113)Write a program to store Employee objects in a TreeSet and sort the objects based on
employee salary using Comparator/Comparable.
Program:
Output:
114)Write a Java program to illustrates the usage of StringTokenizer class.
Program:
Output:
116)Write a java program to illustrates the usage of Arrays class.
Program:
Output:
WEEK – 11
UNIT – V
116)Write a java program for creating multiple threads using thread class.
Program:
Output:
117)Write a java program for creating multiple threads using runnable interface.
Program:
Output:
118)Write a java program for creating multiple threads. The main method sleep for 10
seconds at the end of which all threads should be terminated.
Program:
Output:
119)Write a java program about thread priorities.
Program:
Output:
120)Write a java program that creates two threads. First thread displays even numbers
and second thread displays odd numbers up to 20 for a sleep of 1 second.
Program:
Output:
121)Write a java program 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:
Output:
122)Write a java program that uses the methods isAlive() and join().
Program:
Output:
123)Write a java program to demonstrate synchronized method.
Program:
Output:
125)Write a Java program about producer consumer problem without using wait() and
notify() methods.
Program:
Output:
126)Write a Java program that correctly implements producer consumer problem using
the concept of inter thread communication.
Program:
Output:
127)Write a java program to demonstrate Thread Group class.
Program:
Output:
128)Write a java program to demonstrate Daemon Threads.
Program:
Output:
WEEK-12
UNIT – V
130)Write a Java program that reads on filename from the user then displays
information about whether the file exists, whether the file is
readable/writeable/executable, the absolute and relative path, the contents
of file and the length of the file in bytes.
Program:
Output:
Output:
134)Write a Java program that uses the class ByteInputStream and
ByteOutputStream.
Program:
Output:
135)Write a Java program on FileReader and FileWriter.
Program:
Output:
136)Write a Java program to create a file and write data into file using
Character Stream.
Program:
Output:
UNIT-VI
138)Write a Java program to establish the connection to mysql database.
Program:
Output:
b) Insertion
Program:
Output:
c)Deletion
Program:
Output: