You are on page 1of 2

JAVA PROGRAMMING LABORATORY MANUAL

For Second Semester BCS

Lab1:
1. Write a Java Program to Print Hello World!
2. Write a java Program to add two numbers.
3. Write a Java Program to define a class, describe its constructor, overload the Constructors and instantiate
its object.
4. Write a Java Program to define a class, define instance methods for setting and retrieving values of instance
variables and instantiate its object.

Lab 2:
1. Write a Java program with a class of Quadratic that prints all real solutions to the quadratic equation ax2 +
bx + c=0. Create three setter methods to set the value of a, b and c and a method displayResult(), which
prints all real solutions of the quadratic equation, if the discriminant b2 4ac is negative display a message
stating that there are no real solutions.
2. Write a Java program that calculate mathematical constant e using the formula e=1+1/2! +1/3! +........ up
to 5.

Lab 3:
1. Write a java program to print the prime numbers from 1 to 100.
2. Write a Java program that prints the following patterns.
****** ******
***** *****
**** ****
*** ***
** **
* *

* *
** **
*** ***
**** ****
***** *****
****** ******

Lab 4:
1. Write a Java program that displays area of different Figures(Rectangle, Square, Triangle) using the method
overloading.
2. Write a Java program that counts the number of objects created by using static variable .
Lab 5:
1. Write a Java program to sort the elements of an array in ascending order.
2. Write a Java program multiplication of two matrices.
3. Write a Java Program to implement array of objects.

LAB 6
1. Write a Java program that reverses a given String.
2. Write a Java program that checks whether a given string is a palindrome or not.
3. Write a Java program to count the frequency of words, characters in the given line of text.
4. Write a Java program for sorting a given list of names in ascending order.
5. Write a Java program to practice using String Buffer class and its methods.
LAB 7
1. Write code to generate and catch an ArrayIndexOutOfBoundsException.
2. Create two classes, A and B, with default constructors (empty argument lists) that announce
themselves. Inherit a new class called C from A, and create a member of class B inside C. Do not
create a constructor for C. Create an object of class C and observe the results.
3. Write a Java Program to implement inheritance and demonstrate use of method overriding.
4. Write a Java Program to implement multilevel inheritance by applying various access controls to its
data members and methods.
Lab 8:
1. Write a program to demonstrate use of implementing interfaces.
2. Write a program to demonstrate use of extending interfaces.
3. Write a Java program to implement the concept of importing classes from user defined package and
creating packages.
Lab 9:
1. Write a program to implement the concept of threading by extending Thread Class.
2. Write a program to implement the concept of threading by implementing Runnable Interface
Lab 10:
1. Write a Java Program to implement Wrapper classes and their methods.
2. Write a Java Program to implement Vector class and its methods.
Lab 11:
1. Write a program to implement the concept of Exception Handling using predefined exception.
2. Write a program to implement the concept of Exception Handling by creating user defined exceptions.

Lab 12(GUI's):
3.Write a program using Applet to display a message in the Applet.
4.Write a program using Applet for configuring Applets by passing parameters.
Lab 13:
5. Write a Java Program to demonstrate Keyboard event.
6. Write a Java Program to demonstrate Mouse events.
Lab 14:
7. Write programs for using Graphics class - to display basic shapes and fill them - draw different items using
basic shapes - set background and foreground colors.