Java Notes
HubArray IntroductionArray OperationsArray Programs — FundamentalsArray Interview QuestionsJagged Array in JavaMulti Dimensional ArrayOne Dimensional Arraybreak and continue in JavaDo-While Loop in JavaFor Loop in JavaIf-Else Statements in JavaNested Loops in JavaSwitch-Case in JavaWhile Loop in JavaJava Compilation ProcessFeatures of JavaYour First Java ProgramHistory of JavaJava EditionsJava Program StructureJDK, JRE, and JVMWhat is Java?Immutable Strings in JavaString Class in JavaString Interview QuestionsString MethodsString Programs — FundamentalsStringBuffer in JavaStringBuilder in JavaComments in JavaData Types in JavaIdentifiers in JavaInput and Output in JavaKeywords in JavaOperators in JavaType Casting in JavaVariables in JavaAbstract Class in JavaAbstraction in JavaAnonymous Class in JavaClass and Object in JavaConstructor in JavaEncapsulation in JavaInheritance in JavaInner Class in JavaInterface in JavaMethod Overloading in JavaMethod Overriding in JavaObject Class in JavaObject Cloning in JavaOOPs IntroductionPolymorphism in Javastatic Keyword in Javasuper Keyword in Javathis Keyword in JavaWrapper Class in JavaCollections Framework OverviewCollections Practice ProgramsComparable vs Comparator in JavaGenerics in JavaIterator in JavaArrayList in JavaLinkedList in JavaStack in Java — Collections FrameworkVector in JavaHashMap in JavaHashtable in JavaLinkedHashMap in JavaTreeMap in JavaArrayDeque in JavaDeque Interface in JavaPriorityQueue in JavaHashSet in JavaLinkedHashSet in JavaTreeSet in JavaException Handling Best PracticesCustom Exceptions in JavaException Hierarchy in JavaFinally Block in JavaException Handling Introductionthrow and throws Keywords in JavaTry-Catch Block in JavaBuffered Streams in JavaByte Streams in JavaCharacter Streams in JavaDeserialization in JavaFile Class in JavaJava NIO PackageSerialization in JavaDate and Time API in Java 8Default and Static Methods in InterfacesFunctional Interface in Java 8Lambda Expression in Java 8Method Reference in Java 8Optional Class in Java 8Stream API in Java 8Creating Threads in JavaDaemon Threads in JavaExecutor Framework in JavaInter-Thread Communication in JavaMultithreading Programs in JavaRunnable Interface in JavaSynchronization in JavaThread Class in JavaThread IntroductionThread Life Cycle in JavaThread Priority in JavaBatch Processing in JDBCCallableStatement in JDBCJDBC ArchitectureJDBC IntroductionJDBC ProjectsMySQL Connection with JDBCPreparedStatement in JDBCResultSet in JDBCStatement Interface in JDBCTransaction Management in JDBCCookies in ServletsExpression Language (EL)GenericServletHttpServletJSP IntroductionJSP Tags and JSTLMVC ArchitectureRequest and Response ObjectsServlet IntroductionServlet Life CycleSession TrackingDependency InjectionAPI GatewayConfig ServerDocker DeploymentEureka Server - Service DiscoverySpring BeansCRUD ApplicationException Handling in Spring BootJWT Authentication — Java ProgrammingREST API with Spring BootSpring SecuritySpring Boot IntroductionSpring Data JPAValidation in Spring BootSpring Core ContainerSpring Framework IntroductionDynamic Programming in JavaGraph Data Structure in JavaHashing in JavaHeap (DSA)Linked List in JavaQueue in JavaRecursion in JavaSearching Algorithms in JavaSorting Algorithms in JavaStack in Java — DSA in JavaTime ComplexityTree Data Structure in JavaAdapter Design PatternBuilder Design PatternFactory Design PatternMVC Pattern — Java ProgrammingObserver Design PatternSingleton Design PatternArray Programs — PracticeBasic Java ProgramsCollection ProgramsJDBC ProgramsMultithreading ProgramsOOP ProgramsPlacement Coding QuestionsString Programs — PracticeBanking System — Java ProgrammingChat ApplicationE-Commerce BackendEmployee Management SystemLibrary Management System — Java ProgrammingSpring Boot Fullstack ProjectStudent Management System — Java ProgrammingCoding Interview QuestionsCollections Interview QuestionsCore Java Interview QuestionsJDBC Interview QuestionsMultithreading Interview QuestionsOOPs Interview QuestionsSpring Framework Interview QuestionsJava Cheat SheetImportant Formulas & ConceptsImportant Java ProgramsQuick Revision Notes — Java ProgrammingJava Master Course - Learning Roadmap
Collection of most important Java programs frequently asked in exams and interviews - patterns, number programs, string programs, and array programs.
Number Programs
1. Check Armstrong Number
java example
public boolean isArmstrong(int num) {
int original = num, sum = 0;
int digits = String.valueOf(num).length();
while (num > 0) {
int d = num % 10;
sum += Math.pow(d, digits);
num /= 10;
}
return sum == original;
}
// 153 = 1³ + 5³ + 3³ = 153 ✅2. Reverse a Number
java example
public int reverse(int num) {
int rev = 0;
while (num != 0) {
rev = rev * 10 + num % 10;
num /= 10;
}
return rev;
}
// 12345 → 543213. Check Palindrome Number
java example
public boolean isPalindrome(int num) {
return num == reverse(num);
}
// 121 → true, 123 → false4. Swap Two Numbers Without Temp
java example
a = a + b; // a=15
b = a - b; // b=5 (original a)
a = a - b; // a=10 (original b)
// OR using XOR
a = a ^ b; b = a ^ b; a = a ^ b;5. GCD and LCM
java example
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }6. Sum of Digits
java example
int sumOfDigits(int n) {
int sum = 0;
while (n > 0) { sum += n % 10; n /= 10; }
return sum;
}String Programs
12. Count Vowels and Consonants
Example
String s = "Hello World";
int vowels = 0, consonants = 0;
for (char c : s.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) != -1) vowels++;
else if (c >= 'a' && c <= 'z') consonants++;
}
13. Check Anagram
java example
boolean isAnagram(String a, String b) {
char[] x = a.toLowerCase().toCharArray();
char[] y = b.toLowerCase().toCharArray();
Arrays.sort(x); Arrays.sort(y);
return Arrays.equals(x, y);
}14. Remove Whitespace
java example
String result = str.replaceAll("\\s+", "");15. Count Words in String
java example
int words = str.trim().split("\\s+").length;Array Programs
16. Find Max and Min
Example
int max = arr[0], min = arr[0];
for (int num : arr) {
if (num > max) max = num;
if (num < min) min = num;
}
17. Bubble Sort
Example
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp;
}
}
}
18. Linear Search
Example
int search(int[] arr, int key) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] == key) return i;
}
return -1;
}
19. Matrix Addition
Example
int[][] result = new int[rows][cols];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
result[i][j] = a[i][j] + b[i][j];
20. Matrix Transpose
Example
int[][] transpose = new int[cols][rows];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
transpose[j][i] = matrix[i][j];
Recursion Programs
21. Tower of Hanoi
java example
void hanoi(int n, char from, char to, char aux) {
if (n == 1) { System.out.println(from + " → " + to); return; }
hanoi(n-1, from, aux, to);
System.out.println(from + " → " + to);
hanoi(n-1, aux, to, from);
}22. Power Function
java example
double power(double base, int exp) {
if (exp == 0) return 1;
if (exp < 0) return 1.0 / power(base, -exp);
return base * power(base, exp - 1);
}23. Sum of Array (Recursive)
Example
int sum(int[] arr, int n) {
if (n == 0) return 0;
return arr[n-1] + sum(arr, n-1);
}
OOP Programs
24. Singleton Pattern
java example
class Singleton {
private static Singleton instance;
private Singleton() {}
public static synchronized Singleton getInstance() {
if (instance == null) instance = new Singleton();
return instance;
}
}25. Custom Exception
java example
class InsufficientBalanceException extends Exception {
public InsufficientBalanceException(double amount) {
super("Insufficient balance. Tried to withdraw: " + amount);
}
}Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Important Java Programs.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Java Master Course topic.
Search Terms
java-master-course, java master course, java, master, course, notes, important, programs
Related Java Master Course Topics
Continue learning this concept
NotesImportant Formulas & ConceptsEssential Java formulas, time complexity reference, bit manipulation tricks, and mathematical concepts used in programming and DSA.NotesJava Cheat SheetComplete Java programming cheat sheet with syntax reference, common operations, built-in methods, and code snippets for quick lookup.NotesQuick Revision Notes — Java ProgrammingConcise Java quick revision notes covering all major topics - OOP, Collections, Multithreading, JDBC, Spring Boot in table format for fast review before exams or interviews.Collections FrameworkCollections Practice ProgramsComprehensive Java Collections practice programs covering List, Set, Map, Queue operations with solutions, explanations, and time complexity analysis.FundamentalsArray Programs — Fundamentals20+ complete Java array programs with solutions, detailed explanations, step-by-step logic, input/output examples covering all common array programming problems.FundamentalsString Programs — Fundamentals20+ essential Java string programs with complete solutions, detailed explanations, and output covering palindrome, anagram, reversal, frequency count, and all common string coding problems.