Java Coding Questions
Practice 25 Java Coding Questions interview questions with detailed answers. Part of the Core Java track on Java Interview Hub.
- Write a Java Program to reverse a given string without using any built-in String reversal methods such as reverse().
- Write a Java Program to Swap the values of two variables without using a third temporary variable.
- Write a Java Program to count the frequency of each word in a given string using a HashMap.
- Write a Java Program to iterate HashMap using While and advance for loop.
- Write a Java Program to find whether a number is prime or not in the most efficient way?
- Check whether a given string or number is a palindrome. A palindrome is a sequence that remains the same when read from both forward and backward directions.
- Write a Java Program for the Fibonacci series using recursion. In the Fibonacci sequence, each number is the sum of the two preceding numbers, starting with 0 and 1.
- Write a Java Program to iterate an ArrayList using for-loop, while-loop, and enhanced for-loop.
- Write a Java Program to find the duplicate characters in a string.
- Write a Java Program to find the second-highest number in an array.
- Write a Java Program to Check whether a given number is an Armstrong number. An Armstrong number is a number that is equal to the sum of its digits raised to the power of the total number of digits. For example, 153 is an Armstrong number because 1³ + 5³ + 3³ = 153.
- Write a Java Program to Remove all whitespace characters from a given string without using the replace() or replaceAll() methods.
- Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
- Write a Java program that accepts comma-separated strings, sorts them in ascending order, and outputs the concatenated string of the sorted values.
- Given a string s, return true if s is a "good" string, or false otherwise. A string s is good if all characters that appear in s have the same number of occurrences (i.e., the same frequency).
- Given an array nums and a value val, remove all instances of that value in-place and return the new length of the array. Do not allocate extra space for another array. You must modify the input array in-place with O(1) extra memory.
- Given an integer array and a list of queries, where each query contains a value and an index, update the array element at the specified index by adding the given value. After each update, return the sum of all even numbers present in the array.
- Given two strings s and p, find all the start indices of p's anagrams in s.
- Given a string s, find the length of the longest substring without repeating characters.
- Merge two sorted linked lists into a single sorted linked list while maintaining the sorted order of the elements.
- Rotate a given n × n matrix by 90 degrees in the clockwise direction without using an additional matrix.
- Given a non-negative integer, repeatedly add its digits until the result becomes a single-digit number.
- Given an integer, write a function to determine if it is a power of two.
- Given an integer array, move all zero values to the end of the array without changing the relative order of the non-zero elements.
- Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.