Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers - Order By Newest | ||||
![]() ![]() | ||||
| ||||
Ans. Component methods called by the container to notify the component of the events | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. String class has a public method intern() that returns a canonical representation for the string object. String class privately maintains a pool of strings, where String literals are automatically interned. these are automatically interned so as to have efficient String comparison using == operator instead of equals which is usually slower. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. It will print 4 because member elements of an interface are implicitly static and hence the concept of overriding doesn't work. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. 10 | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Compilation is the process of converting Java source files to class files which can be executed by the Java runtime environment whereas Decompilation is the process of converting class files back to the Java Source code. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class Class{ public static void main(String[] args){ List<Integer> collector = new ArrayList(); Scanner scanner = new Scanner(System.in); int x = scanner.nextInt(); while(x != 0){ collector.add(x); x = scanner.nextInt(); } System.out.println(collector.stream().collect(Collectors.averagingInt(p->((Integer)p)))); } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public class Class{ public static void main(String[] args){ String string1 = "Hello I am Jack. I live in United States. I live in california state."; String string2 = "I live in"; if(string1.indexOf(string2) >= -1){ System.out.println("string2 is sub string of string1"); } else { System.out.println("string2 is not sub string of string1"); } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class Class{ public static void main(String[] args){ String string1 = "Hello I am Jack. I live in United States. I live in california state."; String string2 = "I live in"; int startIndex = 0; int endIndex = string1.length()-1; int countNoOfOccurences = 0; String remainingString = string1; while(startIndex < endIndex){ if(remainingString.indexOf(string2) != -1){ countNoOfOccurences++; startIndex = remainingString.indexOf(string2) + string2.length(); remainingString = remainingString.substring(startIndex); } else { break; } } System.out.println(countNoOfOccurences); } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public class Class { public static void main(String[] args) { String str = "mallam"; String firstHalf = str.substring(0, str.length() / 2); String secondHalf = str.substring(str.length() / 2); if (firstHalf.equals(new StringBuilder(secondHalf).reverse().toString())) { System.out.println("It's a Colidrome"); } else { System.out.println("It's not a Colidrome"); } } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public class Class{ public static void main(String[] args){ for(int i=1;i<= 100;i++){ if(i%3 == 0){ if(i%5 == 0){ System.out.println("FizzBuzz"); } System.out.println("Fizz"); } else if(i%5 == 0){ System.out.println("Buzz"); } else { System.out.println(i); } } } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { Map<Character, Integer> countMap = new HashMap(); String str = "hello world"; for (char character : str.toCharArray()) { if (countMap.containsKey(character)) { countMap.put(character, countMap.get(character) + 1); } else { countMap.put(character, 1); } } System.out.println(countMap); } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread{ public static void main (String args[]) { Set<Character> set = new HashSet(); Set<Character> setWithDuplicateChar = new HashSet(); String str = "hello world"; for(char character: str.toCharArray()){ if(set.contains(character)){ setWithDuplicateChar.add(character); } else { set.add(character); } } System.out.println(setWithDuplicateChar); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread{ public static void main (String args[]) { for(int counter=1;counter<=100;counter++){ if(counter % 5 == 0){ System.out.println(counter); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread1{ public static void main (String args[]) { for(int x=1;x<=100;x++){ for(int y=1;y <= x;y++){ System.out.println(x); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread{ public static void main (String args[]) { for(int x=1;x<=100;x++){ for(int y=1;y <= x;y++){ System.out.print(y); } System.out.println(" "); } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { for(int x=10;x<100;x++){ int tensDigit = x/10; int unitDigit = x%10; if((tensDigit+unitDigit)*3 == x){ System.out.println(x); } } } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. class A { public void test() { System.out.println("Class A Test"); } } class B extends A { public void test() { System.out.println("Class B Test"); } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. class A { public void test() { System.out.println("Class A Test"); } } class B extends A { public void test() { System.out.println("Class B Test"); } public static void main(String[] args){ A a = new B(); a.test(); // will print Class B Test } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "We are what we repeatedly do; excellence, then, is not an act but a habit."; String longestWord = ""; str = str.replaceAll(",",""); str = str.replaceAll(";",""); str = str.replaceAll("/.",""); for(String word: str.split(" ")){ if(word.length() > longestWord.length()){ longestWord = word; } } System.out.println(longestWord); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { Map<String,Integer> wordLength = new HashMap(); String str = "We are what we repeatedly do; excellence, then, is not an act but a habit."; String longestWord = ""; str = str.replaceAll(",",""); str = str.replaceAll(";",""); str = str.replaceAll("/.",""); str = str.toLowerCase(); for(String word: str.split(" ")){ if(wordLength.containsKey(word)){ wordLength.put(word, wordLength.get(word).intValue() + 1); } else { wordLength.put(word, 1); } } for(Map.Entry<String, Integer> entry:wordLength.entrySet()){ if(entry.getValue().intValue() > 1){ System.out.println(entry.getKey()); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread1 { public static void main(String args[]) { Map<String,Integer> wordLength = new HashMap(); String str = "We are what we repeatedly do; excellence, then, is not an act but a habit"; String longestWord = ""; str = str.replaceAll(",",""); str = str.replaceAll(";",""); str = str.toLowerCase(); for(String word: str.split(" ")){ wordLength.put(word, word.length()); } for(Map.Entry<String, Integer> entry:wordLength.entrySet()){ if(entry.getValue().intValue() > 5){ System.out.println(entry.getKey()); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { Map<String,Integer> wordLength = new HashMap(); String str = "We are what we repeatedly do; excellence, then, is not an act but a habit"; str = str.replaceAll(",",""); str = str.replaceAll(";",""); str = str.toLowerCase(); for(String word: str.split(" ")){ wordLength.put(word, word.length()); } List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>( wordLength.entrySet() ); Collections.sort( list, new Comparator<Map.Entry<String, Integer>>() { public int compare( Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2 ) { return (o1.getValue()).compareTo( o2.getValue() ); } } ); int countWords = 1; for(Map.Entry<String, Integer> entry:list){ if(countWords <= 3){ System.out.println(entry.getKey()); } countWords++; } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { Map<String,Integer> wordLength = new HashMap(); String str = "We are what we repeatedly do; excellence, then, is not an act but a habit"; str = str.replaceAll(",",""); str = str.replaceAll(";",""); str = str.toLowerCase(); for(String word: str.split(" ")){ wordLength.put(word, word.length()); } List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>( wordLength.entrySet() ); Collections.sort( list, new Comparator<Map.Entry<String, Integer>>() { public int compare( Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2 ) { return (o1.getValue()).compareTo( o2.getValue() ) * -1; } } ); int countWords = 1; for(Map.Entry<String, Integer> entry:list){ if(countWords <= 3){ System.out.println(entry.getKey()); } countWords++; } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { Map<String,Integer> wordLength = new HashMap(); String str = "We are what we repeatedly do; excellence, then, is not an act but a habit"; for(String word: str.split(" ")){ wordLength.put(word, word.length()); } List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>( wordLength.entrySet() ); Collections.sort( list, new Comparator<Map.Entry<String, Integer>>() { public int compare( Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2 ) { return (o1.getValue()).compareTo( o2.getValue() ) * -1; } } ); System.out.println(list); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "We are what we repeatedly do; excellence, then, is not an act but a habit"; System.out.println(str.replaceAll(" ", "")); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "We are what we repeatedly do; excellence, then, is not an act but a habit"; String[] splittedString = str.split(" "); for(String word: splittedString){ word = word.trim(); if(!word.equals("")){ System.out.print(word.trim()); System.out.print(" "); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. 1. Object Level Reuse - private methods 2. Class Level Reuse - static methods 3. package level Reuse - default methods 4. Application Level Reuse - Classes 5. Multiple Applications Level Reuse - Libraries , Frameworks | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. boolean byte char double float int long short void | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
![]() ![]() | ||||