Interview Questions and Answers - Order By Rating Q2731. How are values passed in Java ? By value or reference ? Core Java
Ans. Java only provides pass by value. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ebay   pass by value   pass by reference   method call   methods   functions   function call Asked in 10 Companies basic   frequent Q2732. Can we add more elements to an array list that has been marked as final ?
Ans. Yes, the array list can hold more elements. Final only puts the restriction that the array list reference cannot hold any other array list. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ebay   collections   arraylist   final keyword Q2733. Which Data Structure should be used for Load Balancer ?
Ans. [ Open Ended question ] Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  data structures   open ended questions   load balancer Q2734. What is the use of Synchronized block ? Core Java
Ans. The goal of a synchronised block is to achieve mutual exclusion i.e at one time, the segment of the code should be executed by single thread only and hence the lock needs to be retrieved before executing the segment and then released. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  synchronized block   synchronized   synchronization   multithreading   threads   mutual exclusion   concurrency Asked in 4 Companies intermediate   frequent Try 1 Question(s) Test Q2735. What is continuous integration ? Process
Ans. Continuous integration or CI is the practice, of merging all developer working copies to a shared mainline several times a day. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  continuous integration   jenkins  hudson   build toolsMust know at all levels. Among Top 10 frequently asked questions in Java. Very frequently asked to fresh graduates or less experienced professionals. Ans. Its a facility for code reuse and independent extension wherein a derived class inherits the properties of parent class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inheritance  object oriented programming (oops)  oops concepts  oops concepts  java concepts  code reuse  code re-use   classes  derived classes Asked in 14 Companies basic   frequent Q2737. What is a Java Bean ? How is it different from other Java classes ?
Ans. A Java bean is a class which abides by following conventions:
Core of the object is member elements and not operations ( methods )
Member Elements can be accessed by getters (and setters if those properties are not read-only).
serializable. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java bean   javabean   pojo   classes basic   frequent Q2738. What is ADT or Abtstract Data Type ? Core Java
Ans. ADT is a container which holds different types of objects with specifications.
For example - Stack, Array, Liked list, Tree Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  data types  abstract data types Q2739. Find the repeating number using O(n) time and constant space. Algorithm
Ans. http://www.geeksforgeeks.org/find-duplicates-in-on-time-and-constant-extra-space/ Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  algorithm   program   code   coding  makemytrip.com Q2740. 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 Q2741. 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 Q2742. 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 Q2743. 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 Q2744. 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 Q2745. What will happen if we don't have termination statement in recursion ?
Ans. Function call allocates a stackframe in stack. Every stackframe will use some memory to store local variables, parameters and to remember return address. Without terminating condition stackframes will keep consuming memory from stack and eventually program will result in stackoverflow error. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  recursion   break statement  break  stackoverflow exception  stackoverflow  memory management  memory  exceptions Q2746. 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 Q2747. 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 Q2748. What are different types of classes ? Core Java
Ans. There are different verticals in which Java Classes can be classified.
1. Access - Public , Private , default or Protected.
2. Packaging - System, library or User Defined
3. Structure - Outer or Inner
4. Object Derivation - Abstract Class or Concrete Class.
5. Object Creation - Normal, Singleton , Doubleton , Immutable or Enum.
6. Functionality - String , Util , Stream etc. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  classes   different types of classes Asked in 1 Companies Try 1 Question(s) Test Q2749. 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 Q2750. 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 Q2751. 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 Q2752. 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 Q2753. 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 Q2754. 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 Q2755. 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 Q2756. 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 Q2757. 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 Recently asked in Capital One. Q2758. What will happen if we call perform(null) ?
public void perform(Object obj) {
System.out.println("Object");
}
public void perform(Integer int) {
System.out.println("Integer");
} Core Java
Ans. compiler will throws error as ambiguous methods Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  overloading   method overloading Asked in 1 Companies intermediate Q2759. 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 Q2760. In which cases , moving methods to utility class could be useful ? Core Java
Ans. It could be worthy to move a method to util class if the method needs to be shared, doesn't require polymorphic behavior and need not be overridden in special cases.
Don't belong to one group through is-a relationship ( You can share through parent class method )
Don't implement a specific interface ( java 8 default methods )
Doesn't involve complex computing as you will be loosing the benefit of object state with just static method.
Doesn't require polymorphic behavior as static methods don't participate in runtime polymorphism. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  utility classes   util classes   static methods   application design   rare