Interview Questions and Answers - Order By Newest        Q961. Write a method to convert all elements of a set to lower case.  Core Java 
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=Method+to+convert+all+elements+of+a+collection&category=code    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        code  coding  string  String.toLowerCase  set  collections  Q962. Write java code to Get all words from a String and display them  Core Java 
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=+Get+all+words+from+a+String&category=code    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        string   get all words from strings   string.splitRecently asked in Sophos   Q963. Write a Method to get a map of words and their count by passing in the string  Core Java 
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=Method+to+get+a+map+of+words&category=code    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        map  collections      Asked in 2 Companies        intermediate   Q964. Write code for singleton class  Design 
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=singleton+class&category=code    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        singleton  code  coding  design pattern      Asked in 1 Companies        Intermediate          frequent   Q965. Have you ever looked into internal implementation of Java Collections ?  
Ans. Yeah, I once looked into implementation of TreeSet and TreeMap just for learning.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        collections  Q966. How is static and dynamic polymorphism achieved in Java ?  Core Java 
Ans. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        static polymorphism  object oriented programming (oops)  oops concepts   dynamic polymorphism  object oriented programming (oops)  oops concepts   polymorphism  object oriented programming (oops)  oops concepts   overloading   overriding   broadridg      Asked in 1 Companies        basic          frequent   Q967. Why can't we declare a class abstract as well as final ?  Core Java 
Ans. Abstract means that the class is only meant to be subclassed whereas final means that it cannot be subclassed so both concepts - abstract and final are actually mutually exclusive and hence not permitted together.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        abstract   final   java keywords      Asked in 1 Companies   Q968. Write a program / method to input few numbers and then print the sum.  
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=946    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        code  coding  scanner       basic Very frequently asked to fresh graduates. Frequently asked in NSEiT and Accenture India   Q969. Write a program to Generate prime numbers till a given number  Core Java 
Ans. public class Main { 
 public static void main(String args[]) { 
  int number = 2; 
  int count = 0; 
  long sum = 0; 
  int givenNumber = 1000; 
  while (count < givenNumber) { 
   if (isPrimeNumber(number)) { 
    sum = number; 
    count; 
   } 
   number; 
  } 
  System.out.println(sum); 
 } 
 private static boolean isPrimeNumber(int number) { 
  for (int i = 2; i <= number / 2; i) { 
   if (number % i == 0) { 
    return false; 
   } 
  } 
  return true; 
 } 
}   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        generate prime numbers  code  coding      Asked in 5 Companies        basic          frequent   Q970. Write a program to calculate factorial of a number using recursion  Core Java 
Ans.  
 
public class Factorial { 
   public static void main(String[] args){ 
      int x = 5; 
       
      System.out.println(calculateFactorial(x)); 
    
   } 
    
   private static int calculateFactorial(int x){ 
      if(x==1){ 
         return 1; 
      } 
      return x * calculateFactorial(x-1); 
   } 
}   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        factorial  calculate factorial  code  coding  recursion      Asked in 1 Companies        basic   Q971. Write code for the usage of Builder Design Pattern  
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=964    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        builder design pattern  builder pattern  code  coding       intermediate   Q972. Write code for constructor overloading  Core Java 
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=965    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        constructor overloading  code  coding      Asked in 2 Companies        basic   Q973. Write code to check if an integer is odd or even using ternary operator  
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=963    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        ternary operator  code  coding  Q974. Write code to sort elements of a set  
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=952    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        set  collections  sorting  treeset  code  coding  Q975. In the following code , how many methods needs to be implemented in Class B ? 
 
public interface A{ 
   public void method1(); 
   public void method2(); 
   public void method3(); 
}  
 
abstract class B implements A{ 
}  Core Java 
Ans. As Class B has been declared abstract , we can either implement any of these methods and just declare rest of them abstract.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        interfaces  abstract classes  code  coding Try 2 Question(s) Test  Q976. What will the following code print ? 
 
Integer a = 100, b =100; 
Integer c = 1000, d = 1000; 
System.out.println(a == b); 
System.out.println(c ==d);  Core Java 
Ans. false 
false   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        object equality  code  coding         frequent     Q977. How is multiple inheritance implemented in Java ?  Core Java 
Ans. There was no multiple inheritance in java before version 8 as implementing multiple interfaces cannot be termed as inheritance. 
 
With Java 8 , came the concept of default methods wherein the class implementing the interface carries the default implementation from the interface and hence facilitating multiple inheritance.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        multiple inheritance  object oriented programming (oops)  oops concepts   inheritance  object oriented programming (oops)  oops concepts   oops concept      Asked in 10 Companies          frequent   Q978. Write a program for Coin Changer application ?  
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=979    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        coin changer application  coin changing  general electic (ge)  Q979. What is unmodifiable set / unmodifiable map ? How can we create one ?  
Ans. It is an unmodifiable / read only view of the underlying collection. We can use  
 
Collections.unmodifiableSet(Set set) 
Collections.unmodifiableMap(Map map) 
Collections.unmodifiableCollection(Collection collection)   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        collections  set  unmodifiable set  map  unmodifiable map  unmodifiablemap  unmodifiableset  Collections.unmodifiableCollection  Collections.unmodifiableMap  Collections.unmodifiableSet  Q980. What is the use of MethodHandle ?  
Ans. MethodHandle is a modern, more flexible, more typesafe way of doing reflection.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        MethodHandle  Reflection    Q981. What is a Destructor ? Do we have Destructors in Java ?  Core Java 
Ans. Destructor is used to de-allocate memory allocated by objects.   
 
There are no destructors in Java. Alternatively, Java provides Automatic garbage collection i.e automatically releasing the un-referenced memory.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        destructor  garbage collection      Asked in 11 Companies        Basic          frequent  Try 1 Question(s) Test  Q982. What are JSP Scriptlets?  
Ans. Scriptlet allow to write Java code inside JSP like following 
 
<% Java Code %>   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        jsp  jsp scriptlet  scriptlet  Q983. What is use of Revert in SVN?  Tools 
Ans. Revert your local changes. 
 
There are 2 types of reverts - 
 
1) Local Revert: It will delete all changes from files which you made after updates and before commit. 
2) Repo Revert: Upload the changes to previous Repo.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        svn  subversion  version control system  configuration management      Asked in 2 Companies   Q984. Can we have multiple threads consuming message stream from a single partition ?   
Ans. Yes, by having multiple Consumer Groups.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        apache kafka  kafka  kafka consumer  kafka topic partitions  bigdata  consumer group  Q985. Can we have multiple threads consuming messages from a single partition if we have single Consumer Group ?   
Ans. No, we can only have max 1 thread per partition in a single Consumer Group.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        apache kafka  kafka  kafka consumer  kafka topic partitions  bigdata  consumer group  Q986. If we have more threads than partitions in a kafka consumer, How can we model it efficiently ?  
Ans. We will have to use multiple consumer groups in that case as threads will remain idle if we use single consumer group. A more sophisticated algorithm could be required with multiple groups if we have to ensure the order of consumption.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        apache kafka  kafka  kafka consumer  kafka topic partitions  bigdata  consumer group  Q987. Is Iterator a class ?  
Ans. No, iterator is an interface that is used to parse through the elements of a Collection   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        collections  iterator  Q988. Can a lock be acquired on a class? How is it different than the object level lock ?  
Ans. Yes, a lock can be acquired on the class. Class level lock is applicable on the whole class and hence on all objects of the class whereas the object level lock is applicable on the respective object.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        synchronization  class level lock  object level lock  Q989. What is the use of Runtime Class ?  
Ans. This class is used to provide access to the Java runtime system   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        runtime class  jre  java runtimeFrequently asked.   Q990. What should a class do if its implementing an interface ?  Core Java 
Ans. It should either implement all interface methods or declare unimplemented methods as abstract.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        interfaces      Asked in 1 Companies        Basic          frequent  Try 1 Question(s) Test