Interview Questions and Answers - Order By Newest Ans. Generics are a facility of generic programming that were added to the Java programming language in 2004 within J2SE5.0. They allow "a type or method to operate on objects of various types while providing compile-time type safety. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  generics Asked in 7 Companies Q1212. What are the uses of Abstraction ? Core Java
Ans. Loose Coupling
Facilitates designing complex applications by making them modular. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  oops concepts  abstraction Asked in 1 Companies Q1213. Why is JVM called Virtual machine ? 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  jvm Q1214. Lets say we have a set "set1" with objects of Class A, Class has a non static string called element1, Write a code ( using lambda expression ) to see if there is any object in the set with element1 = "Hello". Core Java
Ans. set1.stream().filter(p->p.element1.equals("Hello")).findAny().isPreent();
or
set1.stream().map(A::getElement1).anyMatch("Hello"::equals) Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  lambda expressions  java 8  java8  java 8 filter  findAny() Q1215. Is Runtime Polymorphism possible without Inheritance ? Core Java
Ans. Yes, Runtime Polymprohism requires either Class inheritance or Interface implementation. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  runtime polymorphism  object oriented programming (oops)  oops concepts  method overriding  inheritance  object oriented programming (oops)  oops concepts Q1216. Why is Java such an important Programming language ? Core Java
Ans. Because of following features
Object Oriented and hence helps build maintainable and easily enhanceable code.
Platform Independence and hence can be executed anywhere
Fast due to JIT compiler Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q1217. Why Java is considered more purer object oriented language than C++ ? Core Java
Ans. Because of
lack of use of pointers,
Lack of structural programming and
Lack of Multiple Inheritance Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  oops  java vc c++ Q1218. Does Wrapper classes produces immutable objects ? Core Java
Ans. Yes Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  wrapper classes  immutable  immutability Q1219. Why shouldn't we use string concatenation extensively or in a loop ? Core Java
Ans. Because String being an immutable object creates a new object upon each concatenation cycle. If there is any such need , we should use String Builder whose objects are mutable. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string  string immutable  immutability  for loop  control statements  loop statement Asked in 1 Companies Q1220. What do we mean by a Data Type ? Core Java
Ans. if you have similar type of data or objects or entities, then we can give them a type with unique name. And this name will be our Data type. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  data type Q1221. In the following code, which text will get printed immediately after Hello
for(int countx=0;countx<10;count++){
System.out.println("World");
for(int countx=0;countx<10;count++){
System.out.println("Friend");
for(int countx=0;countx<10;count++){
System.out.println("Hello");
break;
}
System.out.println("Buddy");
}
}
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  break statement Q1222. Which of the two - iteration or recursion - is slower ? Core Java
Ans. Any function call is slower than the code in the same method as Java has to maintain stack of meta and function call information. So recursion is slower. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  iteration  recursion  iteration vs recursion Q1223. In case of generic class declared like following , What can T hold
class MyClass<T>{
T element;
} 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  generics Q1224. What features would you like to see in Java 10 ? 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  java10  java 10 Q1225. Can we instantiate the object of derived class if parent constructor is private ? Core Java
Ans. No Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor  private constructor Q1226. 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 Q1227. 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 Q1228. 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 Q1229. 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 Q1230. 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 Q1231. 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 Q1232. 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 Q1233. 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 Q1234. 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 Q1235. 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 Q1236. 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 Q1237. 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 Q1238. 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 Q1239. 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