Interview Questions and Answers - Order By Newest Q1301. Explain Inheritance and Polymorphism. Core Java
Ans. Getting parent class object properties into child class is called Inheritance.
The process of representing one form into multiple forms is called polymorphism. 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  polymorphism  object oriented programming (oops)  oops concepts Asked in 1 Companies Basic   frequent Q1302. What is the difference between access and error log ? Logging
Ans. We log each access to the application resource within access logs, something like
"GET / HTTP/1.0" 200 113 "-" "Mozilla/5.0 zgrab/0.x" "-"
We log only error / warn messages within error logs, something like
ERROR 123#0: *19 connect() failed Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  logging  access log  error log Q1303. If Table A has 100 records and Table B has 50 records , how many records will the equi join of Table generate ? SQL
Ans. It depends on the join condition. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  equi join  sql join  database  sql Q1304. If Table A has 100 records and Table B has 50 records , how many records will the left join of Table A with Table B generate ? SQL
Ans. 100 records Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  database  sql  sql joins   left join Q1305. If Table A has 100 records and Table B has 50 records , how many records will the right join of Table A with Table B generate ? SQL
Ans. 50 records Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  database  sql  sql joins   right join Q1306. If Table A has 0 records and Table B has 50 records , how many records will the equi join of Table generate ? SQL
Ans. 0 records Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  database  sql  sql joins   equi join Q1307. What will be the output of following code
class TestMain {
public static void main(String[] args) {
String s1 = "ravi";
String s2 = new String("ravi");
Integer i = 10;
Integer a1 = new Integer("10");
System.out.println(s1 == s1);
System.out.println(i == a1);
}
} 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  ==  coding  code Asked in 1 Companies Q1308. Will the following code compile ?
final HashMap hm = new HashMap();
hm.put("Ravi", 221); Core Java
Ans. Yes, it will compile without error. final in this context means that the reference hm cannot be assigned to a new hash map but didn't restrict from changing the state of collection already held by hm. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  final  final variable Asked in 1 Companies Q1309. What is the difference between being final and being immutable ? Are string final or immutable in Java ? Core Java
Ans. Being final in the sense of objects or object reference means that the reference cannot be reassigned to a different object whereas being immutable means that the object contents cannot be changed.
Strings in Java are immutable. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string  immutable  immutability  final vs immutable  immutability Q1310. What does the following initialization mean ?
ArrayList<LinkedList> traversalPaths = new ArrayList<LinkedList>();
What could be the use of such a collection. Core Java
Ans. Initialize an ArrayList that will hold LinkedLists i.e every element of the arraylist will be a linked list.
Such collection could be used in algorithms that require first random access and then sequential traversal. For example - Storing traversal paths for a graph wherein we can start from any vertex. Implementing dictionary with each arraylist element holding staring with character and then linked list holding duplicate words. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  collections  linkedlist  arraylist Q1311. Given the list of adjacent nodes, What will be the Breadth First path
1 -> 2
1 -> 3
1 -> 6
2 -> 4
3 -> 5
Algorithm
Ans. 1 -> 2 -> 3 -> 6 -> 4 - > 5 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  breadth first traversal  graph traversal Q1312. Given the list of adjacent nodes, What will be the Depth First path
1 -> 2
1 -> 3
1 -> 6
2 -> 4
3 -> 5 Algorithm
Ans. 1 -> 2 -> 4 -> 3 -> 5 -> 6 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  depth first traversal  graph traversal Q1313. What will happen in a graph traversal if we don't have a check for cycle Algorithm
Ans. It will result in never ending loop Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  graph traversal Q1314. What is the difference between return and continue statement ? Core Java
Ans. return is used within a method to return control out of the method. It may be followed by a value which is returned from the method to calling method immediately preceding the point of call.
continue statement is used within a loop to start next iteration without executing the remaining statements in the loop. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  return statement  continue statement  return vs continue  for loop  control statements  loop statement Q1315. What is the difference between Java SE Map and Apache Commons MultiMap ? How can we implement functionality similar to multimap using Java SE map ? Core Java
Ans. We can have duplicate keys within MultiMap whereas we cannot have duplicate keys within Java Util Map.
We can have a Map with value as a "collection of values" instead of single value to have a similar function as Multimap. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Apache commons multimap  map vs multimap Q1316. Is it a bad practice to initialize object reference to Null ? Core Java
Ans. never initialise local to null,yes it is bad pratice Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  null  nullpointerexception Q1317. What will be the output of following code and Why ?
int x = 5;
int y = 7;
float f = 5f;
float z = y / x * f;
System.out.println(z); Core Java
Ans. 5.0
operation between two ints generate int only. so 7/5 generates 1 and not 1.4. Multiplication between int and float generates float and hence
1 * 5.0 = 5.0 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arithmetic calculation  data types Q1318. Can we synchronize the run() method 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  synchronization  multithreading  run methodAns. if statements nested within another if or else blocks are called nested if statements.
if(condition1) {
if(condition2){
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  if statement  control statements   nested if Q1320. what are different pointer operators used ? Core Java
This question was recently asked at 'Huawei Technologies'.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   Asked in 1 Companies Q1321. Do we have a method to reverse a string in String class ? Core Java
Ans. No but we have it in StringBuilder. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  String  StringBuilder  Reverse a string Q1322. How different is it when final applied to variables and object references ? Core Java
Ans. final when assigned to object references doesn't make them immutable. It means that the references cannot be de-referenced.
final when applied to variables means that the value cannot be changed. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  final keyword  final variable Q1323. Why the following code produced this output ?
int x = 5;
int y = x;
y = 10;
System.out.println(x); // prints 5 and not 10 Core Java
Ans. Because when we say y = x, the value of x is copied to another memory location and then y points to that new memory location.
Unlike object references that once assigned point to same object in memory, value is copied in case of variable assignment. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  variable assignment Q1324. Describe how you could use a single array to implement three stacks Algorithm
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  Data Structure Q1325. How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time Algorithm
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  Data Stricture   Big O Notation  time complexity Q1326. Write a program to sort a stack in ascending order You should not make any assumptions about how the stack is implemented The following are the only functions that should be used to write this program: push | pop | peek | isEmpty Algorithm
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  Data StructuresAns. 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 Q1328. 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 Q1329. 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() Q1330. Which of the OOP's features facilitate dependency injection ? Design
Ans. Inheritance , Runtime Polymorphism and Composition. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  dependency injection  inversion of control  ioc  oops  oops features