CSE 331 Final
CSE 331 Final
CO2 1. a) 5
For the code segment above, what type of exception will the code throw? How can
we handle the exception? Explain with necessary code.
b) Suppose two different threads are running in the background and are trying to 5
access a single resource at the same time. How can we synchronize the accessing?
Explain with necessary code.
CO3 2. a) Write a program to insert 5 float values in dynamic list. Now take user input for a 5
b) Write a program to create two threads. The 1st thread will print only the odd 5
numbers and the 2 thread will print only the even numbers. Make sure that the 1
nd st
thread gets more priority than the 2nd one while running concurrently.
CO3 3. Imagine you have to write a program in JAVA. In that program you have to input 5
a)
a string. If the string length is less than 8 then you want to show your own error
saying “Too small”. Otherwise show an output saying “All Okay”. Apply the user
defined exception mechanism.
Page 1 of 2
b) Create a class named Course which has the property named course_name(String), 5
course_code(String), course_credit(double) etc. The value of course_name,
course_code and course_credit will be initialized when we create an object of that
class. Make 5 object of Course class and add them into an ArrayList. Those
courses whose credit is over 1.5 will be shown in output. Complete the following
Program.
CO4 4 We will find out the character that gets repeated maximum times in a string. For 5
a)
example, in string “apple”, ‘p’ repeats maximum times. Write a program in Java to
find out the maximum repeated character in a string.
b) Write a code in Java to save user’s data in a file. The program will take input a 5
sentence from user using console and store the sentence in a text file input.txt.
Page 2 of 2