Core%20java - Interview Questions and Answers for 'L' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Core%20java - Interview Questions and Answers for 'L' - 0 question(s) found - Order By Newest

 Q1. What will be the output of following ?

String str1 = new String("String1");
String str2 = new String("String1");
System.out.print(str1 == str2);
System.out.print(str1.equals(str2));
str1 = str2;
System.out.print(str1 == str2);
Core Java
a. falsetruetrue
b. truetruetrue
c. truetruefalse
d. falsetruefalse

Ans.a. falsetruetrue

 Q2. What will be the output of following code ?

String str1 = "String1";
String str2 = "String1";
System.out.print(str1 == str2);
System.out.print(str1.equals(str2));
str1 = str2;
System.out.print(str1 == str2);
Core Java
a. falsetruetrue
b. falsefalsetrue
c. truetruetrue
d. falsefalsefalse

Ans.c. truetruetrue

 Q3. Which method needs to be implemented if a class is implementing comparable interface ?Core Java
a. comp
b. compare
c. compareTo
d. compareEquals

Ans.c. compareTo

 Q4. Which of the following is false ?Core Java
a. A Class cannot override both hashcode and equals method.
b. A class can override both hashcode and equals method.
c. A Class must override hashCode method if its overridding equal method.
d. A Class can override hashCode even if its not overridding equals method.

Ans.a. A Class cannot override both hashcode and equals method.

 Q5. Collections is a / an ..Core Java
a. interface
b. abstract class
c. final class
d. util class

Ans.d. util class

 Q6. 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 Method

Ans.a. Static Block
Main Method

 Q7. 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
Constructor

Ans.d. Static Block
Main Method
Instance Initialization Block
Constructor

 Q8. With the following code, Which is a valid way to initialize ?
public class BuggyBread {

   private String element1;

   private String element2;

   private BuggyBread(String element1, String element2){
      this.element1 = element1;
      this.element2 = element2;
   }

   public static class Builder {
   
      private String element1;

      private String element2;

      Builder(BuggyBread buggybread){
         element1 = buggybread.element1;
         element2 = buggybread.element2;
      }

      Builder withElement1(String element1){
         this.element1 = element1;
         return this;
      }

      Builder withElement2(String element2){
         this.element2 = element2;
         return this;
      }

      BuggyBread build(){
         BuggyBread buggybread = new BuggyBread(element1,element2);
         return buggybread;
      }
   }
}
Core Java
a. BuggyBread buggybread = new BuggyBread();
b. BuggyBread buggybread = new BuggyBread("element1","element2");
c. BuggyBread.Builder builder = new BuggyBread.Builder();
d. BuggyBread.Builder builder = new BuggyBread.Builder("element1","element2");

Ans.d. BuggyBread.Builder builder = new BuggyBread.Builder("element1","element2");

 Q9. What will be the output of following code ?

public class BuggyBread {
   
   private int x;
   private int y;
   
   BuggyBread(int x,int y){};
   
   public static void main(String[] args){
      BuggyBread buggybread = new BuggyBread();
      System.out.println(buggybread.x);
   }
}
Core Java
a. 0
b. null
c. compilation error due to uninitialized element
d. compilation error due to constructor

Ans.d. compilation error due to constructor

 Q10. What will be the output of following ?

public class BuggyBread {

   private int x;
   private Integer y;

   BuggyBread(int x,int y){};

   public static void main(String[] args){
      BuggyBread buggybread = new BuggyBread(1,2);
      System.out.println(buggybread.x);
      System.out.println(buggybread.y);
   }
}
Core Java
a. 0 0
b. 0 null
c. null 0
d. null null

Ans.b. 0 null

 Q11. 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,1

Ans.a. 1,2,3

 Q12. 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,1

Ans.b. Order cannot be determined

 Q13. Which of the following is true for == operator ?Core Java
a. For primitives, == checks if the variables on left and right have same data type
b. For primitives, == checks if the variables on left and right have same value
c. For Objects, == checks if the references on left and right have same data type
d. For Objects, == checks if the references on left and right have same value

Ans.b. For primitives, == checks if the variables on left and right have same value

 Q14. Which of the following is equivalent to following logic ?

Not X && Not Y
Core Java
a. x || Y
b. Not(X || Y)
c. Not(X && Y)
d. Not X && Y

Ans.b. Not(X || Y)

 Q15. Optional has been introduced in Java 8 to get away with which of following exception ?Core Java
a. ArithmeticException
b. ParseException
c. NullPointerException
d. FileNotFoundException

Ans.c. NullPointerException

 Q16. Which of the following is not true for abstract classes ?Core Java
a. Abstract Class is only meant to be sub classed and not supposed to be instantiated.
b. Abstract class handlers can be used to handle derived class objects.
c. We can't have an abstract class without abstract methods.
d. Abstract class has member elements.

Ans.c. We can't have an abstract class without abstract methods.

 Q17. Which of the following class creates immutable objects ?Core Java
a. String
b. StringBuffer
c. StringBuilder
d. None of these create immutable objects.

Ans.a. String

 Q18. Which of the following class is synchronized ?Core Java
a. String
b. StringBuffer
c. StringBuilder
d. None of these

Ans.b. StringBuffer

 Q19. Which of the following methods are used by Java Garbage Collection Mechanism ?Core Java
a. final
b. finally
c. finalize
d. All of the above

Ans.c. finalize

 Q20. 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 required

Ans.b. Garbage Collection guarantees that the application will not run out of memory

 Q21. What is Lazy Initialization in Hibernate ?Hibernate
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 all

Ans.c. Feature to not load dependencies and relationship in advance and load when required

 Q22. 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 Database

Ans.c. Less number of Database calls

 Q23. Which of the following is not an advantage of JSON over XML ?JSON
a. Lighter and Faster
b. Object Representation
c. Supports multiple data types
d. Backward compatible with all XML applications

Ans.d. Backward compatible with all XML applications

 Q24. Binary Search requires that the collection should beAlgorithm
a. Sorted in Ascending Order
b. Sorted in Descending Order
c. Sorted in any Order
d. Unsorted

Ans.c. Sorted in any Order

 Q25. The following code is an example of

public class Car extends Vehicle{
   int x;

   Car(int y){
      x = 5;
   }

   Car(){
      this(5);
   }
}
Core Java
a. Constructor Overloading
b. Constructor Chaining
c. Both Constructor Overloading and Chaining
d. None of above

Ans.c. Both Constructor Overloading and Chaining

 Q26. The use of volatile keyword facilitates ..Core Java
a. Making Use of Cache for better Performance
b. Avoiding use of Cache
c. Making use of Backward as well as Forward Cache
d. Keeping only one copy of variable in Cache

Ans.b. Avoiding use of Cache

 Q27. Static Polymorphic in Java is achieved through .. Core Java
a. Method Overloading
b. Method Overriding
c. Variable Overloading
d. Variable Overriding

Ans.a. Method Overloading

 Q28. Runtime Polymorphism in Java is achieved through ..Core Java
a. Method Overloading
b. Method Overriding
c. Variable Overloading
d. Variable Overriding

Ans.b. Method Overriding

 Q29. Which of the following collections stores its elements in natural sorting order ?Core Java
a. HashMap
b. LinkedHashMap
c. TreeMap
d. EnumMap

Ans.c. TreeMap

 Q30. Which of following stores its elements in natural Sorting Order ?Core Java
a. AbstractSet
b. HashSet
c. LinkedHashSet
d. TreeSet

Ans.d. TreeSet


Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: