Categories: Q & A

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.
Please leave a comment before you go. (click to exit )

Larry Battle

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

View Comments

  • Good list of questions. In my view there would be a lot more must know questions for someone with 2 year experience. ?Keep up the good work.

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

    The keyword 'final' also prevents a method from being overridden in a subclass.

    • final prevents the inheritance if you declare a class as final we can not create the sub class to its final class

    • final is compile time constant mns it can apply to method,member,and class.
      finally is a block which is always executed even there is exception occur or not.
      finalize method will be called before object get garbage colleted

    • 1.final is at three levels, at variable level, method level and class level
      a. A final variable cannot be modified
      b. A final method cannot be overridden
      c. A final class never participates in Inheritance
      2.finally {} block executes compulsorily irrespective of the execution of try block
      3.finalize() will be called or invoked jes before the object is garbage collected

      Thx....

    • final modifier :

      It is possible to apply the final modifier on class,variables,methods and inner class. But it is not possible to apply the final modifier on interface,constructors and blocks.

      whenever we apply the final on class it is not possible to creat subclass. In this senario final and abstract are illegal combination. Whenever we apply the final on variable those becomes as constants.Whenever we apply the final on methods those methods does not support the overriding. But to declare the method final and abstract are illegal
      combination.

      Hence final is used to declare the conistants and to restricts the oops concepts.

      finaly :

      finally is a block in java. It is used to release the resources like clossing the streams and clossing the jdbc connections.

      finallize:

      finallize() is a method in java.lang.Object class. It is also is used to resources. But it is called by garbage collection before remove the object form the jvm's memory. But hear we can not give the gaurenty when the garbage collection call the finallize() method.

      Hence it is recamended use the finally block insted of the finallize() method to release the resources.

      Basha Allisagari

Share
Published by
Larry Battle

Recent Posts

What really is Data Science? Told by a Data Scientist

What REALLY is Data Science? Told by a Data Scientist - By Joma Tech

7 years ago

Video: How Water Towers Work

How Water Towers Work - Practical Engineering

7 years ago

Dev Tip: Simple tips to improve code reviews

Writing perfect code is a challenging process. That's where code reviews come in to help…

7 years ago

Video: How AI will change the 3d industry

"The Next Leap: How A.I. will change the 3D industry - Andrew Price - Blender"

7 years ago

Best Software Presentation for 2018

"Captain Disillusion: World's Greatest Blenderer - Live at the Blender Conference 2018 - CaptainDisillusion"

7 years ago

Dev Video: A Few Linux Shell Tips

My 5 Favorite Linux Shell Tricks for SPEEEEEED (and efficiency) - By tutoriaLinux > What's…

7 years ago