Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

MCSL 025- JAVA LAB PROGRAMS SOLVED - ignou mca Most of JAVA lab programs solved Check for

the proper order of section wise programs from your lab manual Session 1: Data types, variables and operators Exercise 1: Write a program in Java to implement the formula (Area = Height Widt h) to find the area of a rectangle. Where Height and Width are the rectangle s hei ght and width. Exercise 2: Write a program in Java to find the result of following expression ( Assume a = 10, b = 5) i) (a < < 2) + (b > > 2) ii) (a) | | (b > 0) iii) (a + b *100) / 10 iv) a & b Exercise 3: Write a program in Java to explain the use of break and continue sta tements. Exercise 4: Write a program in Java to find the average of marks you obtained in your 10+2 class. Session 2: Statements and array Exercise1: Write a program in Java to find AB where A is a matrix of 33 and B is a matrix of 34. Take the values in matrixes A and B from the user. Exercise 2: 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 of 23451will be 15) Session 3: Class and Objects Exercise 1: Write a program in Java with class Rectangle with the data fields wi dth, 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_ co lour(), and find_ area (). Create two object of Rectangle and compare their area and colour. If area andcolor both are the same for the objects then display Matc hing Rectangles , otherwise display Non matching Rectangle . Exercise 2: Create a class Account with two overloaded constructors. The first c onstructor is used for initializing, the name of account holder, the account num ber and the initial amount in the account. The second constructor is used for in itializing the name of the account holder, the account number, the addresses, th e type of account and the current balance. The Account class is having methods D eposit (), Withdraw (), and Get_Balance(). Make the necessary assumption for dat a members and return types of the methods. Create objects of Account class and u se them Exercise 3: Write a program in Java to create a stack class of variable size wit h push() and pop () methods. Create two objects of stack with 10 data items in b oth. Compare the top elements of both stack and print the comparison result.>

Session 4: Inheritance and polymorphism

Exercise 1: Write a Java program to show that private member of a super class ca nnot be accessed from derived classes. Exercise 2: Write a program in Java to create a Player class. Inherit the classe s Cricket _Player, Football _Player and Hockey_ Player from Player class. Exercise 3: Write a class Worker and derive classes DailyWorker and SalariedWork er 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 ba sis 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 calcu late the pay of workers. You are expected to use the concept of polymorphism to write this program. Exercise 4: Consider the trunk calls of a telephone exchange. A trunk call can b e ordinary, urgent or lightning. The charges depend on the duration and the type of the call. Writ a program using the concept of polymorphism in Java to calcul ate the charges. Session 5: Package and Interface Exercise 1: 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. Exercise 2: Write a program in Java to show the usefulness of Interfaces as a pl ace to keep constant value of the program. Exercise 3: Create an Interface having two methods division and modules. Create a class, which overrides these methods. Exercise 4: Write a program in Java which implements interface Student which has two methods Display_Grade and Atrendance for PG_Students and UG_Students (PG_St udents and UG_Students are two different classes for Post Graduate and Under Gra duate students respectively). Session 6: Exception Handling Exercise 1: Write a program in Java to display the names and roll numbers of stu dents. Initialize respective array variables for 10 students. Handle ArrayIndexO utOfBoundsExeption, so that any such problem doesn t cause illegal termination of program. Exercise 2: Write a Java program to enable the user to handle any chance of divi de by zero exception. Exercise 3: Create an exception class, which throws an exception if operand is n on-numeric in calculating modules. (Use command line arguments). Exercise 4: On a single track two vehicles are running. As vehicles are going in same direction there is no problem. If the vehicles are running in different di rection there is a chance of collision. To avoid collisions write a Java program using exception handling. You are free to make necessary assumptions. Session 7: Multithreading Exercise 1: Write a Java program to create five threads with different prioritie s. Send two threads of the highest priority to sleep state. Check the aliveness

of the threads and mark which thread is long lasting. Exercise 2: Write a program to launch 10 threads. Each thread increments a count er variable. Run the program with synchronization. Exercise 3: Write a program for generating 2 threads, one for printing even numb ers and the other for printing odd numbers. Exercise 4: Write a Java program using thread synchronization in multithreading (You can take some objects visible on screen for real time effect). Session 8: Reading, Writing and String handling in Java Exercise 1: Writ a program in Java to create a String object. Initialize this ob ject with your name. Find the length of your name using the appropriate String m ethod. 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 .Try the same for different String objects. Exercise 2: Write a program in Java for String handling which performs the follo wing: i) Checks the capacity of StringBuffer objects. ii) Reverses the contents of a string given on console and converts the resultan t string in upper case. iii) Reads a string from console and appends it to the resultant string of ii. Exercise 3: Write a program for searching strings for the first occurrence of a character or substring and for the last occurrence of a character or substring. Exercise 4: Write a program in Java to read a statement from console, convert it into upper case and again print on console. Exercise 5: Write a program in Java, which takes the name of a file from user, r ead the contents of the file and display it on the console. Exercise 6: Write a Java program to copy a file into another file. Session 9: Applets and its applications Exercise 1: Write a Java Applet program which reads your name and address in dif ferent text fields and when a button named find is pressed the sum of the length of characters in name and address is displayed in another text field. Use appro priate colors, layout to make your applet look good. Exercise 2: Create an applet which displays a rectangle/string with specified co lour & coordinate passed as parameter from the HTML file. Exercise 3: Create an applet which will display the calendar of a given date. Exercise 4: Write a program to store student s detail using Card Layout. Exercise 5: Write a Java Applet program, which provides a text area with horizon tal and vertical scrollbars. Type some lines of text in the text area and use sc rollbars for movements in the text area. Read a word in a text field and find wh ether the word is in the content of the text area or not. Session 10: Networking and other advanced feature and JAVA Exercise 1: Write a Java program to find the numeric address of the following we b sites i. www.ignou.ac.in

ii. www.indiatimes.com iii. www.rediff.com iv. www.apple.com In addition to this, find the Internet Address of your local host. Exercise 2: Create an applet which takes name and age as parameters and display the message <name> is <age> year old. . Print the URL of the class file. Exercise 3: Write a program to test Socket functionality for appropriate hostnam e and port number. Exercise 4: Write a Java program to connect to a database created in MS ACCESS/SQL SERVER/ORACLE using JDBC concept. Perform basic operations of Selectio n, Insertion and Deletion on the database.

You might also like