Java Walk-in Interview Questions and Answers
1. Reverse a string without using in-built reverse()
String str = "hello";
String reversed = "";
for(int i = str.length()-1; i >= 0; i--)
reversed += str.charAt(i);
System.out.println(reversed);
2. Check if a number is prime
int num = 29, flag = 0;
for (int i = 2; i <= num / 2; ++i) {
if (num % i == 0) {
flag = 1;
break;
System.out.println(flag == 0 ? "Prime" : "Not Prime");
3. Palindrome string check
String str = "madam";
String rev = new StringBuilder(str).reverse().toString();
System.out.println(str.equals(rev) ? "Palindrome" : "Not Palindrome");
4. Factorial using recursion
int factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
5. Find duplicate elements in array
int[] arr = {1, 2, 3, 2, 4, 3};
Java Walk-in Interview Questions and Answers
Set<Integer> set = new HashSet<>();
for(int n : arr) {
if (!set.add(n)) System.out.println("Duplicate: " + n);
6. Difference between == and .equals()
== checks reference equality (same object).
.equals() checks value equality (same content).
7. Create a class with encapsulation
public class Person {
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
8. Inheritance example
class Animal {
void sound() { System.out.println("Animal sound"); }
class Dog extends Animal {
void sound() { System.out.println("Bark"); }
9. Interface vs Abstract class
Interface: all methods are abstract, no state.
Abstract class: can have both abstract and concrete methods, with state.
10. SQL: Top 3 salaries from employee table
SELECT DISTINCT salary FROM employee ORDER BY salary DESC LIMIT 3;