Assignments

This are the collection of Question , it is very usefull to improve your java practicle knowlege and you  can be get perfaction in language.This are also usefull to the student of computer language,student can learn the java by performing the following task.

                            Assignment-1

1. Print 'hello world' in java.

2. Addition of two values passing by command line argument.

3. Write a program to find the result of following expression.
1) a << 2 + b >> 2
2) (a<<2) + (b>>2)
3) a & b
4) a | 4 + a >> b & 7

4. Write a program in java to explain the use of break and continue statements.

5. Create Box class with data members width, height and depth. Objects of this class initialize with zero
value or by passing single value. Create a method to calculate volume and display it.

6. Calculate area of square, rectangle and triangle using the three same name methods 'area';

7. Make CALC class with two data members. Perform addition, subtraction, multiplication and division
operation of given two values by user. Initialize both data members with zero. (use menu-driven)

8. Create array with values {8,7,6,5,4} and display it.

9. Write a program which display following pattern.
1
1 2
1 2 3
1 2 3 4

10. Write a program which display following pattern.
1
2 3
4 5 6
7 8 9 10

11. Write a program which display following pattern.
            1
        2    2
     3    3     3
 4     4    4     4

12. Create integer array of size 5. Insert 5 values through user and sort the array and display it. Also
calculate total of all 5 values.

13. Write a program which have a class AVERAGE contain a single dimensional array MARKS (size 5) as
data member. Take input from parameterized constructor. Take methods to calculate average marks
and display it. Create only one object of class.

14. Create STACK class with push, pop fun.

15. Write a program in java to find A x B where A is a matrix of 3 x 3 and B is a matrix of 3 x 4. Take the
values in matrixes A and B form the user.

16. Create one string array of size 5. Insert 5 names through user and sort the array name wise and
display it.

17. Write a program in java to compute the sum of the digits of a given integer. Remember, your integer
should not be less than the five digits. (e.g. if input is 23451 then sum of the digits 2+3+4+5+1 = 15)

18. Create class STUDENT with rno and name data members. Create 5 objects using array (array of
objects). Enter data through user and display it.

19. Create class EMPLOYEE with 􀍚id, name and salary􀍛 private data-members. Create 5 objects
dynamically through user input. Create two methods which display data salary wise and name wise.
(make menu-driven by switch case)

20. Write a program in Java with class Rectangle with the data fields width, length, area and colour. The
length, width and area are of double type and colour is of string type .The methods are set_ length () ,
set_width (), set_ colour(), and find_ area(). Create two object of Rectangle and compare their area and
colour. If area and color both are the same for the objects then display 􀍞Matching Rectangles􀍟,
otherwise display 􀍞Non matching Rectangle􀍟.

21. Create a class Account with two overloaded constructors. The first constructor is used for initializing,
the name of account holder, the account number and the initial amount in the account. The second
constructor is used for initializing the name of the account holder, the account number, the addresses,
the type of account and the current balance. The Account class is having methods Deposit (),
Withdraw(), and Get_Balance(). Make the necessary assumption for data members and return types of
the methods. Create objects of Account class and use them.


                            Assignment-2

1. Write a Java program to show that private member of a super class cannot be accessed from derived
classes.

2. Write a program which show the calling sequence of default constructor in multilevel inheritance.

3. Create a class Student and derive class Result. Student class has name and rollNo. Result class has
sub1, sub2, sub3 and total_marks. Student class and Result class has their own display method to display
their parameters. Display the result of 5 students. Take input using parameterized constructors. Use
super keyword to call parent class constructor and parent class method.

4. Write a class Worker and derive classes DailyWorker and SalariedWorker from it. Every worker has a
name and a salary rate. Write method ComPay (int hours) to compute the week pay of every worker. A
Daily Worker is paid on the basis of the number of days s/he works. The Salaried Worker gets paid the
wage for 40 hours a week no matter what the actual hours are. Test this program to calculate the pay of
workers. You are expected to use the concept of polymorphism to write this program.

5. Write a program which show the Dynamic method dispatch.

6. Create abstract class Figure and its child classes Rectangle and Triangle. Figure class has abstract area
method which is implemented by Rectangle and Triangle class to calculate area. Use run time
polymorphism to calculate area or Rectangle and Triangle objects.

7. Write a program which show the Dynamic method dispatch using interface.

8. Write a program in Java to show the usefulness of Interfaces as a place to keep constant value of the
program.

9. Create an Interface having two methods division and modules. Create a class, which overrides these
methods.

10. Write a program in Java which show that interface can inherit another interface. Take interface A
which have input method and another interface B which have display method. Create one child class C
which implements the both methods.

11. Write a program which show partial implementation concept in interface.

12. Write a program to accept names from the user, print all the names which have the surname 􀍞Patel􀍟
in it.

13. Write a java application which accept two strings. Merge both the string using alternate characters
Of each strings.
Eg. 􀍞Hello􀍟 and 􀍞Good􀍟.
Result should be, 􀍞HGeololdo􀍟.

14. Write a java code which accept a string and display the string in reverse order.

15. Write a program in Java to create a String object. Initialize this object with your full name. Find the
length of your name using the appropriate String method. Find whether the character 􀍚a􀍛 is in your
name or not; if yes find the number of times 􀍚a􀍛 appears in your name. Print locations of occurrences of
􀍚a􀍛 .

16. Write a program in Java for String handling which performs the following using StringBuffer class:
i) Checks the capacity of StringBuffer objects.
ii) Reverses the contents of a string given on console and converts the resultant string in upper case.
iii) Reads a string from console and appends it to the resultant string of ii.

17. Write a program for searching a given sub string from the given sentence. Also calculate number of
times given sub string occur in given sentence.

18. Write a program to make a package Balance in which has Account class with Display_Balance
method in it. Import Balance package in another program to access Display_Balance method of Account
class.

19. Write a program which show the different package non sub class concept. Check the result of
different access specifiers – private, public, protected and default.

20. Write a program which show the different package sub class concept. Check the result of different
access specifiers -– private, public, protected and default.


                             Assignment-3

1.write a program which show example of Exception handling in which all keywords try, catch, finally,

2. Write a program which show finally block is called after try/catch block.

3. Write a program which show finally block is called before function return.

4. Create your own User defined exception GreaterTenException if value is given greater than 10.

5.Create  own User defined exception InvalidCharException if any one of the char @,*,? is present

6. Create java application which display clock. Display time using thread concept.

7. Write a program which show threads are working simultaneously (parallel) in multithreading concept.

8.. Write a program which show deadlock in the concept of synchronization in java.

9.. Write a program which show inter-thread communication.

10. Write a program which show use of join and isAlive methods in multithreading system.

11. create an applet program which display rotated text of your name at one place.

12. create an applet program to display your name which move in window left to right.

13. Write an applet program which show Digital Clock.

14. Write an applet program which display image in window.

15. Write an applet program which change background color by click on different buttons.

Comments