Java Workbook Unit-4 5 6

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

ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

COMPUTER ENGINEERING

SEM – IV YEAR – 2023-24

Name of Student:- ________________________________________________________

Class & Division :-________________________________

Roll no :-________________________________________

Subject :- Java Programming(22412)

1
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

UNIT NO – 4 Exception & Multithreading

Q1. Difference Between Error & Exception 2 marks


Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
Q2. Define error. List types of error. 2 Marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q3. Explain what is Exception & List types of Exception. 2 marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

2
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

Q4. Enlist any four compile time errors. 2 Mark


Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q5. Write the syntax of try-catch-finally blocks. 2 Mark


Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
______________________________________________________________________
Q6. State and Explain built-in exceptions. 4 marks
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
3
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________
Q7. WAP to show the Arithmatic Exception for Divide by zero Accept the value from
user. Or .Write a program to create a user defined exception in java. 4 marks
Ans._____________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

4
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
Q 8. Differenciate between Throw and Throws. 4 marks
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q9. Write a program that throws an exception called "NoMatchException” when a
string is not equal to "India". 6 Marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
5
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q10. Write a program to input name and salary of employee and throw user
defined exception if entered salary is negative. 6 marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________

6
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
7
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

Q11. WAP to show Voting Exception where age<18 then display “You cannot vote”.
Else increase vote count. 6 marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
8
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q12. Explain Thread life Cycle in details with neat diagram 6 marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
9
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q.13 Explain the two ways of creating threads in Java. 4 marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
10
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q14. WAP using Thread class . 4 marks
Ans
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
11
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q.15 WAP using Runnable interface . 4 marks
Ans
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________
12
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

Q16. Explain the term Synchronization in Java with Example? 4 marks


Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
13
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

Q17. Explain the term Deadlock in Java? 2 mark


Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q18 . Give a syntax of following thread method 2 marks
i) Notify ( ) ii) Sleep ( ) iii)NotifyAll()
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q19. Differentiate between starting thread with run( ) method and start() method. 2
Mark
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
14
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________

Q20. Write a program to print even and odd number using two threads with delay
of 1000ms after each number. 6 marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
15
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q21. i) Explain Errors and its types in detail.
ii) Explain thread methods to set and get priority. 6 Marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
16
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q22. Write a Java program in which thread A will display the even numbers
between 1 to 50 and thread B will display the odd numbers between 1 to 50.
After 3 iterations thread A should go to sleep for 500ms. 6 Marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
17
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q23. Explain the functions of Thread.
1.Yield() 2.Suspend() 3. Wait() 4. Resume() 5.. Sleep() 6. Notify() 6 marks
Ans______________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
18
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
19
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

UNIT NO – 5 Applet Programming

Q1. Difference between Applet and Application 4 marks


Ans
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q2. Explain in details Applet Life Cycle. 4 marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
____. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

20
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
____. ____________________________________________________________________
Q3. Give a syntax of <param)>tag to pass parameters to an applet. 2 Marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q4. State the classes that can an applet extend. 2 Marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q5. Explain how to pass parameter to an applet ? Write an applet to accept username
in the form of parameter and print “Hello <username>” 6 marks.

_________________________________________________________________________
_________________________________________________________________________
21
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q6. Write syntax of elipse. 2 Marks


Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

22
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

Q7. Write an applet program for following graphics method.


i) Drawoval ( ) /Filloval()
ii) DrawPolygon ( ) 4 marks
Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

23
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

Q8. Write a program to generate following output using drawline () method. Refer
Fig. No. 2. 4 Marks

Ans. ____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q9. Explain any four font methods with example. 4 Marks


Ans. ____________________________________________________________________

24
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
____________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________
Q10. Explain
i) drawLine
ii) drawOval
iii) drawRect
iv) drawArc 4 Marks
Ans
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
25
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q11. Describe the use of following methods:
(i) filloval ( )
(ii) getFont ( )
(iii) fillRect ( )
(iv) getFamily ( ) 4 Marks
Ans
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

26
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q13. Write a program to draw a chessboard in Java Applet 6 MARKS

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

27
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q14. Write a Java applet to draw a bar chart for the following values. 6 Marks
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

28
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q15. WAP to generate the following Applet. 6 marks

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
________________________________________________________________________
29
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

UNIT NO – 6 File Handling

Q1. Define stream class and list types of stream class. 2 marks
Ans.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q2. Give syntax to open a file using Inputstream class. 2 marks


Ans
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q3. Explain any two methods of File Class 2 marks


Ans.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

30
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

Q4. List the various functions in Files?


Ans______________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q5. Write a program for reading and writing character to and from the given files
using byte stream classes. 4 marks.
Ans.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

31
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

Q6. Write a program for reading and writing character to and from the given files
using character stream classes. 4 marks.
Ans.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q7. Write a program to read a file and then count number of words. 4 marks
Ans._____________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
______________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
32
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q8. Enlist types of Byte stream class and describe input stream class and output
stream class. 4 marks
Ans.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

33
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

Q9. Explain the following classes. 4 marks


i)Byte stream class
ii)Character Stream Class
Ans.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q10. Distinguish between Input stream class and output stream class. 4 marks
Ans.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

34
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q11. Enlist any four methods of file input stream class and give syntax of any
two methods. 4 Marks
Ans.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________

35
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q12. Write a program to append content of one file into another file. 4 Marks

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
36
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Q13. Write a program to count number of words from a text file using stream classes.
(Note : Any other relevant logic shall be considered) 6 Marks

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

37
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q14. Write a program to copy content of one file to another file. 4 Marks

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

38
ZEAL EDUCATION SOCIETY’S

ZEAL POLYTECHNIC, PUNE.


NARHE │PUNE -41 │ INDIA

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Q15. Explain 4 marks
1. FileReader & FileWriter class
2. Bufferreader & BufferWriter class
Ans.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
39

You might also like