0% found this document useful (0 votes)
7 views2 pages

Java Walkin Interview Questions

The document provides a collection of Java walk-in interview questions and answers covering various topics such as string manipulation, prime number checking, recursion, encapsulation, inheritance, and differences between interfaces and abstract classes. It also includes a SQL query example for retrieving the top 3 salaries from an employee table. Each question is accompanied by a code snippet demonstrating the solution.

Uploaded by

Nirmal Mali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Java Walkin Interview Questions

The document provides a collection of Java walk-in interview questions and answers covering various topics such as string manipulation, prime number checking, recursion, encapsulation, inheritance, and differences between interfaces and abstract classes. It also includes a SQL query example for retrieving the top 3 salaries from an employee table. Each question is accompanied by a code snippet demonstrating the solution.

Uploaded by

Nirmal Mali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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;

You might also like