Interview questions :: JAVA

By | 2014/10/02

Hi,
long time no see 😉
This time something different.. couple of questions I’ve heard of related to Java.. you can run into those during job interview – feel warned..

  • What is singleton?

    It is design pattern: to allow only one instance of class in application.

  • How singletons are usually implemented?

    Private constructor, private class member with instance of the class, getInstance() method returning the member holding class instance

  • What is static class?

    If you make all the members and functions of a Java class static then it is in effect a static class but there’s no way of making a top-level class static

  • What is difference between static class and singleton?
    1. static class is created when class is loaded by Class Loader, singleton is created when first invocation of “getInstance” method is done
    2. singletons can implement interfaces (or derive from useful base classes), so you can pass around the singleton as if it were “just another” implementation

Maybe you could send me some other questions?

Leave a Reply

Your email address will not be published. Required fields are marked *