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 Rating | ||||
![]() ![]() | ||||
| ||||
Ans. CREATE TABLE TABLE_NAME ( ID NUMBER PRIMARY KEY, NAME VARCHAR(50) NOT NULL, ); INSERT INTO TABLE_NAME(ID, NAME) VALUES(1, "Abc"); | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
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. 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[]) { 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[]) { 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"; 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 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."; 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 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. import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.io.*; public class Common { public static void main(String ar[])throws Exception { File f=new File("a.txt"); File f1=new File("x.java"); System.out.println(f.exists()); FileInputStream fin = new FileInputStream(f); FileInputStream fin1 = new FileInputStream(f1); byte b[]=new byte[10000]; byte b1[]=new byte[10000]; fin.read(b); fin1.read(b1); String s1 = new String(b); String s2 =new String(b1); String words1[] = s1.trim().split(" "); String words2[] = s2.trim().split(" "); Listlist1 = new ArrayList<>(Arrays.asList(words1)); Listlist2 = new ArrayList<>(Arrays.asList(words2)); list1.retainAll(list2); System.out.println(list1); } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
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. 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. 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. 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 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 counter=1;counter<=100;counter++){ if(counter % 5 == 0){ System.out.println(counter); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
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[]) { 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 BuggyBread1{ public static void main (String args[]) { String str = "hheello world"; char[] charArray = str.toCharArray(); char selectedChar = 'a'; for(char char1: charArray){ if(!str.contains(Character.toString(char1).concat(Character.toString(char1)))){ selectedChar = char1; break; } } System.out.println(str.indexOf(Character.toString(selectedChar))); } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Yes , It can be done using single for loop public class BuggyBread{ public static void main (String args[]) { int x = 50; for(int i=1;i <= 100;i++){ if(i<=50){ System.out.println(i*2); } else { System.out.println(i-x); x = x - 1; } } } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
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 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){ 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 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){ 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. 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. 10 | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. It will print 4 because member elements of an interface are implicitly static and hence the concept of overriding doesn't work. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. https://javasearch.buggybread.com/InterviewQuestions/questionSearch.php?searchOption=label' | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
![]() ![]() | ||||