Git Product home page Git Product logo

java-interview-question's Introduction

Java Interview Questions

Today, there are about 10,000,000 Java developers around the world, Not necessarily this number but if we keep together all kinds of Java developers (senior, junior, students, back-end developers, mobile developers etc) and let's say in one word: ALL KINDS OF JAVA DEVELOPERS, then we can trust to those statistics. Beside of this huge number of Java users, there are a lot of resources for learning Java language such as books, official documents, websites, youtube videos, code examples on SCM remotes, online & offline courses etc. The main goal of making this public repository on Github is to provide a resource to answer frequently asking questions around Java technology and frameworks based on it.
This repo would be helpful for those Java developers who:

1- Have a little knowledge about Java technology and want to improve their knowledge
2- Want to know more about some specific contexts
3- Going to be employed by an organization and need to have an overview on core theory concepts (Interview Questions)
4- Are kind of experienced and want to know more theory concepts

Every suggestions, comments & contributions are greatly appreciated. Please rate us if this repo helps you anyway.
contact us:

Java

Java is the high-level, object-oriented, robust, secure programming language, platform-independent, high performance, Multithreaded, and portable programming language. It was developed by James Gosling in June 1991. It can also be known as the platform as it provides its own JRE and API.more


Spring

The Spring Framework is an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE (Enterprise Edition) platform. Although the framework does not impose any specific programming model, it has become popular in the Java community as an addition to the Enterprise JavaBeans (EJB) model. The Spring Framework is open source.more


Java question


Spring question

Core Java Interview Quetions

1) What are static blocks and static initializers in Java?

the static initialization blocks can only initialize the static instance variables. These blocks are only executed once when the class is loaded.and we know Instance variables are initialized using initialization block.

public class Test {
   static int number = 0 ;
   static {
      System.out.println("Running static initialization block.");
      number = 5;
   }
   public static void main(String[] args) {
      Test obj1 = new Test();
      System.out.println(Test.number);
   }
}

Output of this code :

5

2) How to call one constructor from the other constructor ?

When we have several constructor :
Calling a constructor from the another constructor of same class is known as Constructor chaining.
The real purpose of Constructor Chaining is that you can pass parameters through a bunch of different constructors, but only have the initialization done in a single place.This allows you to maintain your initializations from a single location, while providing multiple constructors to the user
With a simple example we can better see its meaning.

public class MyClass {
    public MyClass() {
         System.out.println("Default Constructor");
    }

    public MyClass(String str) {
         this();
         System.out.println("Constructor with single parameter");
    }

    public MyClass(String str, int num) {
         this("test");
         System.out.println("Constructor with double parameter");
    }

    public MyClass(int num1 , int num2, int num3) {
         this("test",2);
         System.out.println("Constructor with three parameter");
   }
}
     public static void main(String[] args) {
          MyClass chain = new MyClass();
          System.out.println("-------------------------");
          MyClass chain = new MyClass(2,1,3);
          
          
     }

Output of this code :

Default Constructor
-------------------------
Default Constructor
Constructor with single parameter
Constructor with double parameter
Constructor with three parameter



3) What is method overriding in java ?

If subclass (child) has the same method as declared in the parent class, it is known as method overriding in Java.
in other words, if subclass provides a specific implementation of the method that has been declared by one it's parentclass, it's known as method overriding.
Method overriding is used to provide the specific implementation of a method which is already provided by its superclass.
Method overriding is used for runtime polymorphism.

Rols for java method overriding:
  • The method must have the same name as in the parent class.
  • The method must have the same parameter as in the parent class.
  • There must be an IS-A relationship (inheritance).
public class Parent{
    public String info(){
         return "this is Parent";
    }
}
public class Child extends Parent{
    @Override
    public String info(){
         return "this is Child";
    }
}

Consider a scenario where Bank is a class that provides functionality to get the rate of interest. However, the rate of interest varies according to banks. For example, SBI, ICICI and AXIS banks could provide 8%, 7%, and 9% rate of interest.

for more information, vist here


4) What is super keyword in java ?

The super keyword refres to superclass (parent) object.
It is majorly used in the following contexts :

  • to Access the variable from (parent) object
  • Call superclass method
  • to Access the superclass constructor.

For example :

public class Parent{
    String name;
    Integer id;

    public Parent(String name, Integer id){
        this.name = name;
        this.id = id;
    }

    public String message(){
        return "this is the parent class";
    }
}

public class Child extend Parent{
    Integer weight;

    public Child(Integer weight , String name , Integer id ){
        /*[to access the super class constructor] invoke or call parent class constructor */
        super(name , id);  //this line should be first line of child constructor
        this.weight = weight;
    }

    public String getParentName(){
        /*[variable] return name of (parent) object */
        return super.name;
    }

    public String message(){
        return "this is the child class";
    }

    public void printMessage(){
        /* this is a message from child*/
        System.out.println(this.message);

        /*[calling method from parent] this is a message from parent*/
        System.out.println(super.message);
    }

}

click here for more information about super keyword


  1. Difference between method overloading and method overriding in java ?
  2. Difference between abstract class and interface ?
  3. Why java is platform independent?
  4. What is method overloading in java ?
  5. What is difference between c++ and Java ?
  6. What is JIT compiler ?
  7. What is bytecode in java ?
  8. Difference between this() and super() in java ?
  9. What is a class ?
  10. What is an object ?
  11. What is method in java ?
  12. What is encapsulation ?
  13. Why main() method is public, static and void in java ?
  14. Explain about main() method in java ?
  15. What is constructor in java ?
  16. What is difference between length and length() method in java ?
  17. What is ASCII Code?
  18. What is Unicode ?
  19. Difference between Character Constant and String Constant in java ?
  20. What are constants and how to create constants in java?
  21. Difference between ‘>>’ and ‘>>>’ operators in java?

Core java Interview questions on Coding Standards

  1. Explain Java Coding Standards for classes or Java coding conventions for classes?
  2. Explain Java Coding standards for interfaces?
  3. Explain Java Coding standards for Methods?
  4. Explain Java Coding Standards for variables ?
  5. Explain Java Coding Standards for Constants?
  6. Difference between overriding and overloading in java?
  7. What is ‘IS-A ‘ relationship in java?
  8. What is ‘HAS A’’ relationship in java?
  9. Difference between ‘IS-A’ and ‘HAS-A’ relationship in java?
  10. Explain about instanceof operator in java?
  11. What does null mean in java?
  12. Can we have multiple classes in single file ?
  13. What all access modifiers are allowed for top class ?
  14. What are packages in java?
  15. Can we have more than one package statement in source file ?
  16. Can we define package statement after import statement in java?
  17. What are identifiers in java?
  18. What are access modifiers in java?
  19. What is the difference between access specifiers and access modifiers in java?
  20. What access modifiers can be used for class ?
  21. Explain what access modifiers can be used for methods?
  22. Explain what access modifiers can be used for variables?
  23. What is final access modifier in java?
  24. Explain about abstract classes in java?
  25. Can we create constructor in abstract class ?
  26. What are abstract methods in java?

Java Exception Handling Interview questions

  1. What is an exception in java?
  2. State some situations where exceptions may arise in java?
  3. What is Exception handling in java?
  4. What is an eror in Java?
  5. What are advantages of Exception handling in java?
  6. In how many ways we can do exception handling in java?
  7. List out five keywords related to Exception handling ?
  8. Explain try and catch keywords in java?
  9. Can we have try block without catch block?
  10. Can we have multiple catch block for a try block?
  11. Explain importance of finally block in java?
  12. Can we have any code between try and catch blocks?
  13. Can we have any code between try and finally blocks?
  14. Can we catch more than one exception in single catch block?
  15. What are checked Exceptions?
  16. What are unchecked exceptions in java?
  17. Explain differences between checked and Unchecked exceptions in java?
  18. What is default Exception handling in java?
  19. Explain throw keyword in java?
  20. Can we write any code after throw statement?
  21. Explain importance of throws keyword in java?
  22. Explain the importance of finally over return statement?
  23. Explain a situation where finally block will not be executed?
  24. Can we use catch statement for checked exceptions?
  25. What are user defined exceptions?
  26. Can we rethrow the same exception from catch handler?
  27. Can we nested try statements in java?
  28. Explain the importance of throwable class and its methods?
  29. Explain when ClassNotFoundException will be raised ?
  30. Explain when NoClassDefFoundError will be aised ?

Java Interview questions on threads

  1. What is process ?

  2. What is thread in java?

  3. Difference between process and thread?

  4. What is multitasking ?

  5. What are different types of multitasking?

  6. What are the benefits of multithreaded programming?

  7. Explain thread in java?

  8. List Java API that supports threads?

  9. Explain about main thread in java?

  10. In how many ways we can create threads in java?

  11. Explain creating threads by implementing Runnable class?

  12. Explain creating threads by extending Thread class ?

  13. Which is the best approach for creating thread ?

  14. Explain the importance of thread scheduler in java?

  15. Explain the life cycle of thread?

  16. Can we restart a dead thread in java?

  17. Can one thread block the other thread?

  18. Can we restart a thread already started in java?

  19. What happens if we don’t override run method ?

  20. Can we overload run() method in java?

  21. What is a lock or purpose of locks in java?

  22. In how many ways we can do synchronization in java?

  23. What are synchronized methods ?

  24. When do we use synchronized methods in java?

  25. When a thread is executing synchronized methods , then is it possible to execute other synchronized methods simultaneously by other threads?

  26. When a thread is executing a synchronized method , then is it possible for the same thread to access other synchronized methods of an object ?

  27. What are synchronized blocks in java?

  28. When do we use synchronized blocks and advantages of using synchronized blocks?

  29. What is class level lock ?

  30. Can we synchronize static methods in java?

  31. Can we use synchronized block for primitives?

  32. What are thread priorities and importance of thread priorities in java?

  33. Explain different types of thread priorities ?

  34. How to change the priority of thread or how to set priority of thread?

  35. If two threads have same priority which thread will be executed first ?

  36. What all methods are used to prevent thread execution ?

  37. Explain yield() method in thread class ?

  38. Is it possible for yielded thread to get chance for its execution again ?

  39. Explain the importance of join() method in thread class?

  40. Explain purpose of sleep() method in java?

  41. Assume a thread has lock on it, calling sleep() method on that thread will release the lock?

  42. Can sleep() method causes another thread to sleep?

  43. Explain about interrupt() method of thread class ?

  44. Explain about interthread communication and how it takes place in java?

  45. Explain wait(), notify() and notifyAll() methods of object class ?

  46. Explain why wait() , notify() and notifyAll() methods are in Object class rather than in thread class?

  47. Explain IllegalMonitorStateException and when it will be thrown?

  48. when wait(), notify(), notifyAll() methods are called does it releases the lock or holds the acquired lock?

  49. Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyAll() methods are executed?

  50. What are thread groups?

  51. What are thread local variables ?

  52. What are daemon threads in java?

  53. How to make a non daemon thread as daemon?

  54. Can we make main() thread as daemon?

Interview questions on Nested classses and inner classes

  1. What are nested classes in java?

  2. What are inner classes or non static nested classes in java?

  3. Why to use nested classes in java? or What is the purpose of nested class in java?

  4. Explain about static nested classes in java?

  5. How to instantiate static nested classes in java?

  6. Explain about method local inner classes or local inner classes in java?

  7. Explain about features of local inner class?

  8. Explain about anonymous inner classes in java?

  9. Explain restrictions for using anonymous inner classes?

  10. Is this valid in java ? can we instantiate interface in java?

  11. Explain about member inner classes?

  12. How to instantiate member inner class?

  13. How to do encapsulation in Java?

  14. What are reference variables in java?

  15. Will the compiler creates a default constructor if I have a parameterized constructor in the class?

  16. Can we have a method name same as class name in java?

  17. Can we override constructors in java?

  18. Can Static methods access instance variables in java?

  19. How do we access static members in java?

  20. Can we override static methods in java?

  21. Difference between object and reference?

  22. Objects or references which of them gets garbage collected?

  23. How many times finalize method will be invoked ? who invokes finalize() method in java?

  24. Can we able to pass objects as an arguments in java?

  25. Explain wrapper classes in java?

  26. Explain different types of wrapper classes in java?

  27. Explain about transient variables in java?

  28. Can we serialize static variables in java?

  29. What is type conversion in java?

  30. Explain about Automatic type conversion in java?

  31. Explain about narrowing conversion in java?

  32. Explain the importance of import keyword in java?

  33. Explain naming conventions for packages ?

  34. What is classpath ?

  35. What is jar ?

  36. What is the scope or life time of instance variables ?

  37. Explain the scope or life time of class variables or static variables?

  38. Explain scope or life time of local variables in java?

  39. Explain about static imports in java?

  40. Can we define static methods inside interface?

  41. Define interface in java?

  42. What is the purpose of interface?

  43. Explain features of interfaces in java?

  44. Explain enumeration in java?

  45. Explain restrictions on using enum?

  46. Explain about field hiding in java?

  47. Explain about Varargs in java?

  48. Explain where variables are created in memory?

  49. Can we use Switch statement with Strings?

  50. In java how do we copy objects?

Oops concepts interview questions

  1. Explain about procedural programming language or structured programming language and its features?

  2. Explain about object oriented programming and its features?

  3. List out benefits of object oriented programming language?

  4. Differences between traditional programming language and object oriented programming ? ain HashSet and its features ?

  5. Explain Tree Set and its features?

  6. When do we use HashSet over TreeSet?

  7. What is Linked HashSet and its features?

  8. Explain about Map interface in java?

  9. What is linked hashmap and its features?

  10. What is SortedMap interface?

  11. What is Hashtable and explain features of Hashtable?

  12. Difference between HashMap and Hashtable?

  13. Difference between arraylist and linkedlist?

  14. Difference between Comparator and Comparable in java?

  15. What is concurrent hashmap and its features?

  16. Difference between Concurrent HashMap and Hashtable and collectionssynchronizedHashMap?

  17. Explain copyOnWriteArrayList and when do we use copyOnWriteArrayList?

  18. Explain about fail fast iterators in java?

  19. Explain about fail safe iterators in java?

Core java Serialization interview questions

  1. What is serialization in java?

  2. What is the main purpose of serialization in java?

  3. What are alternatives to java serialization?

  4. Explain about serializable interface in java?

  5. How to make object serializable in java? 4

  6. What is serial version UID and its importance in java ?

  7. What is serial version UID and its importance in java?

  8. What happens if we don’t define serial version UID ?

  9. Can we serialize static variables in java?

  10. When we serialize an object does the serialization mechanism saves its references too?

  11. If we don’t want some of the fields not to serialize How to do that?

  12. Explain oops concepts in detail?

  13. Explain what is encapsulation?

  14. What is inheritance ?

  15. Explain importance of inheritance in java?

  16. What is polymorphism in java?

Collection Framework interview questions

  1. What is collections framework ?

  2. What is collection ?

  3. Difference between collection, Collection and Collections in java?

  4. Explain about Collection interface in java ?

  5. List the interfaces which extends collection interface ?

  6. Explain List interface ?

  7. Explain methods specific to List interface ?

  8. List implementations of List Interface ?

  9. Explain about ArrayList ?

  10. Difference between Array and ArrayList ?

  11. What is vector?

  12. Difference between arraylist and vector ?

  13. Define Linked List and its features with signature ?

  14. Define Iterator and methods in Iterator?

  15. In which order the Iterator iterates over collection?

  16. Explain ListIterator and methods in ListIterator?

  17. Explain about Sets ?

  18. Implementations of Set interface ?

  19. Expl

Spring overview

  1. What is Spring?
  2. What are benefits of Spring Framework?
  3. Which are the Spring framework modules?
  4. Explain the Core Container (Application context) module
  5. BeanFactory BeanFactory implementation example
  6. XMLBeanFactory
  7. Explain the AOP module
  8. Explain the JDBC abstraction and DAO module
  9. Explain the object/relational mapping integration module
  10. Explain the web module
  11. Explain the Spring MVC module
  12. Spring configuration file
  13. What is Spring IoC container?
  14. What are the benefits of IOC?
  15. What are the common implementations of the ApplicationContext?
  16. What is the difference between Bean Factory and ApplicationContext?
  17. What does a Spring application look like?

Dependency Injection

  1. What is Dependency Injection in Spring?

  2. What are the different types of IoC (dependency injection)?

  3. Which DI would you suggest Constructor-based or setter-based DI?

Spring Beans

  1. What are Spring beans?
  2. What does a Spring Bean definition contain?
  3. How do you provide configuration metadata to the Spring Container?
  4. How do you define the scope of a bean?
  5. Explain the bean scopes supported by Spring
  6. Are Singleton beans thread safe in Spring Framework?
  7. Explain Bean lifecycle in Spring framework
  8. What is bean wiring?
  9. What is bean auto wiring?
  10. Explain different modes of auto wiring?
  11. Are there limitations with autowiring?
  12. Can you inject null and empty string values in Spring?

Spring Annotations

  1. What is Spring Java-Based Configuration? Give some annotation example
  2. What is Annotation-based container configuration?
  3. How do you turn on annotation wiring? @Required annotation
  4. @Autowired annotation
  5. @Qualifier annotation

Spring Data Access

  1. How can JDBC be used more efficiently in the Spring framework?

  2. JdbcTemplate

  3. Spring DAO support

  4. What are the ways to access Hibernate by using Spring?

  5. ORMs Spring support

  6. How can we integrate Spring and Hibernate using HibernateDaoSupport?

  7. Types of the transaction management Spring support

  8. What are the benefits of the Spring Frameworks transaction management?

  9. Which Transaction management type is more preferable?

Spring Aspect Oriented Programming

  1. Explain AOP
  2. Aspect
  3. What is the difference between concern and cross-cutting concern in Spring AOP
  4. Join point
  5. Advice
  6. Pointcut
  7. What is Introduction?
  8. What is Target object?
  9. What is a Proxy?
  10. What are the different types of AutoProxying?
  11. What is Weaving? What are the different points where weaving can be applied?
  12. Explain XML Schema-based aspect implementation?
  13. Explain annotation-based (@AspectJ based) aspect implementation

Spring Model View Controller

  1. What is Spring MVC framework?
  2. DispatcherServlet
  3. WebApplicationContext
  4. What is Controller in Spring MVC framework?
  5. @Controller annotation
  6. @RequestMapping annotation

java-interview-question's People

Contributors

4mocpmo avatar amirhossein1999git avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.