Interview Questions and Answers for 'Java' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   next 30
 Q1341. Can we have private methods in interfaces ?Core Java
Ans. Yes, With Java 9

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java 9


 Q1342. What could be the reason for allowing private methods in java 9 ?Core Java
Ans. Java 8 allowed for method implementation using default methods in interfaces. As those default methods could contain complex logic and might need organizing the logic into multiple methods, they have allowed for private methods.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java 9  default methods


 Q1343. What is the difference between implementing interfaces and inheritance in Java ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q1344. What is a weak reference ?Core Java
Ans. A weak reference is a reference that gets removed on the next garbage collection cycle.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     weak reference  garbage collection     Asked in 1 Companies        rare


 Q1345. Write a program that count the number of access to a method? Core Java
 This question was recently asked at 'TrueCaller'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q1346. Can you explain following exception

java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     ArithmeticException


 Q1347. What are we doing here

list.stream().collect(Collectors.groupingBy(ClassA::getElement1,
               Collectors.averagingDouble(ClassA::getelement2)));
Core Java
Ans. We are averaging elements of a collection by element1 grouped by element1

* list is the reference of collection
* element1 is the member element returned by getElement1 method of ClassA
* element2 is the member element returned by getElement2 method of ClassA

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java 8  collections  java 8 streams  collectors


 Q1348. What will the following code return

list.stream().collect(Collectors.groupingBy(ClassA::getElement1,
               Collectors.averagingDouble(ClassA::getElement2)));
Core Java
Ans. Map<DataType1,DataType2> where DataType1 is the data type of element1 ( returned by getelement1 method ) and DataType2 is the data type of element2 ( returned by getElement2 method )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java 8  collections  java 8 streams


 Q1349. What is the advantage of BidDecimal over Double ?Core Java
Ans. BigDecimal provides more precision as compared to double.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     BigDecimal  Double  data types


 Q1350. What is the difference between following rounding modes

RoundingMode.CEILING
RoundingMode.DOWN
RoundingMode.FLOOR
RoundingMode.HALF_DOWN
RoundingMode.HALF_UP
RoundingMode.HALF_EVEN

Which is the one you use often and Why ?
Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     RoundingMode


 Q1351. Have you worked on creating any cron job ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q1352. Have you used any framework to capture command line arguments or options ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q1353. How would you choose your favorite company name for e.g. three companies are given in radio buttons Infosys, TCS and Aricent. Do You need to loop trough all radio buttons and select your favorite company or can just get the selected value.Javascript
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q1354. Write code to get count of every 5 letter word in a string using lambda expression

Core Java
Ans. String str = "I had been saying that he had been there";

Map<String,Long> countWords = Arrays.asList(str.split(" ")).stream().filter(p->p.length() = 5).collect(Collectors.groupingBy(p->p,Collectors.counting()));

System.out.println(countWords);

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Collectors  lambda  filter  coding  java 8


 Q1355. Can you write code so that we can keep track of Keys that have their values changed along with the number of times they were changed.Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q1356. What are the different types of methods in Java ?Core Java
Ans. Static Methods
Instance Methods
Accessor / Mutator or getter setters

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q1357. Are getters setter / accessor mutator methods instance methods or static methods ? why ?Core Java
Ans. They are usually instance methods. They are usually applied to DAOs / DTOs / POJO that are used to transport objects and used to access object elements. As they are tied to objects and are not common to all objects of a class, hence they are created as non static.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q1358. Design a class that find all files with SSN.Core Java
 This question was recently asked at 'The Home Depot'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q1359. Describe inheritance and polymorphism and their importance for OOP. Core Java
 This question was recently asked at 'The Home Depot'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q1360. What is the difference between instantiation and initialization ?Core Java
Ans. Instantiation is the process of reserving memory for the object

For ex -

List list = new ArrayList();

Initialization is the process of setting the default value for the object or default object construction.

List list = new ArrayList(set);

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q1361. Why do we need to close the Scanner ?Core Java
Ans. For releasing input stream reference (System.in), you should close scanner.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     scanner  input output  io


 Q1362. Can you explain filter and collectors in java 8 ?Core Java
Ans. Filters are used to filter object in stream on certail criteria. And collector is used to collect outcome of the stream. Collector is a terminal operation.
List numbers = List.of(1,2,3,4,5,6,7);
List evenNumbers = numbers.stream().filter(n -> n%2==0).collect(Collectors.toList());
The above code will filter out odd numbers and return the list of even number.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collector  filter


 Q1363. Can you explain filter and collectors in java 8 ?Core Java
Ans. Filters are used to filter object in stream on certain criteria.
Collector is used to collect outcome of the stream. Collector is a terminal operation.
List numbers = List.of(1,2,3,4,5,6,7);
List evenNumbers = numbers.stream().filter(n -> n%2==0).collect(Collectors.toList());
The above code will filter out odd numbers and return the list of even number.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collectors  filters  java 8


 Q1364. Write a program that identifies numbers in a list that are palindrome and perfect square ?Core Java
 This question was recently asked at 'Spillman Technologies'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q1365. Write a program to sort the Array of StringsCore Java
Ans. String[] s = { "sort", "string", "array" };
Collections.sort(Arrays.asList(s));
System.out.println(Arrays.toString(s));      // [array, sort, string]

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q1366. Explain Java collectionsCore Java
Ans. Collection is a container which is used to store and manipulate the group of objects

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q1367. Get all numbers from a collection that are both perfect square and palindomeCore Java
Ans. public static void main(String[] args){
      List<Integer> listOfIntegers = Arrays.asList(1,2,3,4,5,6,7,8,9,10,11);
      List<Integer> perfectAndPalindromeIntegers = new ArrayList<Integer>();
      
      for(Integer i: listOfIntegers){
         if(isPalindrome(i) && isPerfect(i)){
            perfectAndPalindromeIntegers.add(i);
         }
      }
      
      System.out.println(perfectAndPalindromeIntegers);
   }
   
   private static Boolean isPalindrome(Integer i){
      String str = String.valueOf(i);
      
      char[] charArray = str.toCharArray();
      
      int x = 0;
      int y = str.length()-1;
      
      while(x < y){
         if(charArray[x] != charArray[y]){
            return false;
         }
      }
      
      return true;
   }
   
   private static Boolean isPerfect(Integer i){
      for(int x=2;x<3;x++){
         if(x*x == i){
            return true;
         }
      }
      
      return false;
   }

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q1368. When to use List, Set and Map in JavaCore Java
Ans. I. If we want a Collection that does not store duplicate values, then we use a Set based collection.

II. If we want to frequently access elements operations based on an index value then we use a List based collection. E.g. ArrayList

III. If we want to maintain the insertion order of elements in a collection then we use a List based collection.

IV. For fast search operation based on a key, value pair, we use a HashMap based collection.

V. If we want to maintain the elements in a sorted order, then we use a TreeSet based collection.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q1369. What is garbage collection ?Core Java
Ans. The garbage collection is a facility wherein a program runs on the Java Virtual Machine which gets rid of objects, which are not being used by a Java application anymore. It is a form of automatic memory management and recollection.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 4 Companies


 Q1370. Can we change return type of Overridden method ?Core Java
Ans. Yes, we can change return type of overridden method in child class but child's return type should be sub-type of parent's return type.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: