L.D. College of Engineering
SEM: 5th Information Technology
Subject: JAVA Programming
1 Pass student name using command line argument and print output in following
format: First Name : abc
Second Name : pqr
Last Name : str
2 Write a program that creates and initializes a four element byte array. Calculate and
display the average of its values.
3. Write an application that creates a two-dimension arrary with int values. the first,
second, and third elements should be arrays with one, two and three numbers
respectively. Display the length of each dimension.
4 Write a program to check whether given number is even or odd.
5 Write a program that displays the value of 2 raised to the power 12.
6. Write a program that displays the substring formed by the last ten characters of a
string.(Use length() method)
7 A string contains five numbers separated by commas .Write a program that displays
the last number.
9 Write a program check primality of a number.
10 Write a program to create circle class with area function to find area of circle.
11 Define class complex with function to add and to compare to complex number.
12 Write a program to print following triangle with character ‘A’ passed as command
line argument for n row.
13 Create circle class then derive cylinder class with overriding of area calculation
14 Create Tiles class with lengh and width parameter and area calculation methos.Derive
subclass Room with same parameter and quantity function to calculate number of
tiles required as per room size.
15 Write a program to find volume of Box. Overload constructor to initialize data
member of Box. Derive class BoxWeight with weight data member and density
16 Derive shipment class form above BoxWeight class with data member shipping price
per unit weight and calculate method to find total shipping cost.
17 Create a StringBuffer object and illustrate the operation of the append() and reverse()
18 Write an application that creates an array with five Float arguments and display the
length of the array and its elements.
19 Write an application that accepts two doubles as its command-line arguments,
multiplies these together, and display the product.
20 Write an application that converts between meters and feet.its first command-line
argument is a number. Its second command-line argument if either “feet” or
“meters”. If this argument equal “feet”, display a string reporting the equivalent
number of meters. If this argument equal “meters”, display a string reporting the
equivalent number of feet. Otherwise, report that the unit system is not recognized.
(note: one meter is equal to 3.28 feet.)
21 Write a program that outputs a table of numbers. Each line in the table contains three
entries: the number, its square, and its cube. Begin with 1 and end with 10.
22 Use While loop to generate random numbers and maintain a running sum of these
values. Terminate when the sum exceeds 20. (Note: use Math. random() method to
23 Write an application that generates the first 15 numbers in the Fibonacci series.
24 Write an application that counts the total number of characters in all of its command-
25 Write an application that searches through its command-line argument. If an
argument is found that does not begin with and upper case letter, display error
message and terminate.
26 Write an application that declares a class named Sphere. It should have instance
variables to record its radius and the coordinates of its center. This should be of type
double. Use the new operator to create a Sphere object. Set and display its instance
27 Write an application that defines a Circle class with two constructors. The first form
accepts a double value that represents the radius of the circle. This constructor
assumes that the circle is centered at the origin. The second form accepts the three
double values. The first two arguments define the coordinates of the center and the
third argument defines the radius.
28 Write an application that defines a sphere class with three constructors.
The first form accepts no arguments. It assumes the sphere is centered at the origin
and has a radius of one unit. The second form accepts one double value that
represents the radius of the sphere. It assumes the sphere is centered at the origin .The
third form accept four double arguments. These specify the coordinates of the center
and the radius.
29 Write an application that demonstrates a class inheritance hierarchy. Class M extends
Object and has two instance variable of type float and String. Class N extends M and
has one instance variable of type Double. Instance class N initialize and display its
30 Write a program that illustrates method overriding. Class Bond is extended by
ConvertibleBond. Each of there classes defines a display() method that outputs the
string “Bond” of “ConvertibleBond”, respectively. Declare an array to hold six Bond
objects. Initialize the elements of the array with a mix of Bond and ConvertibleBond
objects. Execute a program loop to invoke the display method of each object.
31 Write an application that illustrates how a method can invoke a superclass method.
Class I2 is extended by J2.Class J2 is extended by K2.Each of these classes defines a
getDescription() method that returns a string. That string includes a description of the
class plus descriptions of each superclass. Instantiate each of these classes and invoke
the getDescription() method.
32 Write a program that illustrates interface inheritance. Interface p is extended by P1
and P2.Interface p12 inherits from both P1 and P2.Each interface declares one
constant and one method. Class Q implements P12.Instatiate Q and invoke each of its
methods. Each method Displays one of the constants.
33 Assume that you created three packages named a.b.c.d, j.k.l.m, and r.s.t. the .class
files for these packages are stored in directories c:lab8abc, c:freshmanchem101j
klm,and c:semeinarrst,respectively.How should CLASSPATH be set so the
classes and interfaces in those three packages can be located by JDK tools.
34 Write a program that illustrates how to use the throw statement. Create a class that
has static method main(),a(),b(),c(), and d().The main method invokes a().Method a()
invokes b().method b() invokes c().Method c() invokes d().Method d() declares a
local array with ten elements and then attempts to access the element at position
20.Therefor,and ArryIndexOutOfBound Exception is generated. Each method has a
catch block for this type of exception and a finally block. The catch blocks in c() and
d() contain a throw statement to propagate this exception to their caller .Use the
println() method to monitor the flow of control in your program.
35 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 array elements is null or NumberFormatException if an
element is incorrectly formatted. Write a program that illustrates how to declare and
use this method. Include throws clause in the method declaration to indicate that
these problems can occur.
36 Write an application that reads a file and counts the number of occurrences of each
digit between 0 and 9 .supply the file name as a command-line argument.
37 Write an application that reads and processes strings from the console. Reverse the
sequence of characters in each string and then display it.
38 Write one application that writes the first 15 numbers of the Fibonacci series to a file.
Use writeSort() method of DataOutputStrem to output the numbers. Write a second
application that reads this data from a file and displays it. Use the readShort() method
of DataInputStream to input the numbers. For both applications ,specify the name of
the file a command-line argument.
39 Write an Applet which display one string named LDCE at the centre in red color.
40 Write an applet that draws a circle. The dimensions of the applet should be 500*300
pixels. The circle should be centered in the applet and have radius of 100 pixels.(Use
the drawOval() method of Graphics.)
41 Write an applet that draws a rectangle and display one string in the center of the
rectangle with yellow color. Also fill rectangle with blue color. The dimension of
applet should be 500*300 pixels.
42 Write an applet which insets an image.
43 Write an applet that tracks the position of the mouse when it is dragged or moved.
Draw a 10 * 10 pixel rectangle filled with black at the current mouse position.
44 Write an applet that contains one button. Initialize the label on the button to “start”
.when the user presses the button, change the label to “stop” .Toggle the button label
between these two values each time the button is pressed.
45 Write an applet and frame program that tracks the position of the mouse when it is
dragged or moved. Print “hello” at the current mouse position.
46 Write an applet that contains three check boxes and 30 * 30 pixel canvas. The three
check boxes should be labeled “red” ,”Green” and “Blue” .The selections of the
check boxes determine the color of the canvas. for example ,if the user selects both
“Red” and “Blue” the canvas should be purple.(Hint: Use the setBackground() and
repaint() ,methods to change the color of the canvas)
47 Write a java frame program when mouse pressed in frame area ,each time new button
added to frame. Write same program with different layout and see output.
48 Write a java frame program when mouse pressed in frame area new window is
opened.When close button is pressed only one window should be closed.
49 Write a java frame program which shows use of button, menu bar and menu item.
50 Write an applet that contains one choice element and a 30 * 30 pixel canvas. The
items in the choice element should be “red”, ”Green” and “Blue”. The Choice
selection should determine the color of the canvas.
51 Write a program to display a random integer between 5 and 10 every three seconds.
52 Write a multithreaded program that simulates a set of grasshoppers jumping around
in a box. Each grasshopper jumps to a different location every 2 to 12 seconds.
Display the new location of a grasshopper after each of these jumps.
53 Write a multi thread java program to find factorial of a large number.