Program list of java
## **Section A: Pattern Problems (10 Questions)**
1. **Right Triangle Star Pattern**
Write a program to print a right-angled triangle using `*`. Take number of
rows as input.
**Sample Input:** 3
**Output:**
```
*
**
***
```
2. **Inverted Number Pyramid**
Print an inverted half pyramid with numbers.
**Input:** 4
**Output:**
```
1234
123
12
1
```
3. **Hollow Rectangle Pattern**
Print a hollow rectangle of given dimensions.
**Input:** 4, 5
**Output:**
```
*****
* *
* *
*****
```
4. **Diamond Pattern**
Print a diamond pattern with `*`.
**Input:** 3
**Output:**
```
*
***
*****
***
*
```
5. **Floyd's Triangle**
Print Floyd's Triangle.
**Input:** 4
**Output:**
```
1
23
456
7 8 9 10
```
6. **Pascal's Triangle**
Print Pascal's Triangle.
**Input:** 5
**Output:**
```
1
11
121
1331
14641
```
7. **Butterfly Pattern**
Print a butterfly pattern.
**Input:** 4
**Output:**
```
* *
** **
*** ***
********
*** ***
** **
* *
```
8. **Number Pyramid**
Print a pyramid with numbers.
**Input:** 4
**Output:**
```
1
22
333
4444
```
9. **Alphabet Pattern**
Print alphabet pattern 'A' to 'Z'.
**Input:** 'D'
**Output:**
```
A
BB
C C
D D
```
10. **Spiral Matrix**
Print numbers in a spiral pattern.
**Input:** 3
**Output:**
```
123
894
765
```
---
## **Section B: OOP Concepts (20 Questions)**
### **Abstraction & Encapsulation**
11. Create an abstract class `Shape` with abstract method `area()`. Implement
`Circle` and `Rectangle` classes.
12. Design a `BankAccount` class with private fields and public methods for
deposit/withdraw.
13. Create an interface `Drawable` with method `draw()`. Implement it in
`Circle` and `Square` classes.
14. Design a `Student` class with encapsulation (private fields, getters/setters).
15. Create an abstract `Vehicle` class with derived classes `Car` and `Bike`.
### **Inheritance**
16. Implement single inheritance: `Animal` → `Dog`.
17. Create multilevel inheritance: `Person` → `Employee` → `Manager`.
18. Implement hierarchical inheritance: `Shape` → `Circle`, `Square`.
19. Override `toString()` in a `Person` class and its child `Student` class.
20. Use `super` keyword to call parent class constructor from child class.
### **Polymorphism**
21. Demonstrate method overloading in a `Calculator` class.
22. Show runtime polymorphism with `Animal` → `Dog`, `Cat` overriding
`makeSound()`.
23. Create a polymorphic array of `Shape` objects calling `draw()`.
24. Implement interface polymorphism with `List` → `ArrayList`, `LinkedList`.
25. Override `equals()` and `hashCode()` in a `Person` class.
### **Constructors**
26. Create a class with default and parameterized constructors.
27. Implement constructor overloading in a `Box` class.
28. Write a program demonstrating copy constructor.
29. Create a singleton class using private constructor.
30. Show constructor chaining using `this()`.
---
## **Section C: Packages & Exception Handling (10 Questions)**
31. Create a user-defined package `com.math` with a `Calculator` class.
32. Import and use `java.util.Arrays` to sort an array.
33. Demonstrate static import with `Math.PI`.
34. Create custom exception `InvalidAgeException`.
35. Handle `ArithmeticException` in a division program.
36. Use multiple catch blocks for different exceptions.
37. Demonstrate `finally` block with file handling.
38. Throw `NullPointerException` and handle it.
39. Create a method that throws `IOException`.
40. Use `try-with-resources` for file operations.
---
## **Section D: Multithreading (10 Questions)**
41. Create a thread by extending `Thread` class.
42. Implement `Runnable` interface to create a thread.
43. Print numbers 1-10 using two threads (odd/even).
44. Demonstrate thread priority.
45. Synchronize a bank withdrawal operation.
46. Use `join()` to wait for thread completion.
47. Create a daemon thread.
48. Implement thread pool using `ExecutorService`.
49. Solve producer-consumer problem using `wait()`/`notify()`.
50. Demonstrate deadlock scenario and prevention.
---
## **Section E: File Handling & Graphics (10 Questions)**
51. Read a text file and count lines.
52. Write user input to a file.
53. Copy contents of one file to another.
54. Serialize and deserialize an object.
55. Draw a line using `java.awt.Graphics`.
56. Create a GUI button that changes color when clicked.
57. Display text in different fonts in a window.
58. Create a simple animation (moving ball).
59. Draw a bar chart using AWT.
60. Create a basic calculator GUI using Swing.