Java Practical List
Java Practical List
1) Write a java program to get the two numbers from the command line and add them and display
the result.
2) Write program to take a number from command line and check whether it is even or odd.
3) Write a java program to display the following pattern:
1
12
123
1234
4) Write a java program to display the following pattern:
1
01
101
0101
5) Write a java program to find out the largest numbers passed from the command line.
6) Write a java program to take five numbers from the command line and store them into an array
and calculate the sum of those numbers.
7) Write a Java program that takes various strings form command line and display them in sorted
order.
8) Write program to display the bytes of a file in reverse sequence provide the name of the file as
command line argument.
9) Write a program that reads a file & counts the number of occurrence of each digit between "0"
and "9" supply file name as command line Argument.
10) Write a Java program to find sum of elements of array and find average of 5 numbers using
multithreading.
11) Write a Java program to sort elements of an array.
12) Write a Java program to find factor of a quadratic equation use try and catch.
13) Write a Java program to multiply two 3*3 arrays.
14) To create class A in package p, class B in package q and class C in package r. each class should
contain show () method that display the class and package name. Class containing main method
should be written in packages. Create one object of each class A, b and c and call their show ()
method. Also write the steps to compile and run the main program. Assume default package is
c:\java.
15) Write an applet program to pass the name of shapes (rectangle, circle and triangle) and colored,
green and blue) from the html file to applet and Draw filled shape in the specified color.
16) Write a file comparison program using character i/o classes to compare two files and display the
line number and character number where The first difference occurs. If both the file are
identical than display the message "files are identical". The two files names should be passed
from command line argument.
17) Write a Java program that illustrate array out of Bounds and divide by zero exception.
18) Write a Java program to create three threads. Each thread should produce the sum of 1 to 10,
11 to 20 and 21 to 30 respectively. Main thread should wait for all the threads to complete and
it should display final sum.
19) Write Java program that copies one text file to another, converting every lower case character
to uppercase equivalent. Names of source file and destination file should be passed from
command line. Or Write a Java program that takes filename or directory name from command
line. If it is a valid filename then it should display its size. If is a valid directory name then it
should display the count of number of files in that directory.
20) Write a Java applet that draws a line between 2 points. The co-ordinates of 2 points should be
passed as parameters from html file. The color of the line should be red OR Write a Java applet
to draw cylinder and pentagon shapes.
21) Write a program to define custom exception called 'nomatchexception' that is thrown when a
string is not equal to 'internet'. This string is providing through command line argument.
22) Write an application that accepts two integers from the user and divides the first by second and
displays the result. Write catch block to handle different types of exception. If second argument
is zero.
23) WAP that create and starts five threads. Each thread is instantiated from the same class. It
executes a loop with five iterations. Each iteration displays the character Y and sleep for 500
millisecond. The application waits for all threads to complete and then display a message
'finished'.
24) Write a program that counts number of words, and lines in the file. Take the file name as a
command line argument.
25) Write a program that will generate random integer numbers using thread between the ranges
specified by the user. Random numbers should be generated by random thread. Create the
threads using runnable interface.
26) Write an AWT-based applet program that 2 numbers from textfield and displays the sum of the
numbers in the result textfield, when the user clicks the button having caption "find sum". The
program should perform event handling, when the button is clicked.
27) A set of double values are stored in two different files "fl.dat" and "f2.dat". Write a program
that reads these files and find the average of the values.
28) To create 3 threads (using interface) that calculates the sum of the square of 1-5, 6-10 and 11-
15 respectively. Main thread should wait for all threads to complete and then print the sum.
29) Write a program which calculate sum of all the elements of an array. A method named add ()
accepts an array of integer as its arguments. The method generates outofrangeexception if an
element is greater than () or less than 10. Also provide a finally cause to thank the user for using
the program.
30) Write program which writes 10 integer values in a file and read it and display it on the console.