Answers to “15 Must Know Java Interview Questions After 2 Years of Experience”

This post is in response to 15 Must Know Java Interview Questions After 2 Years of Experience.
Note: Only short responses are provided for the questions.
If you feel that more depth or a correction is needed then visit the links or leave a comment below.

Core Java Questions with answers:

  1. What is the purpose of serialization?
    Answer: Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent storage or streamed across a communication link. The byte stream can then be deserialised – converted into a replica of the original object.
    Source | Example
  2. What is the difference between JDK and JRE?
    Answer: Java Development Kit (JDK) is the most widely used Java Software Development Kit. Java Runtime Environment (JRE) is an implementation of the Java Virtual Machine which executes Java programs.
    Source | JDK Wiki | JVM Wiki
  3. What is the difference between equals() and “==” ?
    Answer: Equals is intended to check logical equality and == checks if both references point to same object. (Thanks Sandeep)

    a == b;        // Compares references, not values.
    a.equals(b);  // Compares values for equality.

    Source

  4. When will you use Comparator and Comparable interfaces?
    Answer: java.util.Comparator and java.lang.Comparable
    java.util.Comparator compares some other class’s instances, while java.lang.Comparable compares itself with another object.
    Source | Example
  5. What is the wait/notify mechanism?
    Answer: This deals with concurrent programming. The wait() and notify() methods are designed to provide a mechanism to allow a thread to be block until a specific condition is met.
    However, java.util.concurrent should be used instead of wait() and notify() to reduce complexity.
    Source | Java API | Java Technical Article
  6. What is the difference between checked and unchecked exceptions?
    Answer:
    In general, unchecked exceptions represent defects in the program (bugs), which are normally Runtime exceptions.
    Furthermore, checked exceptions represent invalid conditions in areas outside the immediate control of the program.
    Source
  7. What is the difference between final, finally and finalize?
    Answer: “final” is the keyword to declare a constant AND prevents a class from producing subclasses. (Thanks Tom Ellis)
    “finally” is a block of code that always executes when the try block is finished, unless System.exit() was called. finalize() is an method that is invoked before an object is discarded by the garbage collector.
    Source | Final Usage |Finally Usage | Finalize()
  8. What is the difference between web server and app server?
    Answer: A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols.
    Source
  9. Explain the Struts1/Struts2/MVC application architecture?
    Answer: Struts was adopted by the Java developer community as a default web framework for developing web applications
    The MVC(Model–view–controller) an application that consist of three distinct parts. The problem domain is represented by the Model. The output to the user is represented by the View. And, the input from the user is represented by Controller.
    Source
  10. What is the difference between forward and sendredirect?
    Answer: Both method calls redirect you to new resource/page/servlet. The difference between the two is that sendRedirect always sends a header back to the client/browser, containing the data in which you wanted to be redirected.
    Source
  11. How does a 3 tier application differ from a 2 tier one?
    Answer: Tiers are the physical units of separation or deployment, while layers are the logical units of separation.
    Imagine that you’re designing an e-commerce website. A 3 tier architecture would consist of web pages, a web server and a database, with the corresponding 3 layers being the “Presentation”, “Business Logic” and “Database” layers.
    If you take the database tier and layer out then your have a 2 tier architecture.
    Source
  12. How does the version control process works?
    Answer: Initiate, pull, branch, merge, commit, push.
    (Init) Make your own repository. (Pull) Download an existing repository from a url. (Branch / Merge )Make revisions. Commit then push your modifications.




    Git Cheat Sheet

  13. What is the difference between JAR and WAR files?
    Answer: JAR files (Java ARchive) allows aggregating many files into one, it is usually used to hold Java classes in a library.
    WAR files (Web Application aRchive) stores XML, java classes, and JavaServer pages for Web Application purposes.
    Source
  14. What is a Left outer join?
    Answer: This deals with SQL. Left outer join preserves the unmatched rows from the first (left) table, joining them with a NULL row in the shape of the second (right) table.
    Source | Joins Wiki
  15. What is the difference between UNION and UNION ALL?
    Answer: This deals with SQL. UNION only selects distinct values, UNION ALL selects all values.
    Source | Example

Check out Effective Java (2nd Edition) to fresh up your Java skills.



Larry Battle

I love to program, and discover new tech. Check out my stackoverflow and github accounts.

More Posts - Website

Follow Me:
Twitter

  • Roshini

    Unknown Unknown

    Thanks for sharing, i did web design course in Chennai, now i preferred to learn java, angular training in Chennai, this post is really useful to me.

  • jackson

    Unknown Unknown

    Java is one of the popular technologies with improved job opportunity for hopeful professionals. Java Training in Chennai helps you to study this technology in details.If you are looking for best Java Training Institutes in Chennai reach Fita academy.

  • Unknown Unknown

    very interesting article on on software development
    http://www.fita.in/web-design-training-in-chennai/

  • Unknown Unknown

    Very Nice questions … visit more Java interview question

  • lisa anjela

    Unknown Unknown

    Thanks for posting this. I’ve been looking for an easy way to get Core Java online training

  • Vandana P

    Unknown Unknown

    Hi,

    Can you plz explain me the output for the below statement if we call this through a method?

    return (true ? null : 0);

    • Pawan Vyas

      Unknown Unknown

      Assume the following method:
      public static Integer returnInt(){
      return(true ? null : 0);
      }
      public static void main(String[] args){
      Integer i = returnInt();
      System.out.println(“Integer value: ” + i);
      }
      Here, the ” (true ? null : 0) ” is a form of ternary operator. What that means is, the condition before the ” ? ” is evaluated, if the condition is TRUE, then the expression before the ” : ” is returned/evaluated, else the expression after the ” : ” is returned/evaluated. This is the general syntax for ternary operator:
      ? :
      //Meaning — LeftExpr – evaluated if condition true, else RightExpr evaluated.

      Now coming back to our our case, it’s pretty obvious the condition being specified is always TRUE. So the left expression is evaluated, since we are calling the ternary operation in the return statement, the left expression/value will be returned.
      Therefore the “Integer i” we are assigning the value to(using this method) will always be “null”.
      Ternary operator is the shortcut of simple if…else statements. The same return statement can be written as:
      ….
      if(true){
      return null;
      } else{
      return 0;
      }
      ….
      You can even chain/nest ternary operators together.

  • Professor Fontanez

    Unknown Unknown

    2. What is the difference between JDK and JRE?

    The JDK is a software package that allows developers to COMPILE and RUN Java programs; whereas the JDK is only used to RUN Java programs. Every JDK contains a compatible JRE, although the JRE can be downloaded separately.

    (your answer gets more into WHAT they are and not how they are functionally different).

    3. What is the difference between equals() and “==” ?

    “==” is used to evaluate primitive values for equality and objects for referential equality. To evaluate object values, the respective classes must implement the equals() method to define object value equality.

    For question #5, you may want to add that wait() and notify() are methods of the Object class.

    7. What is the difference between final, finally and finalize?

    “final” is not simply the keyword used to declare a constant AND to prevent a class from producing subclasses. When used in a method declaration, it means that the method cannot be overridden.

    12. How does the version control process works?
    Not only the answer you provide is really vague, it might be specific to a particular implementation of a CM tool. For example, for version control, there might be some differences (for example) between SVN and Serena Dimensions. Maybe you should change your question to ask about the Configuration Management process in general, or ask about the version control process for the particular CM tool (i.e. SVN).