Interview Questions and Answers - Order By Rating        Q271. Difference between TreeMap and SortedMap ?  Core Java 
Ans. sortedMap is an interface ,while TreeMap is an implementation of sortMap. 
 
We can not create an instance of sortedMap but we can create an instance of treeMap   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        treemap  sortedmap  Q272. Difference between ArrayList and HashSet ?  Core Java 
Ans. ArrayList is a list , i.e an implementation of List interface whereas HashSet is a Set and an implementation of Set interface.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        arraylist  hashset  Q273. difference between ArrayList and array ?  Core Java 
Ans. ArrayList is a variable length collection class whereas arrays are fixed length primitive structure. 
 
We can use generics with arraylist but not with arrays. 
 
We can store primitive data types within arrays but can't with ArrayList. In ArrayList that needs to be converted to Wrapper objects. 
   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        arraylist  arrays  collection classes  collections       basic          frequent   Q274. What is the difference between final and static in java ?  Core Java 
Ans. final keyword is used to restrict the user from modifying the variable, extending the class and overriding a method 
 
static keyword is used for memory management which can be used for variable, class, method where in it belongs to the class not to the instance of object   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve              Asked in 2 Companies   Q275.  What is the difference between Encapsulation and encryption ?  Networking 
Ans. Encapsulation is the process of wrapping the data with another layer to be transported across the network with the source and destination details on just like the analogy of wrapping letter in envelope with the source and destination details on the envelope. Encryption on the other hand is the process of hashing text or transforming the data in a form that is not readable except you have access to the key use to decrypt it.    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve          Q276. Why is String a class in Java ?  Core Java 
Ans. 1. Creating a class helps in specifying operations on the Strings like length , sub string , concatenation etc. 
 
2. It acts as a Wrapper class for "Array of Characters" and hence facilitates it's usage in collections, assignment to null. 
 
3. Immutability of String objects facilitates in reuse , security and caching.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        string class  Q277. Difference between equals and compareTo in Java ?  Core Java 
Ans. "equals" is the method of object class which is supposed to be overridden to check object equality. x.equals(y) means the references x and y are holding objects that are equal.  
 
The compareTo() method is used for comparing two objects in Java. It is usually defined for the classes whose objects needs to be ordered through Comparable interface or need to be part of an ordered collection like TreeSet or TreeMap.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        equals  compareTo  equals vs compareTo  Q278. Is ConcurrentHashMap synchronized ?  Core Java 
Ans. Yes, ConcurrentHashMap is synchronized.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        ConcurrentHashMapAns. No HashMap isn't synchronized. ConcurrentHashMap and Hashtable are synchronized.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        hashmap  synchronizationAns. Yes   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        aws param store  amazon param store  aws lambda  amazon lambda  Q281. What measures would you take to avoid Java threading issues in a multi-threaded environment ?  
  This question was recently asked at 'Fifth Third Bank'.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   Q282. Does abstract class have public constructor?    Core Java 
Ans. Yes, an abstract class can have a constructor in Java.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        abstract class  public constructor      Asked in 1 Companies   Q283. Explain CloneNotSupportedException ?  Core Java 
Ans. If we do not mention, Cloneable Interface to the Class which we want to Clone then we get this exception, only if we try to clone an object 
 
Like:  
public class TestClone{ 
        @Override 
   protected Object clone() throws CloneNotSupportedException { 
      return super.clone(); 
   } 
} 
 
In Main, You try to do: 
                TestClone clone = new TestClone(); 
       
      TestClone clone2 = (TestClone) clone.clone(); 
 
You will get CloneNotSupportedException. 
 
Just add -> public class TestClone implements Cloneable { 
 
and things are fixed.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        exceptions handling  cloning  Q284. Why Hadoop serialized data types are not using in Spark serialization ?  BigData 
  This question was recently asked at 'Tavant Technology'.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   Q285. Explain when you would decide to use open authentication ?  Authentication 
Ans. Google OAuth can be used when we want to grant the access of our google credentials to the service provider ( most likely a cloud-based mobile application) by using the option ' Login via Google'   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        open authentication      Asked in 1 Companies   Q286. What does 'variable hoisting' mean?    JavaScript 
Ans.    Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve              Asked in 1 Companies   Q287. How many heaps will be there with 3 threads ?  Core Java 
Ans. All threads share a common heap. 
 
Each thread has a private stack, which it can quickly add and remove items from. This makes stack based memory fast, but if you use too much stack memory, as occurs in infinite recursion, you will get a stack overflow.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        memory management  heap memory      Asked in 1 Companies   Q288. Please explain the architecture of our application through a diagram ?  General 
  This question was recently asked at 'Alfresco Software,Ancestry'.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 2 Companies   Q289. What are the disadvantages of binary search trees?    Algorithm 
  This question was recently asked at 'ServiceNow'.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        binary search tree      Asked in 1 Companies   Q290. How to write an iterator for an iterator of iterators?  Core Java 
Ans. CustomArrayList myarrayList = new CustomArrayList(); 
      myarrayList.add("Value 1"); 
      myarrayList.add("Value 2"); 
      myarrayList.add("Value 3"); 
       
      for (String string : myarrayList) { 
         System.out.println(string); 
      } 
 
 
 
package sample.utils; 
 
import java.util.ArrayList; 
import java.util.Iterator; 
import java.util.List; 
 
public class CustomArrayList implements Iterable { 
 
   private ArrayList mylist = new ArrayList(); 
 
   public void add(T t) { 
      this.mylist.add(t); 
   } 
 
   @Override 
   public Iterator iterator() { 
      return new CustomIterator(mylist); 
   } 
 
   class CustomIterator implements Iterator { 
 
      private int indexPosition = 0; 
      private List internalList; 
 
      public CustomIterator(List internalList) { 
         this.internalList = internalList; 
      } 
 
      @Override 
      public boolean hasNext() { 
         if (internalList.size() >= indexPosition   1) { 
            return true; 
         } 
         return false; 
      } 
 
      @Override 
      public E next() { 
         E val = internalList.get(indexPosition); 
         indexPosition  ; 
         return val; 
      } 
 
   } 
 
}   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        iterator      Asked in 1 Companies   Q291. Do you think it's a good practice to keep passwords in config files ?  Solution 
Ans. We can keep them in config as encrypted values.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve          Q292. Can we keep application configuration at different places and what could be the consideration for choosing multiple places for doing so ?  Design 
Ans. Yes an application can have configuration stored at multiple places. Factors that could facilitate such a design could be  
 
1. Type of config information - We may have a case to store confidential information differently than other regular config value 
 
2. Environment - We may like to have a base config ( defined in application package ) and then a different override mechanism in different environments. 
 
3. Centralization - Sometime some configs need to be shared across application and hence centralized. 
 
4. Testing - Testing against config may not be possible in some enviornments in certain cases and hence additional config store might be kept for testing purpose only.   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        Design  Solution  Q293. Write a calculator and find if a character appears more than n times ?  Design 
  This question was recently asked at 'Mercury Systems'.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   Q294. How would you test a Twitter application ?   Testing 
  This question was recently asked at 'Slalom'.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        solution  testing      Asked in 1 Companies   This question was recently asked at 'IBM India'.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        queue  stack      Asked in 1 Companies   Q296. Code an elevator simulator.  Design 
  This question was recently asked at 'TrustArc'.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   Q297. What is the minimum number of tables required to perform a SQL join?  Database 
Ans. 1 , We can do self join 
   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        sql join      Asked in 1 Companies   Q298. What is a difference between JUnit 3 and 4 ?  Junit 
  This question was recently asked at 'Conde Nast'.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        testing  junit      Asked in 1 Companies   Q299. Can we have a final argument in a method ? What is the use of that if we do so ?  Core Java 
  This question was recently asked at 'Webster Bank'.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   Q300. why is "".equals(str); safer than str.equals("")?  Core Java 
Ans. str.equals("") this statement will throw NullPointerException if str is null where as "".equals(str) works fine even if str is null   Help us improve. Please let us know the company, where you were asked this question   :       Like            Discuss            Correct / Improve        equals method      Asked in 1 Companies