Java Lab Manual
Java Lab Manual
LAB MANUAL
1
Learning Objective:
To learn why Java is useful for the design of desktop and web
applications.
To learn how to implement object-oriented designs with Java.
To identify Java language components and how they work together in
applications.
To design and program stand-alone Java applications.
To learn how to design a graphical user interface (GUI) with Java Swing.
To understand how to use Java APIs for program development.
To learn how to extend Java classes with inheritance and dynamic
binding.
To learn how to use exception handling in Java applications.
To understand how to design GUI components with the Java Swing API.
To learn Java generics and how to use the Java Collections API.
To understand how to design applications with threads in Java.
To learn how to read and write files in Java.
2
PROGRAMS:-
1. WAP to display a welcome message.
2. WAP to add two numbers and find its sum using third variable.
3. WAP to add two numbers using two variables having concatenation effect.
4. WAP to find out area of the circle.
5. WAP to take the input from user using Scanner class.
6. WAP to display the records of student using Scanner class.
7. WAP to check a number is even or odd.
8. WAP to calculate the electricity bill using if condition.
9. WAP to input two numbers and different services using switch case.
10. WAP to print 1-100 using do-while loop.
11. WAP to print 1-100 using while loop.
12. WAP to print NSU 100 times using for loop.
13. WAP to fetch the values of an array using for-each loop.
14. WAP to sort the value of an array using Date class.
15. WAP to proof that an empty class contains a default constructor.
16. WAP to that a static member functions cannot access instance variable.
17. WAP to proof a static member function cannot access instance methods.
18. WAP that static member function can directly call another static member
a) Without the help of class.
b)With the help of class.
19. WAP to proof that, in order to call an instance member of a class we need
to create an object.
3
20. WAP to create a class student to access the members of student class.
21. WAP to pass parameter to a function.
22. WAP to show that this keyword works like a current object.
23. WAP to differentiate between instance variable and local variable.
24. WAP to create a default constructor.
25. WAP to call a parameterized constructor.
26. WAP that when we create an object a separate copy of instance variables
is created.
27. WAP to create a copy constructor.
28. WAP to create a private constructor.
29. WAP to show the uses of instance block.
30. WAP to implement the concept of access modifier
a. private
b. default
c. protected
d. public
31. WAP to show single level inheritance.
32. WAP to show multi-level inheritance.
33. WAP to show Diamond problem in java.
34. WAP to show how to call a default constructor in super class.
35. WAP to show how to call parameterized constructor in super class.
36. WAP to show uses of super () and this () together.
37. WAP to show method overloading in java.
4
38. WAP to show var-args in method overloading
39. WAP to show method overriding in java.
40. WAP to show advantages of method overriding.
41. WAP to show we can change the return type of method while overriding a
method
42. WAP to show the role of access modifier in method overriding.
43. WAP to show the implementation of toString () of Object class.
44. WAP to show the following uses of final keyword
a) To declare a class as a final
b) To declare a variable as a final
c) To declare a method as a final
45. WAP to create an array object in java.
46. WAP to show static method does not act upon instance variable.
47. WAP to show how to work with static block.
48. WAP to show how to import classes using package in Java.
49. WAP to show how to create user-defined package in java
50. WAP to implement the concept of abstract class and abstract method.
51. WAP to show that we can call the constructor present in the abstract class.
52. WAP to show all the methods present in the abstract class must be
overridden in the child class.
53. WAP to implement the concept of an interface.
54. WAP to show that we can achieve multiple inheritance using interfaces.
55. WAP to show that an interface contains static and default methods.
5
56. WAP to generate an exception by dividing a number by 0.
57. WAP to implement multiple try-catches.
58. WAP to show that the super class catch block must be the last catch
block.
59. WAP to show try with multi catch block.
60. WAP to show nested try block.
61. WAP to implement a try-catch inside the catch block.
62. WAP to show the concept of finally block.
63. WAP to implement checked exception.
64. WAP to implement unchecked exception.
65. WAP to work with throw throws and user-defined exception.
66. WAP to take input data by java.io package.
a) DataInputStream class
b) BufferedReader class
65. WAP to read the data of an employee.
66. WAP to read the content of a file.
67. WAP to write the content to a file.
68. WAP to read the content of two file at a time.
69. WAP to write the content to multiple files.
70. WAP to create a Thread.
a) By extending Thread class.
b) By implementing Runnable interface.
71. WAP to implement start() in multithreading.
6
72. WAP to differentiation between start() and run().
73. WAP to proof that Thread creates a separate stack.
74. WAP to implement sleep() in multithreading.
75. WAP to implement join() in multithreading.
76. WAP to get id of a thread.
77. WAP to set and get the name of a Thread.
78. WAP to set and get the priority of a Thread.
79. WAP to reserve a seat in railway by the help of two threads.
80. WAP to proof that thread cannot perform parallel task.
81. WAP to implement method level synchronization.
82. WAP to implement block level synchronization.
83. WAP to implement static synchronization.
84. WAP for Inter Thread Communication (ITC).
85. WAP to implement wait(), notify() and notifyAll()