Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
309 views

Top 50 Java Programming Interview Questions

This document contains a list of 50 common Java programming interview questions organized into different categories, including questions about strings, arrays, exceptions, inheritance, and more. It also includes examples of code snippets to guess the output for and find mistakes in.

Uploaded by

Ram Gokul
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
309 views

Top 50 Java Programming Interview Questions

This document contains a list of 50 common Java programming interview questions organized into different categories, including questions about strings, arrays, exceptions, inheritance, and more. It also includes examples of code snippets to guess the output for and find mistakes in.

Uploaded by

Ram Gokul
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Top 50 Java Programming Interview

Questions
1. How do you reverse a string in Java?

2. How do you swap two numbers without using a third variable in Java?

3. Write a Java program to check if a vowel is present in a string.

4. Write a Java program to check if the given number is a prime number.

5. Write a Java program to print a Fibonacci sequence using recursion.

6. How do you check if a list of integers contains only odd numbers in Java?

7. How do you check whether a string is a palindrome in Java?

8. How do you remove spaces from a string in Java?

9. How do you remove leading and trailing spaces from a string in Java?

10. How do you sort an array in Java?

11.How do you create a deadlock scenario programmatically in Java?

12. How can you find the factorial of an integer in Java?

13. How do you reverse a linked list in Java?

14. How do you implement a binary search in Java?

15. Write a Java program that illustrates merge sort.

16. Write a Java program that checks if two arrays contain the same
elements.

17. How do you get the sum of all elements in an integer array in Java?

18. How do you find the second largest number in an array in Java?

19. How do you shuffle an array in Java?


20. How can you find a string in a text file in Java?

21. How do you print a date in specific format in Java?

22. How do you merge two lists in Java?

23. Write a Java program that sorts HashMap by value.

24. How do you remove all occurrences of a given character from an input
string in Java?

25. How do you get distinct characters and their count in a string in Java?

26. Can you prove that a String object in Java is immutable


programmatically?

27. Can you write some code to showcase inheritance in Java?

28. How do you show a diamond problem with multiple inheritance in Java?

29. How do you illustrate a try catch example in Java?

30. Write a Java program to show a NullPointerException.

31. How do you create a record in Java?

32. How do you create text blocks in Java?

33.

34.

35. Show an example of switch expressions and multi-label case


statements in Java.

36. How do you compile and run a Java class from the command line?

37. How do you create an enum in Java?

38. How do you use the forEach() method in Java?

39. How do you write an interface with default and static method?

40. How do you create a functional interface?


41. Show an example of using lambda expressions in Java.

42. Show examples of overloading and overriding in Java.

Guess the Output

a) String s1 = "abc";

String s2 = "abc";

System.out.println("s1 == s2 is:" + s1 == s2);

b) String s3 = "JournalDev";
int start = 1;
char end = 5;
System.out.println(s3.substring(start, end));

c) HashSet shortSet = new HashSet();


for (short i = 0; i < 100; i++) {
shortSet.add(i);
shortSet.remove(i - 1);
}
System.out.println(shortSet.size());

d) try {
if (flag) {
while (true) {
} else {
System.exit(1);
}

} finally {

System.out.println("In Finally");

e) String str = null;


String str1="abc";
System.out.println(str1.equals("abc") | str.equals(null));

f) String x = "abc";
String y = "abc";
x.concat(y);
System.out.print(x);

g) public class MathTest {


public void main(String[] args) {
int x = 10 * 10 - 10;
System.out.println(x);

h) public class Test {


public static void main(String[] args) {
try {
throw new IOException("Hello");

} catch(IOException | Exception e) {

System.out.println(e.getMessage());

43. Find 5 mistakes in the following code snippet.

package com.digitalocean.programming-interviews;

public class String Programs {

static void main(String[10] args) {

String s = "abc"

System.out.println(s);

You might also like