Interview Questions and Answers - Order By Newest Must 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 Q782. 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 Q783. 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 Q784. 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 Q785. 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 Q786. 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 Q787. 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 Q788. 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 Very frequently asked to fresh graduates. Frequently asked in NSEiT and Accenture India Q789. 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 Q790. 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 Q791. 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 Q792. 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 Q793. 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 Q794. 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 Q795. What are the new classes in JDK 1.9 ( Java 9 ) ?
Ans. http://www.buggybread.com/2015/05/java-9-new-classes-and-interfaces-in.html Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java9  java 9  jdk1.9  jdk 1.9 Q796. 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 Q797. 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. Q798. 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 Q799. What should a class do if its extending an abstract class ? Core Java
Ans. It should either implement the abstract methods or re-declare them abstract. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  abstract class Asked in 2 Companies Basic   Frequent Q800. What is a compilation unit in Java ?
Ans. Java Source Code File Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  compilation unit in java Q801. What is Associativity while evaluating a Java statement ? Core Java
Ans. Associativity determines whether an expression is evaluated left-right or right-left. When an expression has two operators with the same precedence, the expression is evaluated according to its associativity. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  associativity  expression evaluation  operator Q802. What is the difference between following time formats ?
hh:mm:ss
HH:mm:ss
kk:mm:ss
KK:mm:ss Core Java
Ans. hh= hours in 1-12 format
HH= hours in 0-23 format
kk = Hours in 1-24 format
KK= hours in 0-11 format Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Date  Date Time Format  Date Time Q803. Write a java program to implement Quick sort ? Core Java
Ans. http://www.programcreek.com/2012/11/quicksort-array-in-java/ Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  quick sort  sort Asked in 2 Companies   frequent Frequently asked to Fresh graduates. Q804. Write a program to implement Binary search ? Core Java
Ans. http://algs4.cs.princeton.edu/11model/BinarySearch.java.html Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  binary search  search Asked in 5 Companies basic   frequent Try 1 Question(s) Test Q805. Which data structure would you recommend for ordered and sorted data? Core Java
Ans. TreeSet and TreeMap are used for maintaining sorted elements. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ordered collections  sorted collections Asked in 1 Companies basic   frequent Q806. Explain Exception Hierarchy in Java SE ? Core Java
Ans. <a href="http://www.programcreek.com/2009/02/diagram-for-hierarchy-of-exception-classes/" rel="nofollow">http://www.programcreek.com/2009/02/diagram-for-hierarchy-of-exception-classes/</a> Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exception hierarchy   exceptions Asked in 3 Companies Q807. What do you know about JQuery ? Java EE
Ans. jQuery is a cross platform JavaScript library designed to simplify the client-side scripting of HTML. JQuery is the most popular JavaScript library. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  jquery Asked in 1 Companies Q808. Can we have try statement without catch? If try statement contains return will the finally block be executed? What happens if there is an exception inside finally block? Core Java
Ans. Yes, with finally.
Yes, finally block will be executed even if there is no exception in try block.
If finally throws an exception, the exception gets thrown to the calling module. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exception handling Asked in 1 Companies intermediate Very Frequently asked to fresh graduates and less experienced. Q809. What are the principle concepts of Object Oriented Programming ? Core Java
Ans. Abstraction
Polymorphism
Inheritance
Encapsulation Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  oops  oops concepts Asked in 1 Companies basic   frequent Q810. What is an IP address ? Java EE
Ans. An Internet Protocol address is a numerical label assigned to each device participating in a computer network. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ip address Asked in 2 Companies basic   frequent