Interview Questions and Answers - Order By Newest Q91. Write a Program to check if 2 strings are Anagrams ? Core Java
Ans. public void checkIfAnagram(String str1,String str2){
boolean anagram = true;
for(char c:str1.toCharArray()){
if(!str2.contains(String.valueOf(c))){
System.out.println("Strings are Anagrams");
anagram = false;
}
if(anagram == true){
System.out.println("Strings are not Anagrams");
}
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   check if 2 strings are Anagrams Asked in 30 Companies basic   frequent Q92. Difference between ArrayList and LinkedList ?
Ans. LinkedList and ArrayList are two different implementations of the List interface. LinkedList implements it with a doubly-linked list. ArrayList implements it with a dynamically resizing array. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   list   arraylist   linkedlist   difference between basic   frequent Q93. Which are the sorted collections ? Core Java
Ans. TreeSet and TreeMap Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   treemap   treeset   basic interview question basic   frequent Very frequently asked if being interviewed for hibernate. Frequently asked in Tata Consultancy (TCS) and Overstock.com Q94. Difference between load and get ? Hibernate
Ans. If id doesnt exist in the DB load throws an exception whereas get returns null in that case.get makes the call to DB immediately whereas load makes the call to proxy. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate Asked in 16 Companies basic   frequent Q95. When does an application throw NullPointerException ? Core Java
Ans. When it tries to access an object element or method using reference which is actually null. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exceptions   npe   nullpointerexception Asked in 1 Companies basic   frequent Q96. How is Abstraction implemented in Java ? Core Java
Ans. Abstraction is provided in Java by following ways -
Coding to the ( Interfaces / Abstract Classes ) or contracts
By Encapsulating details within classes and exposing the minimal Door ( few public methods ) Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops concepts   abstraction   interfaces   abstract class   encapsulation  object oriented programming (oops)  oops concepts Asked in 3 Companies basic   frequent Q97. Which java frameworks have you used ? General
Ans. I have primarily worked on Web applications and hence worked on Struts , Spring , Hibernate, JSF ( Java Server Faces ) , Velocity etc. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  elsevier   frameworks   java frameworks   general question Asked in 3 Companies basic   frequent Q98. 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 Q99. What is a package and what are its advantages ? Core Java
Ans. Package is a namespace that organizes a set of related classes.
Advantages of Packages
1. Better Organization of classes.
2. Saves from the problem of duplicate names as duplicate class names are allowed across different packages. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  package  advantages of packages Asked in 1 Companies Basic Q100. What is a Database Trigger ? Database
Ans. A trigger is a special kind of stored procedure that automatically gets executed upon an event in the database server. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  database   trigger Asked in 10 Companies basic   frequent Q101. What is a self Join and give an example of a self Join ?
or
What is self Join and What is it's purpose ? Database
Ans. When a Table Join itself , it's a Self Join. For example - we like to know the pair of department names where first dept has lesser employees than the later.
Select D1.name , D2.name from Dept D1, Dept D2 where D1.employee_count < D2.employee_count Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  sql  joins  self join  self-join  Pair of employee names with first having lesser salary than later  Pair of department names where first dept has lesser employees than the later Asked in 26 Companies basic   frequent Frequently asked. Q102. When does the finally block gets executed ? Core Java
Ans. A finally block of code always executes, whether or not an exception has occurred.The only time finally won't be called is if you call System.exit() or if the JVM crashes first. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  finally  exception handling  exceptions Asked in 4 Companies basic   frequent Ans. System is a class within java.lang package that contains several useful class fields and methods. It cannot be instantiated and hence can use only statically.even in this case this has been used statically i.e with class name itself and without creating an instance.
out is the static reference of Printstream declared as following in the System Class -
public final static PrintStream out = null;
println is the method of PrintStream class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  System class  Streams  Input Output  println Asked in 1 Companies basic   frequent Q104. Does java supports operator overloading ? Core Java
Ans. No Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  operator overloading Asked in 1 Companies basic Q105. What is the use of static keyword in Java ? Core Java
Ans. static keyword is used to specify that the respective programming construct ( method , variable ) belongs to the class and not to its instance and is supposed to be shared by all instances of the class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  static keyword Asked in 1 Companies basic   frequent Q106. Explain various Searching and Sorting Algorithms ? Algorithm
This question was recently asked at 'HeadStrong,ServiceNow'.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  Search Algorithm  Sorting Algorithm Asked in 2 Companies basic   frequent Q107. What is a Servlet Filter ? Java EE
Ans. It's an object that can intercept http request and response and hence we can take appropriate action on those requests.
There are different types of filters based on Specifications like
Authentication
Logging
Encryption
Tokenizing
etc Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  servlets  servlet filters Asked in 3 Companies basic   frequent Q108. What is the difference between authentication and authorization ? Authentication
Ans. Authentication is the process of verifying the identity and credentials of the user to authenticate him into the system.
whereas
Authorization is the process by which access to a segment , method or resource is determined.
Authorization is usually a step next to authentication. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  authentication  authorization  authentication vs authorization Asked in 9 Companies basic   frequent Q109. What access the variable gets if we don't provide any access specifier ? Core Java
Ans. It gets the default access i.e package protected. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  access specifiers  default Access specifier Basic Q110. How does java identifies which method to be called in method overriding or runtime polymorphism, when both methods share the same name and signature ? Core Java
Ans. Java identifies the method to be called at runtime by the object that is being referenced. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  polymorphism  object oriented programming (oops)  oops concepts  overloading  overriding basic Ans. == compares values === is used in scripting languages for comparing two values as well as there data tpe. like in js,php. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ==  ===  == vs === Asked in 13 Companies basic   frequent Q112. What are the types of authentication used in Web services ? Web Service
Ans. Encrypted User Name / Password
Encrypted Password within Cookie
Encrypted Tokens
IP
Client Certificates
Oauth Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  authentication  security  web service Asked in 12 Companies basic   frequent Q113. Write code to create a folder if it doesn't exist. Core Java
Ans. File folder = new File(path);
if(!folder.exists()){
try {
folder.mkdir();
} catch (Exception e) {}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  code  coding  file handling basic Q114. Difference between Arrays and ArrayList ? Core Java
Ans. Both Arrays and ArrayLists are used to store elements. Elements can be either primitives or objects in case of Arrays, but only objects can be stored in Arraylist. Array is a fixed length data structure while arraylist is variable length collection class. Once created, you cannot change the size of the arrays, but arraylists can dynamically resize itself when needed.Another notable difference between Arrays and Arrayslist is that arary is part of core java programming and array list is part of collection classes Sample Code for arrays
arraylist Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  array  arraylist  array vs arraylist Asked in 7 Companies basic   frequent Q115. Can static method access instance variables ? Core Java
Ans. Though Static methods cannot access the instance variables directly, They can access them using instance handler. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  static   static method   java   oop   variables Asked in 1 Companies basic   frequent Very frequently asked. Usually asked in this format or as difference with interfaces / concrete classes. Ans. Abstract class is the class that is not supposed to be instantiated. The purpose of the class to only have extension to the derived class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  abstract class Asked in 6 Companies basic   frequent Q117. Which interface does java.util.Hashtable implement? Core Java
Ans. Java.util.Map Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   hashtable   map basic   rare Frequently asked. Ans. Iterator is an interface that provides methods to iterate over any Collection. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   iterator Asked in 11 Companies basic   frequent Q119. Which interface provides the capability to store objects using a key-value pair? Core Java
Ans. java.util.map Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   map basic   frequent Q120. Why java doesn't support multiple Inheritence ? Core Java
Ans. class A {
void test() {
System.out.println("test() method");
}
}
class B {
void test() {
System.out.println("test() method");
}
}
Suppose if Java allows multiple inheritance like this,
class C extends A, B {
}
A and B test() methods are inheriting to C class.
So which test() method C class will take? As A & B class test() methods are different , So here we would Facing Ambiguity. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   inheritence   multiple inheritence Asked in 1 Companies basic   frequent