Core Java - Interview Questions and Answers for 'Classe' | 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 Java - Interview Questions and Answers for 'Classe' - 68 question(s) found - Order By Rating

next 30
 Q1. What is the different between collection and Stream Api ?Core Java
Ans. data under collection are actually stored in memory so that they can be retrieved when needed whereas data in streams are not stored and hence we need to construct it again when needed.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collection classes  stream api  collection vs stream     Asked in 1 Companies


 Q2. difference between ArrayList and array ?Core Java
Ans. ArrayList is a variable length collection class whereas arrays are fixed length primitive structure.

We can use generics with arraylist but not with arrays.

We can store primitive data types within arrays but can't with ArrayList. In ArrayList that needs to be converted to Wrapper objects.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arraylist  arrays  collection classes  collections      basic        frequent


 Q3. Why Concurrent Collection Classes are fail-fast 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     concurrent collection classes   fail fast   fail-fast  collections  collection classes      expert


 Q4. Can we have interface as a replacement for utility class ? Core Java
Ans. Yes, With Java 8 we can use Interfaces as collection of utility methods through the use of default methods.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java 8  interfaces  utility class   utility classes


 Q5. Which are the thread safe / synchronized / concurrent classes in java collections ?Core Java
Ans. Stack
Properties
Vector
BlockingQueue
ConcurrentMap
ConcurrentNavigableMap

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections  concurrent classes


 Q6. What are the benefits of immutability or Immutable classes ?Core Java
Ans. Immutable objects are thread-safe so you will not have any synchronization issues.Immutable objects are good for Map keys and Set elements, since these typically do not change once created.Immutability makes it easier to write, use and reason about the code (class invariant is established once and then unchanged)Immutability makes it easier to parallelize your program as there are no conflicts among objects.The internal state of your program will be consistent even if you have exceptions.References to immutable objects can be cached as they are not going to change.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     immutable  immutability classes   benefits of immutable  immutability classes     Asked in 1 Companies


 Q7. Which immutable classes have you worked with ? Can you name some immutable Collections ? How to make an immutable collection ?Core Java
Ans. string and wrapper class objects

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     immutability  immutable  immutability classes   immutable  immutability collections     Asked in 3 Companies


 Q8. Is immutability an advantage with Wrapper classes over primitive types ? Core Java
Ans. There is no concept of de referencing with primitive types and hence they are implicitly immutable. Having wrapper classes as mutable offers disadvantages compared to primitive types. Wrapper classes being immutable offer similar advantage as primitive types.It actually overshadows the disadvantage wrapper class could have if they are immutable.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     immutable  immutability classes  wrapper classes


 Q9. Can we use primitive types with Collection classes ?Core Java
Ans. No, As collection classes involve use of Generics, they cannot accept primitive types.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collection classes  collections


 Q10. What are the benefits of using Wrapper classes over primitive types ?Core Java
Ans. With Collection classes , we cannot use primitive types. Moreover for any class using generic types, we cannot use primitive types.

They add more functionality by means of additional methods.

As their reference can be null , they offer consistent check for uninitialized state.

They facilitate caching and reuse by means of constant Pools.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     wrapper classes  benefits of wrapper classes over primitives


 Q11. Why can we have a static inner class but not a static Top level class 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     static class  inner classes   nested classes      Expert        rare


 Q12. What are the advantage of Abstract classes over interfaces with respect to Java 7 ? and What changed in Java 8 to help facilitate that in Java 8 ?Core Java
Ans. Abstract Classes provide default implementations of methods that are inherited by the classes that extend them, which was not the case for Interfaces. This changed in Java 8, where default implementations are provided for methods.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     abstract classes  interfaces  default method     Asked in 1 Companies      expert


 Q13. Does Wrapper classes produces immutable objects ? Core Java
Ans. Yes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     wrapper classes  immutable  immutability


 Q14. 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


 Q15. Is this code legal in java i.e nested class within interface implementing the parent interface ?

public interface MyInterface {
public class MyClass implements MyInterface {
}
}
Core Java
Ans. Yes that's legal in java

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inner classes  nested classes  sub class      Basic


 Q16. Can an inner class be subclass of it's parent class ?Core Java
Ans. Yes that can be done

public class OuterClass {
public class InnerClass extends OuterClass {
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inner classes  nested classes  sub class      Basic


 Q17. What is the difference between inner class and sub class ?Core Java
Ans. Inner Class is a class that is nested within another class whereas sub class is a class that extends or inherit another class.

Inner class can only be accessed using reference of outer class ( Class name , if inner class is static or object reference, if inner class is non static ) whereas Sub class is accessed directly.

In terms of memory, inner class is stored just like another class having it's own body whereas sub class carries the body of parent class as well as it's own fields in memory.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inner classes  nested classes  inner class vs sub class  nested class vs sub class      Basic


 Q18. How can we hide a class in Java ?Core Java
Ans. By encapsulating it within another class and declaring it private. In such a case, it will only be accessible through parent class or parent class object.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     private class   private inner class  class hiding  encapsulation  object oriented programming (oops)  oops concepts  inner classes   nested classes


 Q19. Can we declare a class private ?Core Java
Ans. We can declare an inner class as private and hence would be restricting it's access from outside. We cannot make outer class as private.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     private class   inner classes  nested classes


 Q20. What is Boxing conversion ?Core Java
Ans. Boxing conversion converts expressions of primitive type to corresponding expressions of reference type.

For example

boolean to Boolean
long to Long
double to Double

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     data type  boxing  wrapper classes


 Q21. What are Util Classes ? What are its advantages ?Core Java
Ans. Classes having only static methods in java is called util classes. As they don't have specific object state, they are basically intend to have shared code and state through static elements and methods. They save resources by sharing code.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     util classes

Try 1 Question(s) Test


 Q22. Upon compiling the following class, What .class files will get created

public class OuterClass{
class InnerClass{
}
}
Core Java
Ans. OuterClass.class AND OuterClass$InnerClass.class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     class files  compilation  compile  inner classes   nested classes


 Q23. how to access the methods of an inner class?Core Java
Ans. It depends on the type of inner class

To access non static inner class method

new OuterClass().new InnerClass().getMethod();

To access static method of static inner class

new OuterClass.InnerClass().getMethod();

  Sample Code for inner class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inner classes  nested aclasses     Asked in 1 Companies      Intermediate        frequent


 Q24. When should we use Abstract classes ?Core Java
Ans. Abstract classes provide a mechanism of interfacing ( using abstract method ) as well as inheritance ( extending abstract class ). So they should be used in place of interfaces in case there is some code ( methods ) or object body ( member elements ) that can be reused with inheritance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     abstract classes     Asked in 1 Companies


 Q25. What are Collection Classes ?Core Java
Ans. Collections in java is a framework of classes that provides an abstracted data structure to store and manipulate the group of objects. Each class is unique in the way it stores , search , sort and modify the elements.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections  collection classes     Asked in 1 Companies      Basic        frequent


 Q26. Can we have an inner class within Interface ?Core Java
Ans. Yes, we can define an inner class within interface.Inside the interface, the inner class is implicitly public static.

So the following is legit in Java

public interface BuggyBreadInterface {
   void doSomething();

   public class BuggyBreadClass implements BuggyBreadInterface{
      void doSomething(){
         System.out.println("Do something");
      }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inner classes  inner class in interface  nested classes


 Q27. How to tackle duplicate classes in maven build ?Maven
Ans. The simplest way is to ignore them if Maven enforcer plugin is complaining about it but it may lead to runtime problems later.

We can do the dependency:tree to see from where these duplicate ones are coming and hence can exclude the duplicate one.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     maven   ban duplicate classes enforcer plugin


 Q28. Have you heard of Ban Duplicate Classes Maven enforcer plugin ? What is its use ?Maven
Ans. Yes , we have been using this plugin with our projects and its purpose is to warn and stop the Build if there are duplicates of the same package and class are being carried either directly or through transitive dependencies. the duplicate could be coming through different types of dependencies or through different versions of the same dependency. Its purpose is to make sure that there is only one copy thats being used at compile time and runtime and hence shouldnt later result in runtime problems.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     maven   ban duplicate classes enforcer plugin


 Q29. Can we access private members of the parent class ? i.e Are private members of the class visible in the derived class ?Core Java
Ans. No, If both Parent and Derived are outer classes.

public class Vehicle {
private static String manufacturingDate = "2016";
}

public class Car extends Vehicle{
public static void main(String args[]){
System.out.println(manufacturingDate); // error - The field Vehicle.manufacturingDate is not visible
}
}

Yes, If derived is the inner class of Parent.

public class Vehicle {
private static String manufacturingDate = "2016";
static public class Car extends Vehicle{
public static void main(String args[]){
System.out.println(manufacturingDate); // no problem
}
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     private members   private methods   private variables   inheritance  object oriented programming (oops)  oops concepts   members visibility   inner classes  nexted classes      basic        frequent


 Q30. What is the difference between the following two code lines ?

1. new OuterClass().new InnerClass();

2. new OuterClass.InnerClass();
Core Java
Ans. In first case we are trying to initialize Inner class object using the instance of Outer Class whereas in second case we are trying to initialize the Inner class object directly using the Outer class name.

In second case , Inner class is "static inner class" as we cannot access "non static inner class" using Classname alone.

In first case, the inner class could be either "static inner class" or "non static inner class".

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inner classes  inner class   static inner class   new operator


next 30

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: