Interview Questions and Answers - Order By Newest Q151. Difference between Encapsulation and Data Hiding ?
Ans. Data Hiding is a broader concept. Encapsulation is a OOP's centri concept which is a way of data hiding in OOP's. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   oops concepts   encapsulation   data hiding   build management basic Q152. What is the use of HashCode in objects ? Core Java
Ans. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   string   hashcode   hash code   string comparison  hashtable Asked in 17 Companies basic   frequent Q153. What will be the output of the following code ?
String s1 = "Buggy Bread";
String s2 = "Buggy Bread";
if(s1 == s2)
System.out.println("equal 1");
String n1 = new String("Buggy Bread");
String n2 = new String("Buggy Bread");
if(n1 == n2)
System.out.println("equal 2"); Core Java
Ans. equal 1 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   string class   string   string pool   code   coding basic   frequent Ans. PATH is the variable that holds the directories for the OS to look for executables. CLASSPATH is the variable that holds the directories for JVM to look for .class files ( Byte Code ). Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   path   classpath   byte code   jvm   basic interview question Asked in 3 Companies intermediate   rare Q155. Which markup languages can be used in restful web services ? Rest
Ans. XML and JSON ( Javascript Object Notation ). Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   web services   rest   java   j2ee   xml   json   architecture basic   frequent Q156. Difference between Inner and Outer Join ? Database
Ans. Inner join is the intersection of two tables on a particular columns whereas Outer Join is the Union of two tables. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  sql   joins   inner join   outer join Asked in 4 Companies basic   frequent Ans. It's a facility that allows traversal over the records pulled from a table or combination of tables. Its like iterator in Java. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  databases   sql   cursors   packages Asked in 5 Companies basic   frequent Q158. Which of the following syntax are correct ?a. LinkedList<Integer> l=new LinkedList<int>();b. List<Integer> l=new LinkedList<int>();c. LinkedList<Integer> l=new LinkedList<Integer>();d. List<Integer> l = new LinkedList<Integer>(); Core Java
Ans. All are correct. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   generics   linkedlist   list   collections basic Q159. Can we have null keys in TreeMap ? Core Java
Ans. No, results in exception. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   treemap Asked in 6 Companies Basic   frequent Q160. What are the different types of inheritance in Hibernate ? Hibernate
Ans. Table Per Class , Table per Sub Class , Table per Concrete Class Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   orm   inheritance hibernate Asked in 1 Companies Basic   frequent Q161. How to do Eager loading in Hibernate ? Hibernate
Ans. Using lazy = false in hibernate config file or @Basic(fetch=FetchType.EAGER) at the mapping Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   lazy loading hibernate   basic annotation hibernate   architecture Q162. What is the difference between int[] x; and int x[]; ? Core Java
Ans. No Difference. Both are the acceptable ways to declare an array. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   array   arrays   array declaration   difference between Asked in 3 Companies basic Q163. How can we protect an application from throwing a NullPointerException ?
Ans. By having Null Checks. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exceptions   npe   nullpointerexception   null checks basic   frequent Q164. Why is a constant defined as a static final in Java? Core Java
Ans. Final makes sure that the value doesn't change after initialization and static makes sure that there is only one copy that can be shared across objects. Making it non static will unnecessarily create a different copy per object wherein the same value will kept for all copies ( as its final and cannot be changed ). Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   static   final variables   variable constants basic   frequent Q165. What is Criteria in Hibernate ? Hibernate
Ans. Criteria is a simplified API for retrieving entities by composing Criterion objects.
For example - session.createCriteria(Employee.class).add( Restrictions.like("name", "A%") ).list();
will return all employee objects having name starting with A. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   hibernate criteria Asked in 7 Companies Basic   Frequent Try 1 Question(s) TestAns. It is a continuous integration tool written in Java. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   jenkins Asked in 6 Companies Basic   frequent Q167. Which takes more memory - float or Float ? Core Java
Ans. float is a native data type whereas Float is a class. A Float object will always take more memory than float variable as there are metadata overheads with the objects. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   data type   float Asked in 3 Companies basic   frequent Q168. Which of the collections allows null as the key ?
a. HashTable
b. HashMap
c. TreeMap
d. LinkedHashMap Core Java
Ans. HashMap Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   map  hashtable Asked in 2 Companies basic   frequent Q169. Difference between prefix and postfix increment operator ?
Ans. Prefix operator performs the increment and then assignment whereas its inverse for postfix operator. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  prefix increment operator   postfix increment operator   operators   java basic   frequent Q170. Have you ever had any conflict with the team member (like disagreement on some design decision ) and How you reacted to it ? General
Ans. [Open Ended Answer]
This is a very sensitive question and should be dealt with caution. Just simply saying that you never had any disagreement will present you as dumb team member. Showing your self as too aggressive in such decisions will present you as a trouble maker. You should present a situation where you had an argument / disagreement but eventually you and your team mates mutually found a way out of it. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 20 Companies basic Frequently asked in face to face interviews. Q171. Write a program to print fibonacci series. Core Java
Ans. int count = 15;
int[] fibonacci = new int[count];
fibonacci[0] = 0;
fibonacci[1] = 1;
for(int x=2; x < count; x++){
fibonacci[x] = fibonacci[x-1] + fibonacci[x-2];
}
for(int x=0; x< count; x++){
System.out.print(fibonacci[x] + " ");
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ebay   fibonacci series Asked in 66 Companies basic   frequent 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 Q173. 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 Q174. 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 Q175. 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 Q176. 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 Q177. 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 Q178. 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 Q179. 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) TestFrequently asked. Q180. 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