Interview Questions and Answers - Order By Rating Q841. Can a lock be acquired on a class? How is it different than the object level lock ?
Ans. Yes, a lock can be acquired on the class. Class level lock is applicable on the whole class and hence on all objects of the class whereas the object level lock is applicable on the respective object. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  synchronization  class level lock  object level lockRelated Questions Q842. 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 javaRelated Questions Difference between == and .equals() ? Why is String immutable in Java ? Explain the scenerios to choose between String , StringBuilder and StringBuffer ?
or
What is the difference between String , StringBuilder and StringBuffer ? What are the difference between composition and inheritance in Java? Explain OOPs
or
Explain OOPs Principles
or
Explain OOPs Concepts
or
Explain OOPs features
or
Tell me something about OOPs What is a Lambda Expression ? What's its use ? What are different ways to create String Object? Explain. Why Char array is preferred over String for storing password? Does garbage collection guarantee that a program will not run out of memory? What is the difference between final, finally and finalize() ? Q843. 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  operatorRelated Questions a. interface b. abstract class c. final class d. util classAns.d. util class
Q845. What will be the output of executing following class ?
public class BuggyBread {
static {
System.out.println("Static Block");
}
{
System.out.println("Initialization Block");
}
BuggyBread(){
System.out.println("Constructor");
}
public static void main(String[] args){
System.out.println("Main Method");
}
}
Core Java
a. Static Block
Main Method b. Static Block
Instance Initialization Block
Main Method c. Static Block
Constructor
Main Method d. Static Block
Instance Initialization Block
Constructor
Main MethodAns.a. Static Block
Main Method
Q846. What will be the output upon executing following class ?
public class BuggyBread {
static {
System.out.println("Static Block");
}
{
System.out.println("Instance Initialization Block");
}
BuggyBread(){
System.out.println("Constructor");
}
public static void main(String[] args){
System.out.println("Main Method");
new BuggyBread();
}
} Core Java
a. Instance Initialization Block
Constructor
Static Block
Main Method b. Static Block
Instance Initialization Block
Constructor
Main Method c. Main Method
Static Block
Instance Initialization Block
Constructor d. Static Block
Main Method
Instance Initialization Block
ConstructorAns.d. Static Block
Main Method
Instance Initialization Block
Constructor
Q847. What will be the output of exceuting main method ?
public static void main(String[] args){
List list = new ArrayList();
list.add(1);
list.add(2);
list.add(3);
System.out.println(list);
} Core Java
a. 1,2,3 b. Order cannot be determined c. compilation error d. 3,2,1Ans.a. 1,2,3
Q848. What will be the output upon executing main method ?
public static void main(String[] args){
Set set = new HashSet();
set.add(1);
set.add(2);
set.add(3);
System.out.println(set);
} Core Java
a. 1,2,3 b. Order cannot be determined c. Compilation error d. 3,2,1Ans.b. Order cannot be determined
Q849. What is Dirty Read in Database Transactions ? Database
a. Data Read by Transaction 2 which hasn't yet updated by Transaction 1 b. Data Read by Transaction 2 which has been updated and commited by Transaction 1 c. Data Read by Transaction 2 which has been updated but not commited by Transaction 1 d. Inability of Transaction 2 to read Data when Transaction 1 is updating.Ans.c. Data Read by Transaction 2 which has been updated but not commited by Transaction 1
Q850. Which of following annotation is used to initialize objects before executing set of tests ? Reference Junit
a. @Test b. @Ignore c. @After d. @BeforeAns.d. @Before
Q851. Optional has been introduced in Java 8 to get away with which of following exception ? Reference Core Java
a. ArithmeticException b. ParseException c. NullPointerException d. FileNotFoundExceptionAns.c. NullPointerException
Q852. Which of the following methods are used by Java Garbage Collection Mechanism ? Core Java
a. final b. finally c. finalize d. All of the aboveAns.c. finalize
Q853. Which of the following about Garbage collection is false ? Core Java
a. We can call Garbage collection explicitly b. Garbage Collection guarantees that the application will not run out of memory c. finalize method is used by Java for Garbage Collection d. Garbage Collection Mechanism delete unclaimed objects that are no longer requiredAns.b. Garbage Collection guarantees that the application will not run out of memory
a. Feature to load the dependencies from Cache b. Feature to load all objects and relationships in advance before they can be used c. Feature to not load dependencies and relationship in advance and load when required d. Feature to not load the dependencies and relationships at allAns.c. Feature to not load dependencies and relationship in advance and load when required
Q855. Which of the following is not the benefit of Lazy Initialization in Hibernate ? Hibernate
a. Laod When required provides better performance b. Object stays lighter c. Less number of Database calls d. Less load on DatabaseAns.c. Less number of Database calls
Q856. What is the relationship between Vehicle and Engine in this example ?
public class Vehicle {
Enginer engine;
public void move(){
engine = new Engine();
engine.start();
}
} Core Java
a. Composition ( Vehicle has a Engine ) b. Composition ( Engine has a Vehicle ) c. Inheritance ( Vehicle is a Engine ) d. Inheritance ( Engine is a Vehicle )Ans.a. Composition ( Vehicle has a Engine )
Q857. What is the relationship between Car and Vehicle in the following code ?
public class Car extends Vehicle{
Engine engine;
public static void main(String[] args){
Vehicle vehicle = new Car();
car.move();
}
public void move(){
engine = new Engine();
engine.start();
}
} Core Java
a. Composition ( Vehicle has a Car ) b. Composition ( Car has a Vehicle ) c. Inheritance ( Vehicle is a Car ) d. Inheritance ( Car is a Vehicle )Ans.d. Inheritance ( Car is a Vehicle )
Q858. What is the problem with the following code ?
public class Car extends Vehicle{
Vehicle vehicle;
Car(){
super();
this.vehicle = new Vehicle();
}
} Core Java
a. There is an Inheritance as well as Composition relationship between Vehicle and Car which is not permitted b. We cannot initialize the parent class instance within the constructor c. Call to super is illegal d. There is no problemAns.d. There is no problem
Q859. Which of the following collections stores its elements in natural sorting order ? Core Java
a. HashMap b. LinkedHashMap c. TreeMap d. EnumMapAns.c. TreeMap
Q860. Which of following stores its elements in natural Sorting Order ? Core Java
a. AbstractSet b. HashSet c. LinkedHashSet d. TreeSetAns.d. TreeSet
Q861. What kind of thread is Garbage collection thread ? Core Java
a. Daemon Thread b. User Thread c. System Thread d. Active ThreadAns.a. Daemon Thread
Q862. Which of following are serialized ? Core Java
a. static variables b. transient variables c. instance variables d. method local variablesAns.c. instance variables
Q863. What will be the output of this code
ArrayList list = new LinkedList();
list.add(3);
list.add(2);
list.add(1);
System.out.println(list); Core Java
a. 1,2,3 b. 3,2,1 c. Order cannot be determined d. Compilation ErrorAns.d. Compilation Error
Q864. Which of following memory segment is cleaned by Garbage Collection Mechanism ? Core Java
a. Stack b. Heap c. Code d. CacheAns.b. Heap
Q865. In Case a method is declared to throw an exception , We can only use a call to that method if ... Core Java
a. We use the call within try block and catch the exception b. We declare that the method is expected to throw the exception using throws c. Both 1 and 2 d. Either 1 or 2Ans.d. Either 1 or 2
Q866. Which of the following is not an Hibernate Annotation Hibernate
a. @Id b. @JoinTable c. @ManyToMany d. @AutowiredAns.d. @Autowired
Q867. Which of following is not Spring MVC annotation ? Spring
a. @Autowired b. @Controller c. @JoinColumn d. @TransactionalAns.c. @JoinColumn
Q868. Which of the following is true ? Core Java
a. throw and throws are used to throw an exception b. throw is used to throw an exception whereas throws is a declaration that the method can throw the exception c. throws is used to throw an exception whereas throw is a declaration that the method can throw the exception d. throw and throws are used to declare that an exception can be thrown by the methodAns.b. throw is used to throw an exception whereas throws is a declaration that the method can throw the exception
Q869. throws is a declaration that the ..... is expected to throw an exception ? Core Java
a. Variable b. Method c. Class d. InterfaceAns.b. Method
Q870. Which of the following collection classes store their elements as Key Value pairs ? Core Java
a. Set b. List c. Map d. QueueAns.c. Map