ASSIGNMENT -5(Exception & Multithreading )

estrapadesherbetSoftware and s/w Development

Nov 18, 2013 (3 years and 8 months ago)

90 views



(SVBIT)V
-
CE(JAVA
-
150704)


ASSIGNMENT
-
5
(
Exception & Multithreading
)


1)

Make a program using try
-
catch blocks. If user enters only one command line argument
than throw an exception and if it enters two arguments an
d divides the first argument by
first. If the second argument is zero
than catch the appropriate exception

2)


Write an application that contains a method named average () has one argument that is
an array of strings. It converts these to double values and returns their average. The
method generates a NullPointerException,if a
n array elements is null or a
NumberFormatException, if an element is incorrectly formatted. Include throws
statement in method declaration

3)

Write an application that generates custom exception if any of its command line
arguments are negative
.

4)

Write a prog
ram that accepts the fully qualified name of a class as its argument. Compute
and display how many super classes exist for that class.If a
ClassNotFoundException

occurs, catch it and provide an error message for the user.

5)

A marklist containing reg.no and
marks for a subject is given.if the marks are <0,user
-
defined IllegalMarkException is thrown out and handled with the message “Illegal
Mark”. For all valid marks,the candidate will be declared as “PASS” if the marks are
equal to or greater than 40,otherwis
e it will be declared as “FAIL”.Write a class called
IllegalMarkException.


6)


Write a program to handle NoSuchMethodException, A
rrayIndexOutofBoundsException

With u
sing try, catch, finally & throw

7)

Write a program to handle IntrruptedException, IllegalArg
umentException with using
try,catch, finally & throw.

8)

Write a program that executes two threads. One thread displays “Thread1” every 2,000
milliseconds, and the other displays “Thread2” every 4,000 milliseconds. Create the
threads by extending the
Thread c
lass

or implementing
Runnable interface.

9)

Write a program that executes two threads. One thread will print the even numbers and
the another thread will print odd numbers from 1 to 50.

10)

It is required to have total two threads, both capable of acting as a pro
duce as

well as a
consumer. If first thread acts as a producer then, the second thread

becomes the consumer
and vice
-
versa. They communicate with each other

through a buffer, storing one integer
number. One of the threads initiates the

communication by sen
ding 1 to the other thread.
The second thread, on

receiving 1 sends 2 to the first thread. On receiving 2, the first
thread sends

three integer numbers, one by one to the second thread. The second thread

consumes the numbers by displaying them. Both thread
s terminate after that.

Note that
both threads must be capable of initiating the communication.Write complete multi
-
threaded program to meet above requirements



(SVBIT)V
-
CE(JAVA
-
150704)



ASSIGNMENT
-
6
(
Input Output
)


1)

Write a program to copy one file into another and it takes two i
nput(from command line
argument) one is the name of source file and another is the name of the file into which it
is to be copied

2)

Write a program to replace all “word1” by “word2” from a file1, and output

is written to file2 file and display the no. of rep
lacement.

3)

Write a program to display the bytes of a file in reverse sequence. Provide the name of
the file as a command line argument(Use RandomAccessFile)

4)

Write a program that displays directory tree. The program should accept one command
line argument. i
f this represents a file, its name should be displayed. if this represents a
directory, the program should recursively determine and display all files and directories it
contains
.

5)

Write a standalone program that takes a command line parameter and after ens
uring the
file does not exist. create a file with that name Read customer name(string) and phone
no(integer) form keyboard and store it in file.

6)
Write a program that shows
Calendar

class demo
.


7) Write an application that shows the use of Stack cl
ass.

8)

Write an application that
shows the use of Vector class & Enumeration interface.

9)

Write a program that shows the use of StringTokenizer class.




Tutorial

-
5



1)


Differentiate between

a)

Error & Exception.

b) throw & throws

2)
Name the si
x conditions that generate exception.

3)
Explain custom & built in exception.

4)
What is thread? Explain life cycle of thread.



5)
Why synchronization is required in multithreaded programming and how we implement

it?


6)
Explain
deadlock

in JAVA

wit
h example
.


7)
Explain inter thread communication.

OR (Explain
wait(), notify & notifyall())


8)
Explain
Hashtable

class with example.


9) What is stream? Explain Character stream & Byte stream classes.


10) What is difference between applet & applica
tion? Explain life cycle of applet.


11)
Explain paint(), update() & repaint() methods.


12)
Explain event delegation model.