Interview Questions and Answers - Order By Newest Q1631. Can we call a constructor for an object twice ? 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  constructorAns. Stack is based on Last in First out (LIFO) principle while a queue is based on FIFO (First In First Out) principle. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  data structure  stack vs queue  stack  queue Basic Q1633. Can we compile and execute a Java class without main method ? Core Java
Ans. No without main method can not be executed it will throw an error illegal start of type. Main method is the entry point of application. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  jvm  compilation  main method Basic Q1634. What is the purpose of re throwing the exception when we can provide the handling at the first catch itself ? Core Java
Ans. Sometimes the calls move across layers of classes and functions and hence each layer needs to perform some function like cleaning if something goes wrong deep inside. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exceptions  exceptions handling  rethrowing exception Q1635. What is the problem we could face if we be very liberal with importing classes even if we are not using them ? For example
import java.util.*;
import java.io.*; Core Java
Ans. It makes application little heavy as we are importing classes that aren't required.
It creates class name conflicts as similar name classes might be available across different packages. In case of such conflicts, we will have to specify the package name with the class name at the time of it's usage. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  import statement   java import Q1636. Which java package is loaded by default and hence doesn't require an explicit import statement ? Core Java
Ans. java.lang Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java.lang  import statement basic Q1637. How do we define constant variables in Java ? Core Java
Ans. By using static and final modifiers. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constant variables   static final basic   frequent Q1638. Can a source file contain more than one class declaration ? Core Java
Ans. Yes, but only one of them can be declared public. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  class declaration Q1639. Can an interface be defined inside a class just like we can have inner classes inside a class ? Core Java
Ans. Yes , we can have an interface that is part of a class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inner classes   inner interface  nested classes Q1640. Can an interface implements another interface ? Core Java
Ans. No. No interface provides any implementation and hence the declaration isn't viable. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  interface basic Q1641. Why doesn't java support operator overloading ? 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  operator overloading Q1642. What are the different ways in which dependency injection can be done using Spring Framework ? Spring
Ans. Using Constructor and Setters. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  spring  dependency injection   inversion of control Q1643. Difference between constructor and setter injection ? Spring
Ans. 1. In Setter Injection, partial injection of dependencies can possible, means if we have 3 dependencies like int, string, long, then its not necessary to inject all values if we use setter injection. If you are not inject it will takes default values for those primitives1. In constructor injection, partial injection of dependencies cannot possible, because for calling constructor we must pass all the arguments right, if not so we may get error
2. Setter Injection will overrides the constructor injection value, provided if we write setter and constructor injection for the same property [i already told regarding this, hope you remember ] But, constructor injection cannot overrides the setter injected values
3. If we have more dependencies for example 15 to 20 are there in our bean class then, in this case setter injection is not recommended as we need to write almost 20 setters right, bean length will increase. In this case, Constructor injection is highly recommended, as we can inject all the dependencies with in 3 to 4 lines [i mean, by calling one constructor]
4. Setter injection makes bean class object as mutable [We can change ] .Constructor injection makes bean class object as immutable [We cannot change ] Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  spring  dependency injection   inversion of control Asked in 3 Companies Q1644. Difference between ApplicationContext and BeanFactory ? Spring
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  ApplicationContext  BeanFactory   ApplicationContext vs BeanFactory   frequent Q1645. What are some limitations or dis advantages of Auto Wiring ? Spring
Ans. Autowiring a class of the same type throws an exception.
We can user @Qualifier to overcome this.
Autowiring cannot be used for primitives. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  spring  autowiring  spring auto wiring Q1646. What are the types of transaction management supported by Spring ? Spring
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  spring  spring transaction management Q1647. What are the different types of advices in AOP ? Spring
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  spring app  spring  aspect oriented programming Q1648. What is the use of upcasting in Java ? Core Java
Ans. Interfacing
Car extends Vehicle
Car car = new Car();
// now you need to call an API changeTires() which can change tires for all Vehicle Types and accepts argument of type Vehicle and hence you will have to upcast it
changeTires((Vehicle)car);
Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  upcasting  type casting Q1649. Why do we pass an array of strings to main method ? Core Java
Ans. Array of strings in the main method are the list of arguments or parameters which are sent to the application / program. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  main method   main method string array argument Q1650. In Java, what is the closest thing to pointers? Core Java
Ans. References.
Unlike pointers in C , Java references are strongly typed and we cannot do pointer arithmetics with them. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  pointers  pointers in java  references Asked in 1 Companies Q1651. In Java, would you like to see an explicit destructor? Core Java
Ans. Yes , a gc method to explicitly call garbage collection immediately on the object. It will provide better flexibility over application that require optimal usage of 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 1 Companies expert Q1652. How to calculate lcm of two numbers ? Core Java
This question was recently asked at 'HCL Tech'.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  coding  code Asked in 1 Companies Q1653. Write a Program to find age by birth date ? Core Java
Ans. LocalDate today = LocalDate.now();
LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1);
Period p = Period.between(birthday, today); //Now access the values as below
System.out.println(period.getDays());
System.out.println(period.getMonths());
System.out.println(period.getYears()); Sample Code for LocalDate Sample Code for Period Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  coding  code  date  LocalDate  Period Asked in 1 Companies Q1654. What is a session bean ? Java EE
This question was recently asked at 'BirlaSoft'.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  session bean   java bean Asked in 1 Companies Q1655. 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 Q1656. 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 Q1657. 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 Q1658. 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 Q1659. 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 Q1660. 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