Interview Questions and Answers - Order By Newest Q871. Can an enum extend another enum ? Core Java
Ans. No Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  enum Q872. Can we have a sub enum within an enum ? Core Java
Ans. Yes Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  enum  enum within enum Q873. If a Map needs to be accessed simultaneously by multiple threads, which collection class should be used ? Core Java
Ans. ConcurrentHashMap Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  map  concurrenthashmap  multithreading Q874. Given a collection of Employee objects, how can we get the customers with name starting with 'A' using lambda expression. Core Java
Ans. List emp = Arrays.asList("American", "Indian", "Finn");
emp.stream().filter(em -> em.startsWith("A")).forEach(System.out.println); Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java8  java 8  lambda Asked in 1 Companies Q875. What is the difference between stream and parallel stream ? Core Java
Ans. streams are used for sequential processing of data and parallel streams are used for parallel processing of data (only if the underlying processor is multicore). Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  stream vs parallel stream  stream  parallel stream Asked in 1 Companies Q876. What are the advantage of Abstract classes over interfaces with respect to Java 7 ? and What changed in Java 8 to help facilitate that in Java 8 ? Core Java
Ans. Abstract Classes provide default implementations of methods that are inherited by the classes that extend them, which was not the case for Interfaces. This changed in Java 8, where default implementations are provided for methods. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  abstract classes  interfaces  default method Asked in 1 Companies expert Q877. Why do we use Thread Class as well as Runnable Interface for creating threads 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  Threads  Thread class  runnable interface Q878. Why can we have a static inner class but not a static Top level class 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  static class  inner classes   nested classes Expert   rare Q879. Write a Program to print fibonacci series using recursion. Core Java
Ans. public class FibonacciUsingRecursion {
public static void main(String[] args) throws IOException{
getNextFibanocci(1,1);
}
static int getNextFibanocci(int a,int b){
if(a+b >= 100){
return 0;
} else {
System.out.println(a+b);
getNextFibanocci(b,a+b);
}
return 0;
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  fibonacci  recursion Q880. Can we use primitive types with Collection classes ? Core Java
Ans. No, As collection classes involve use of Generics, they cannot accept primitive types. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  collection classes  collections Q881. Is immutability an advantage with Wrapper classes over primitive types ? Core Java
Ans. There is no concept of de referencing with primitive types and hence they are implicitly immutable. Having wrapper classes as mutable offers disadvantages compared to primitive types. Wrapper classes being immutable offer similar advantage as primitive types.It actually overshadows the disadvantage wrapper class could have if they are immutable. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  immutable  immutability classes  wrapper classes Q882. Do we have Integer constant pool of primitive int or Integer objects ? Core Java
Ans. It's of Integer objects and not primitive int. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  integer constant pool Q883. Which objects are eligible for garbage collection ? Core Java
Ans. Objects that have lost their reference i.e. they cannot be accessed/used by the program anymore. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  garbage collection Asked in 1 Companies basic Q884. Do we have sorted collection for List ? Core Java
Ans. Not in java.util Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   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  blockingqueue  collections Q886. Which immutable classes have you worked with ? Can you name some immutable Collections ? How to make an immutable collection ? Core Java
Ans. string and wrapper class objects Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  immutability  immutable  immutability classes   immutable  immutability collections Asked in 3 Companies Q887. What are the benefits of immutability or Immutable classes ? Core Java
Ans. Immutable objects are thread-safe so you will not have any synchronization issues.Immutable objects are good for Map keys and Set elements, since these typically do not change once created.Immutability makes it easier to write, use and reason about the code (class invariant is established once and then unchanged)Immutability makes it easier to parallelize your program as there are no conflicts among objects.The internal state of your program will be consistent even if you have exceptions.References to immutable objects can be cached as they are not going to change. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  immutable  immutability classes   benefits of immutable  immutability classes Asked in 1 Companies Q888. How is LinkedList collection class internally implemented ? Is it a Linked List or Doubly Linked List ? Core Java
This question was recently asked at '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  linkedlist  internal implementation of linkedlist Asked in 1 Companies Q889. How ConcurrentHashMap provides better performance compared to HashTable ? Core Java
Ans. ConcurrentHashMap uses multiple buckets to store Data and hence avoid read locks which facilitates better performance. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ashTabl expert   rare Q890. What are annotations and what are it's advantages ? Core Java
This question was recently asked at 'Tata Consultancy (TCS)'.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 Q891. Suppose we have a string "Java is object oriented language" and we have to reverse every alternate word in string. How would we do that using Java program. Core Java
This question was recently asked at 'datalake solutions'.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  string manipulation  code  coding Asked in 1 Companies Q892. How to convert array to list in Java ? Core Java
Ans. We can use Arrays.asList Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q893. How much by default filling ratio in HashMap ? 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   Q894. Can we override wait() or notify() ? Core Java
Ans. No, because these are final.
public final void wait() throws InterruptedException
public final void notify() Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  wait  notify Asked in 1 Companies This question was recently asked at 'newGen'.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 Q896. A Kid can go up 1, 2 or 3 stairs in one step. Write a method that takes number of steps in a stair will print all possible ways he can take.
For example , printAllCombinations(3) should print
111
12
21
3
Similarly , printAllCombinations(4) should print
1111
121
13
211
22
31
4 Core Java
Ans. public static String findStep(int n) {
if (n == 1 || n == 0)
return 1;
else if (n == 2)
return 2;
else
return findStep(n - 3) + findStep(n - 2) + findStep(n - 1);
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  coding Asked in 1 Companies Q897. Write a method that takes an integer and verifies if the number is power of 10. Core Java
Ans. public static boolean isPowerOfTen(long input) {
if (input % 10 != 0 || input == 0) {
return false;
}
if (input == 10) {
return true;
}
return isPowerOfTen(input/10);
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  check if number is power of 10 in java Asked in 1 Companies Q898. What is the default data type of state variables in Clonable interface and Serializable interface ? Core Java
Ans. Cloneable and Serializable are Marker Interfaces, So these are empty interfaces with no variables. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  cloneable  serializable  static variables Asked in 1 Companies Q899. How can i split a linked list in two parts in java 8? Core Java
Ans. This can be done using a Spliterator.
LinkedList list = Arrays.asList("names","numbs","birds","animals");
Spliterator split1 = list.Spliterator();
Spliterator split2 = split1.Spliterator();
Now, the LinkedList is split into split1 and split2.
use split2 first then split1 to check the output. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java 8  parallel stream  spliterator Asked in 1 Companies Q900. how does abstraction help your application ? Core Java
This question was recently asked at 'Intel'.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  abstraction  oops concepts Asked in 1 Companies basic