Java Assignment Questions
1. Basic Concepts and Data Types
Write a program to check if a given number is prime.
Write a program to reverse a string without using built-in methods.
Find the factorial of a number using both recursion and iteration.
Write a program to swap two numbers without using a third variable.
Write a program to check if a given number is a palindrome.
Implement Fibonacci series using recursion and iteration.
3. Object-Oriented Programming (OOP)
Design a class for a BankAccount with methods for deposit, withdrawal, and balance inquiry.
Write a program to demonstrate method overloading and method overriding.
Explain and implement the Singleton design pattern.
Explain and demonstrate the Factory design pattern.
Implement encapsulation and inheritance in a small example (like a class hierarchy of Person
and Student).
4. Collections Framework
Write a program to sort a list of objects based on a specific attribute.
Find the frequency of each element in an array using HashMap.
Write a program to find the intersection and union of two arrays.
Demonstrate the use of HashSet, LinkedHashSet, and TreeSet.
Write a program to find duplicate entries in a list and count them.
Arrays
1. Find the maximum product of two integers in an array.
2. Move all zeros to the end of an array.
3. Kadane’s algorithm to find the maximum subarray sum.
4. Find the intersection of two arrays.
5. Rotate an array by k positions.
6. Merge two sorted arrays without extra space.
7. Find the missing number in an array of n numbers.
8. Subarray with a given sum.
Strings
1. Check if a string is a palindrome.
2. Find the first non-repeating character in a string.
3. Reverse words in a sentence.
4. Count and display duplicate characters in a string.
5. Check if two strings are anagrams of each other.
6. Longest Common Prefix.
7. Implement atoi() to convert a string to an integer.
8. Find all permutations of a given string.
Linked List
1. Reverse a linked list.
2. Detect a cycle in a linked list (Floyd’s Cycle-Finding Algorithm).
3. Find the middle element of a linked list.
4. Merge two sorted linked lists.
5. Remove duplicates from a sorted linked list.
6. Find the nth node from the end of a linked list.
7. Add two numbers represented by linked lists.
8. Check if a linked list is a palindrome.
Stacks and Queues
1. Implement a stack using arrays and linked lists.
2. Implement a queue using stacks.
3. Find the next greater element for each element in an array.
4. Evaluate a postfix expression.
5. Implement a Min Stack (stack that supports push(), pop(), and retrieving the minimum
element in constant time).
6. Reverse a queue using recursion.
7. Implement a circular queue.
Trees and Graphs
1. Level order traversal of a binary tree.
2. Check if a binary tree is balanced.
3. Find the lowest common ancestor (LCA) of two nodes in a binary tree.
4. Depth-first search (DFS) and breadth-first search (BFS) implementations.
5. Implement a binary search tree (BST) and perform basic operations (insert, delete, search).
6. Find all paths from the root to leaves in a binary tree.
7. Check if two trees are identical.
8. Detect a cycle in an undirected/ directed graph.
Sorting and Searching
1. Implement binary search.
2. Quick sort implementation.
3. Merge sort implementation.
4. Find the kth smallest/largest element in an array.
5. Search for an element in a rotated sorted array.
6. Count sort for non-negative integers.
7. Find the peak element in an array.
8. Find a pair with a given difference in an unsorted array.