Practical Assignments
Java Programming
Assignment - Multithreading
1. Write a program that create and run the following threads:
i) To print letter ‘A’ times. ii) To print letter ‘B’ 100 times.
iii) To print integers 1 threads 60.
2. Write a program that create and run the following threads:
i) To print First 15 Even Numbers. ii) To print First 15 Odd Numbers.
3. Write a program that create and run the following threads:
i) To print First 10 Prime Numbers form. ii) To print First 10 terms of Fibonacci Series.
iii) To print word “Hello” 15 times.
4. Write java program to create and run thread to display message “HELLO” 15 times.
5. Write 3 different threads counting from 1 to 100, 101 to 200, and 201 to 300. And start them
together. Give them different priorities and see which one finishes first.
6. Write java program to create and run thread to print mathematical table up to 20 (table of 2 to 20)
7. Write java program to create and run thread to generate 10 terms of Fibonacci series.
8. Write a thread that displays from 1 to 100 by extending the thread class.
Assignment – I/O Stream
1. Write a java program that reads read two file names from command line arguments. Read one file
by using Byte Stream and Write its contents in to the second file.
2. Write a java program that read name of a file by using Input Dialog, check whether file exist or
not. If exist then count the number of vowels from that file and display back to the user.
3. Write a java program that reads a lower case string from command line and writes that string in
“[Link]” file in upper case.
4. Write a java program that display Textfield where user can type file name.
When file name is entered, the program should check whether file exists.
If it does not, an error message should be flashed on the screen.
And if it is, then it should display content of the file in the text area
5. Write a java program to append the contents of the file “[Link]” to “[Link]” using Random
Access File classes.
6. Write a java program that accepts a string from user using command line. Check whether current
directory have any file or directory with that name.
If a file exists with that name, display all the properties of that file such as path, parent directory,
readable, writeable, file size etc.
If a directory exists with that name, list all the content of that directory.
7. Write a java program that reads directory name from the user. Check whether it exists or not. If
exist then count total number of files and subdirectories in it.
Assignment – AWD & Applet
1. Create a Frame which contains 3 push buttons Red, Green, and Blue in it.
Write Java program which handles the ActionEvent such that, When user clicked on Red button,
background color of frame changes to red, when user clicked on Green button, background color
changes to green, and when user clicked on Blue button, color changes to blue.
2. Create a Standard Calculator by using the AWT components of java, which performs the basic
arithmetic operations. Handle the Window Event to close the window.
3. Create a frame which accepts User Name and Password from user in two text fields. Check if
password is correct then display it in client area of frame, otherwise display error message in
client area.
4. Create a Frame which contains three scrollbars Red, Green, and Blue in it. The three scrollbars
shows the Color Value from 0 to 255. Handle the appropriate Event of scrollbar such that, when
user adjust the thumb of any of three scrollbars the background color of panel get changed
according to the values of three scrollbars.
5. Create a Java Application which handles the mouse event. Count the number of mouse clicks on
client area of window, and displays the number of single click, number of double clicks, on the
client area.
6. Create a Java Application which handles the Mouse event. The user should able to draw a line on
frame from the points where he pressed the mouse button (as a start point) to the point where he
released the mouse button (as an end point). Use Graphics class to draw a line in Panel.
7. Create a Java Application which handles the Mouse Event. When user clicked on frame once it
draw a rectangle on it. When user clicked again on frame and inside the area of previously drawn
rectangle, then that rectangle gets erased. If user clicked outside the area of rectangle, the
rectangle remains as it is.
User should not able to draw new rectangle until the first rectangle get erased.
8. Create a Frame which handles the key events. Whenever user presses any key from the key board,
if it is character key, then displays that character on the panel, if user presses any functional key
then also displays its equivalent virtual key constants on the panel.
9. Create a Frame, add a panel in it. Select any random (X, Y) co-ordinate of a pixel in the panel.
Write a Java program which handles the Key Event such that, when user presses the any of the 4
arrow key, a line gets drawn from the selected pixel in the direction of the arrow key pressed. Use
the Virtual key constants of 4 arrow keys.
Modify the above program which uses 4 character keys to draw line
Shift + L for Left Arrow, Shift + R for Right Arrow
Shift + U for Up Arrow, Shift + D for Down Arrow
10. Create a frame and add two push buttons “New” and “Close All” in it. When user clicks on New
button, it should create a new frame and displays it. When user clicks on Close All button all the
frames get closed. Write a Java program to implement Multicasting.
11. Create an applet that accepts a number from user by using Input Dialog, and find whether that
number is prime or not. If it is not prime, check whether it is perfect or not. If it is prime then
display the message. If it is perfect then calculate its factorial. Otherwise find its cube.
12. Create an applet to display scrolling text from right to left in an applet window, using Thread.
Text should be accepted by Input Dialog.
13. Create an applet that handles the mouse event. User should able to draw the line from the point
where the mouse button pressed, to the point where the mouse button released. It should display
the line when user drags the mouse by pressing the mouse button.
14. Create an applet that contains the online order purchase form with Item Number, Item Name, Rate
per Item, and Quantity of Item Ordered. After accepting the information of Item, it should
calculate the total amount to be paid by user as bill.
15. Create an applet which contains one Combo Box for fonts name, One List Box for Font Size, and
3 Radio Buttons for Font Style i.e. Bold, Italic, Plain. The applet also displays some string
message by a label. Write a Java program such that user will able to change the Font Type, Font
Size, and Font Style of the text displayed as label caption.