Oops-Insem2-Anskey (2022)
Oops-Insem2-Anskey (2022)
Q1. Which of these access specifiers can be used for an interface? (0.5)
1. **public
2. protected
3. private
4. All of these
Q2. Which of these keywords is used by a class to use an interface defined previously? (0.5)
1. **implements
2. import
3. export
4. define
Q3. Which of these keywords must be used to monitor for exceptions? (0.5)
1. catch
2. **try
3. finally
4. throw
(0.5)
1. Exception
2. Exceptionhandled
3. **handled
4. No output
Q6. Which of these methods of Thread class is used to find out the priority given to a thread? (0.5)
1. ** getPriority()
2. getThreadPriority()
3. threadPriority()
4. priority()
Q7. Which function of Thread class is used to check weather current thread being checked is still
running? (0.5)
1. alive()
2. **isAlive()
3. isRunning()
4. run()
Q8. Which of these classes is/are used for input and output operation when working with bytes?
(0.5)
1. Reader
2. **InputStream
3. Writer
4. All of these
Q9. Which of the following classes is not related to input and output stream in terms of functioning?
(0.5)
1. Reader
2. **File
3. Writer
4. InputStream
Q10. Which of these is a process of writing the state of an object to a byte stream?
(0.5) 1. **Serialization
2. Deserialization
3. Externalization
4. File filter
Type: DES
Q11. Write a java program to input Registration number, city, average mark, email id of the student,
and validate the input data as per following criteria using exception handling technique:
i. Average mark must be between 0 and 100.
ii. Check for validity of email id (valid if ends with gmail.com or manipal.edu).
(2)
Scheme:
class StudData_Exception extends Exception //user defined exception class
public StudData_Exception(String s)
super(s);
class StudData_Exception_main
if(avg_marks<0 || avg_marks>100)
else
String em[]=email.split("@");
if(em[1].equalsIgnoreCase("gmail.com") ||em[1].equalsIgnoreCase("manipal.edu"))
else
try
obj.avg_markCheck(-10);
obj.emailCheck("[email protected]");
Q12. The following program is used to copy the content of source.txt into dest.txt. Identify the
mistake if there is any, and suggest your solution.
(2)
Scheme:
Error in Line-12 : FileReader object (ie file_in) must be used to invoke read() method.
Error in Line-14: FileWriter object (ie file_out) must be used to invoke write() method.
Identification of mistake in Line-12 → 0.5M
Solution → 0.5M
Identification of mistake in Line-14 → 0.5M
Solution → 0.5M
Q13. Write a program to read all lines from the file “sample.txt” in class “ReadLine” and store them
in string “s1”. The method “process()” searches for string “s2” and replaces it with string “s3”. The
updated string “s1” should be stored in the file “updated.txt” through method “fileUpdate()”. The
main class “MainClass” creates objects and calls the methods to do tasks. Consider suitable
exceptions in the program. (3)
Scheme:
Reading file “sample.txt” → 0.5
Storing the contents of “sample.txt” in s1 → 0.5
Search for s2 in process() → 0.5
Replace s2 with s3→ 0.5
File update() → 0.5
Main class→ 0.5
Q14. Develop a multithreaded application in java to perform array operations as follows:
MainThread: Read input elements from the keyboard and store them in an array, also display
the count of odd and even numbers obtained from the following threads:
Thread-1: Display all the odd numbers present in the array.
Thread-2: Display all even numbers present in the array.
Note: Create the threads using Runnable interface to perform the above operations. (3)
Scheme:
import java.util.Scanner;
class MyThread implements Runnable
{
private int Thread_Num;
private int Arr[];
private int count = 0;
MyThread( int no , int A[] )
{
Thread_Num = no;
Arr = A;
}
public void run()
{
if( Thread_Num == 1)
display_even();
if( Thread_Num == 2)
display_odd();
}
public void display_even()
{
System.out.println("The even values are:");
for( int ele : Arr )
{
if( ele % 2 == 0 )
{ count++;
System.out.println(ele);
}
}
}
class MultiThread_ArrDemo
{
public static void main(String[] args) throws Exception
{
System.out.println("Main thread starting.");
Scanner S = new Scanner(System.in);
System.out.println("Enter how many values:");
int size = S.nextInt();
int Arr[] = new int[size];
System.out.println("Enter the values:");
for( int i = 0 ; i < size ; i++)
Arr[i] = S.nextInt();
T1.start();
T1.join();
T2.start();
T2.join();