Top 50 Java Programming Interview Questions
Top 50 Java Programming Interview Questions
Questions
1. How do you reverse a string in Java?
2. How do you swap two numbers without using a third variable in Java?
6. How do you check if a list of integers contains only odd numbers in Java?
9. How do you remove leading and trailing spaces from a string in Java?
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?
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?
28. How do you show a diamond problem with multiple inheritance in Java?
33.
34.
36. How do you compile and run a Java class from the command line?
a) String s1 = "abc";
String s2 = "abc";
b) String s3 = "JournalDev";
int start = 1;
char end = 5;
System.out.println(s3.substring(start, end));
d) try {
if (flag) {
while (true) {
} else {
System.exit(1);
}
} finally {
System.out.println("In Finally");
f) String x = "abc";
String y = "abc";
x.concat(y);
System.out.print(x);
} catch(IOException | Exception e) {
System.out.println(e.getMessage());
package com.digitalocean.programming-interviews;
String s = "abc"
System.out.println(s);