Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
209 views

Java Practice - Questions

This document contains 16 questions related to multi-threaded programming in Java. The questions cover topics such as the life cycle of a thread, what multi-threaded programming is, how to count characters in a file using threads, creating and running multiple threads to display even and odd numbers, what thread synchronization is, differences between input/output streams and readers/writers, how to read and write text files, how to copy files, creating and serializing objects to files, creating arrays of objects and retrieving from files, naming and displaying thread names, explaining serialization and deserialization using Serializable interface, and briefly explaining ByteArrayInputStream, ByteArrayOutputStream, CharArrayReader, CharArrayWriter, FileReader, and FileWriter classes

Uploaded by

Lakshay Chauhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
209 views

Java Practice - Questions

This document contains 16 questions related to multi-threaded programming in Java. The questions cover topics such as the life cycle of a thread, what multi-threaded programming is, how to count characters in a file using threads, creating and running multiple threads to display even and odd numbers, what thread synchronization is, differences between input/output streams and readers/writers, how to read and write text files, how to copy files, creating and serializing objects to files, creating arrays of objects and retrieving from files, naming and displaying thread names, explaining serialization and deserialization using Serializable interface, and briefly explaining ByteArrayInputStream, ByteArrayOutputStream, CharArrayReader, CharArrayWriter, FileReader, and FileWriter classes

Uploaded by

Lakshay Chauhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ASSIGNMENT-2

Question 1
Explain the life cycle of a thread.

Question 2
What is multi-threaded programming?

Question 3
File : Count Character
Write a program to count the number of times a character appears in the File. (Case insensitive...
'a' and 'A' are considered to be the same)

Sample Output:
Enter the file name
Input.txt
Enter the character to be counted
r
File 'Input.txt' has 99 instances of letter 'r'.

Question 4
Create two threads, one thread to display all even numbers between 1 & 20, another to display
odd numbers between 1 & 20.
Note: Display all even numbers followed by odd numbers
Hint: use join

Question 5
What is Thread Synchronization?

Question 6
What is common and how do the following streams differ: InputStream, OutputStream, Reader,
Writer?

Question 7
How do you read/write a text file in Java?

Question 8
Write a program to copy from one file to another.

Question 9
Create an employee object having properties name, date of birth, department, designation and
salary. Let the employee class have appropriate getter/setters methods for accessing these
properties. Initialize these properties through the setter methods. Store this object into a file
"OutObject.txt". Read the same object from the same file and display its properties through
getter methods.
Question 10
Create a student class object array of size four having attributes name, designation and salary.
Let the student class have appropriate getter/setters methods for accessing these attributes.
Initialize these attributes through the setter methods. Store this object into a file "OutObject.txt".
Read the objects from the same file and display the attributes of object through getter methods
where name is equal to “rajiv” (ignoring case) else display the following message “The required
information is not found in file”.

Question 11
Create two threads and assign names ‘Scooby’ and ‘Shaggy’ to the two threads. Display both
thread names.

Question 12
Explain serialization and Deserialization using Serializable interface.

Question 13
Briefly explain ByteArrayInputStream and ByteArrayOutputStream.

Question 14
Briefly explain CharArrayReader and CharArrayWriter.

Question 15
Briefly explain FileReader and FileWriter.

Question 16
1. Create a class of SalesPersons as a thread that will display five salespersons names.
2. Create a class as Days as other Thread that has an array of seven days.
3. Call the instance of SalesPersons in Days and start both the
threads
4. suspend SalesPersons on Sunday and resume on Wednesday
Note: use suspend, resume methods from the thread

You might also like