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.



Be Sociable, Share!

Larry Battle

Hello, I'm Larry Battle and I love to program, fix problems and discover new technologies. Check out my stackoverflow and github accounts. I also do book reviews on amazon.com. I'm not the best of writers but I do enjoy spreading my knowledge through my short blogs at bateru.com/news. So please leave some feedback. It would be greatly appreciated.

More Posts - Website

Follow Me:
Twitter

  • http://extreme-java.blogspot.com Sandeep

    Firefox 4.0 Windows 7

    Thanks for putting this up. There had been requests for the answers. Will link to this post from the questions post.
    Thanks once again.

    • http://extreme-java.blogspot.com Sandeep

      Firefox 4.0 Windows 7

      The only suggestion I can give is regarding “equals and == difference”. equals doesn’t assign value. It is intended to check logical equality and == checks if both references point to same object.

      • http://www.bateru.com Larry

        Opera 11.01 Windows 7

        Thank you for the correction.
        I forgot about a.equals(b).

  • http://resumeownnavigation.com tb

    Firefox 4.0 Linux

    … sweet, was going to look them up in free moment :-)

  • Tom Ellis

    Firefox 3.6WXP.NETCLR3.5.30729 Windows XP

    final – This doesn’t just declare a constant. Can also be used on a class to declare that it cannot be subclassed.

    • Ron

      Firefox 6.0a1 Windows 7

      Let’s clarify about the ‘final’ keyword.
      Instead of thinking of it as a way to declare a constant, think of it as a fixed declaration that cannot be changed.
      In the case of a class member, it makes it a constant.
      In a case of a class, one can’t make a subclass of it.
      In case of a method, it means that even if you do make a subclass, one won’t be able to override that specific method.

      There are various reasons to use the ‘final’ keyword – creating constants, security, making classes immutable.

  • Dave

    Chromium 10.0.648.204 Linux

    #10: No, only redirect does a redirect.

  • Dave

    Chromium 10.0.648.204 Linux

    #13: Both WAR and JAR files contain arbitrary files. A WAR is expected to adhere to specific layout guidelines.

    • Rick

      Chrome 10.0.648.204 Windows 7

      A war file does not necessarily contain jsp pages (think web service)!

      the equals method returns whatever is returned by the overridden equals method of the implemented class, i.e. if the equals method body checks for equivalence of important properties of the class, then it compares logical equivalence, however, the equals method can arbitrarily return true or false, depending on the implementation.

  • http://javarevisited.blogspot.com Javin @ Tibco Tutorials

    Firefox 3.6.16.NETCLR3.5.30729 Windows XP

    Hi,

    Thanks for these interview questions. I would also like to share my favorite interview questions :

    Why String is immutable in Java
    Difference between HashMap and HashTable? Can we make hashmap synchronized

    Thanks
    Javin

  • http://ionelcondor.wordpress.com ionel condor

    MSIE 8.0 Windows 7

    well,
    I would never hire anyone that after 2 years of java is only able to give such incomplete answers.
    We usually do not hire not even entry level programmers with such low level of java knowledge.
    First this is not core java, core java has nothing to do with servlets, struts (:)) btw is Struts still a cool technology…i remeber I have used it in 2001 not now :) …No need to mention incomplete answers about final for instance…or mixing some completely random SQL in the same java sheet …can’t see any reason…

    As a conclusion, these are good questions for an intern that wants to do some white box QA that might involve a 10-15% of java, at maximum.

    • http://www.bateru.com Larry

      Opera 11.01 Windows 7

      Well… could you please then reply with the acceptable solutions to the questions posted.
      Or is it just a waste of your time because it’s only 15% java?

      • http://ionelcondor.wordpress.com ionel condor

        MSIE 8.0 Windows 7

        that’s true, you only tried to respond to another post …
        again: those are ok, but for extremely newbie devs mixed with ‘deprecated’ technologies like Struts, that’s all.
        So i would first change the title :).

  • http://javarevisited.blogspot.com Javin @ Tibco Tutorials

    Firefox 3.6.16.NETCLR3.5.30729 Windows XP

    I have written a blog post about Top 20 Core Java Interview questions asked in Investment Bank
    ,you may find it interesting.

    • http://www.bateru.com Larry

      Opera 11.01 Windows 7

      Great questions.

  • http://www.javaiq.net java interview questions

    Chrome 11.0.696.68 Windows 7

    Check out JavaIQ.net – it has huge collection of java interview questions.

  • Ranjam Pathania

    Unknown Unknown

    Hi

    Plz tell me operater overloading is not used in java.

    • Bnakprwan99

      Unknown Unknown

      No, operator overloading is not used in java, we use method overloading here

      Beena kaparwan

      • sandy

        Unknown Unknown

        why not use operater overloading

      • ajaykumar

        Unknown Unknown

        operator overloading internally supported by java ….jvm internally performs that implementation……e.g +,*………bt operator overloading is nt supported for programmers just like addresses nt supported in java…….

    • Mgkartheek

      Unknown Unknown

      because c++ has proven by its record that its very difficult to maintain and ambuguity for the comiler….so operator overloading in not supported in java…

    • sandy

      Unknown Unknown

      no ,operater overloading use in java

      • Seshareddy1989

        Unknown Unknown

        there is a one mechanism in java to support overloading . + operator which provides overloading in two cases
        – we can use it for addition.
        – for concatnation the two strings.

      • ajaykumar

        Unknown Unknown

        there is also another e.g of operator overloading i.e…….* for multiplication and importing classes from package

      • Madina Basha Allisagari

        Unknown Unknown

        Hi Sandy,

        Operator overloading is avalable in java.In java + operator perform the operator
        overloading. But abort the + operator the remaining all operators does not support the operator overloading.

        Basha

    • Madiba Basha Allisagari

      Unknown Unknown

      Operator overloading mean , a operator can perform the many action.

      In java abort + operator , the remaining all oprators does not support the operator overloading. This + operator perform the addition on numerics and it perform concatination operation on strings.

      for example :

      System.out.println(2+3+4); o/p: 9
      System.out.println(2+3+”ranjam”); o/p: 5ranjam

      Basha

  • Arulkumaran

    Unknown Unknown

    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.

  • Harshit rastogi

    Unknown Unknown

    other useful link i found for interview questions Java interview questions

  • http://pulse.yahoo.com/_6RRBJRRZARTKQLNFDIQTTNF4X4 Somesh

    Unknown Unknown

    Nice Collections of java Interview question. It really helpful for beginner as well as developer.
    Check following link too, It is also having a nice collection on java interview question…

    http://mindstick.com/Interviewer/QuestionPage.aspx?topicid=10&topic=Java

    Thanks Everyone!!

  • http://javarevisited.blogspot.com/2010/10/difference-between-hashmap-and.html hashmap vs hashtable

    Unknown Unknown

    Surprise to see there is no questions on Recursion or datastrucutre. Recursion should always be included in interview, this is the one concept which is always tricky for most candidates. here are some good Java interview questions for senior level

    • Sgh Dvg12

      Unknown Unknown

      Hashtable is synchronized but Hashmap is not synchronized

  • Biswaranjan111

    Unknown Unknown

    good one

  • Bmdan_ro

    Unknown Unknown

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

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

    • Rakesh

      Unknown Unknown

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

    • Mohit Mahajan27

      Unknown Unknown

      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

    • Vinny

      Unknown Unknown

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

    • Madina Basha Allisagari

      Unknown Unknown

      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

  • Sravan

    Unknown Unknown

    good job

  • raghu

    Unknown Unknown

    Thanks a lot !!!!!

  • http://www.fromdev.com/ Java Developer

    Unknown Unknown

    Thanks for sharing

  • Fakhruddin Khan

    Unknown Unknown

    amazing questions, It works well

  • dharmendra patel
  • http://tutiez.com/how-to-serialize-the-object-in-java.html pranav

    Unknown Unknown

    very nicely compiled version of interview questions.

  • ji

    Unknown Unknown

    answer to the 3rd question is wrong

  • ji

    Unknown Unknown

    == value
    .equals , memory location

    • larrybattle

      Unknown Unknown

      Thanks for the correction. You’re right it’s wrong. I’ll change it.

  • Amit_yadav0010

    Unknown Unknown

    thanks for share

  • Rajnikant_laad

    Unknown Unknown

    Hi,
    could please tell me about virtual table in java ? and live example of seralization..

  • Shashiranjan

    Unknown Unknown

    thanks for sharing . i think u missed a few important question

    what is a green thread in java.

    difference b/w clonable interface and remote interface

    what is a marker interface in java.

    • Madina Basha Allisagari

      Unknown Unknown

      Hi Shashiranjan,

      1) green thread in java:

      There are two types of thereads are available . They are native threads and green threads.
      This native threads used by the os to perform the multi-threading and also these threads are managed by the kernal. The os use the pthread library to generate the native threads.

      The green threads are created by the programmer to execute our code in java. Sun microsystem proves only creation of green threads in java.

      It is not possiblt to swithch the native threads. But it is possiblt ot switch the green threads by using yield(),wait() and etc..

      2) Clonable interface:
      This Clonable marked interface is used to creating the exact copy of exiting object.

      Remote interface:

      Remote interface is used to creating the remote object that is shared by the mulitplt vertiul michines through RMI.

      3) marker interface in java:

      Which interface does not contain any methods those interfaces is called as marker interface or tagged interface. Thse interfaces are used to provide the some instruction to jvm.
      For example take the Serializable interface. Whenever any object provide the implementation to this interface the jvm allows the serialization on that object.

  • http://www.facebook.com/profile.php?id=100002096063805 Fila Blue

    Unknown Unknown

    here’s some more:

    +1
    0
    vote
    Answer #1

    Hey!
    I’ll try to give you some examples, differentiated by the level of the candidate applying:

    **UPDATE**: If you are a junior java developer or an aspiring one, I strongly recommend you to take first the OCJP certification before going to an interview. This can increase your chances to succes big time, as well as your entry salary – proven and tested by myself! :)

    1) Junior java developer
    a) Basic ocjp (former scjp) questions:
    – What does static, final mean, purposes;
    – How many accesibility modifiers exist? Please describe them.
    – Why do you need a main method?
    – How many constructors can you have?
    – Define overwriting and overloading
    – Give java API implementations for overwriting and overloading
    – Describe the String class – unique properties
    – StringBuilder vs StringBuffer
    – Collections : please describe, give some examples and compare them to eachother
    – ArrayList vs Vector
    – HashMap vs HashTable
    – What’s a tree
    – What’s a map
    – Multithreading: describe the management in java
    – What’s a semaphone?
    – How many states are there for threads?
    – Describe the usage for synchronized word (2)
    – Serialization in java – a descrition and usage
    – Garbage collection in java – description and usage
    – Can you guarantee the garbage collection process?
    b) Simple design pattern questions:
    – Singleton please describe main features and coding
    – Factory please describe main features and coding
    – Have you used others? please describe them

    2) Intermediate and Senior level – depending on rate of good responses, additional questions to 1):
    http://centraladvisor.com/programming-2/java/java-developer-interview

  • http://java67.blogspot.in/ java67

    Unknown Unknown

    That’s correct. Another similar question from my list of tricky Java questions is putting return statement in finally block which overrides return on try block.

  • Madina Basha Allisagari

    Unknown Unknown

    Hi Shashiranjan,

    1) green thread in java:

    There are two types of thereads are available . They are native threads and green threads.
    This native threads used by the os to perform the multi-threading and also these threads are managed by the kernal. The os use the pthread library to generate the native threads.

    The green threads are created by the programmer to execute our code in java. Sun microsystem proves only creation of green threads in java.

    It is not possiblt to swithch the native threads. But it is possiblt ot switch the green threads by using yield(),wait() and etc..

    3) marker interface in java:

    Which interface does not contain any methods those interfaces is called as marker interface or tagged interface. Thse interfaces are used to provide the some instruction to jvm.
    For example take the Serializable interface. Whenever any object provide the implementation to this interface the jvm allows the serialization on that object.

  • Shrikant R Kale

    Unknown Unknown

    Problem : How Will you access the method of the sub class without creating the objcect of the SuperClass and the chances should be made into line between //….// area only… i.e. in single line. ( obj.add(); )

    public class SuperClass {
    public void add() {
    System.out.print(“add() method from the Super Class”);
    }
    }

    class SubClass extends SuperClass {
    public void add() {
    System.out.println(“add() method from the SubClass.”);
    }

    public static void main(String args[]) {
    SubClass obj=new SubClass();

    //………………………………………………………………..//

    obj.add(); // add() method from SubClass.

    //………………………………………………………………..//
    }
    }

  • Mohan Kommi

    Unknown Unknown

    Thanks for sharing..
    This helps me a lot for time spent

  • Aveyond

    Unknown Unknown

    Hi programmers

    I found a good way to make money

    a good place to exposure yourself as a freelancer to employers

    any skill’s in programming or designing or any other skills are Good to make money

    this is my weblog: http://howcanifindwork.wordpress.com/

    I wrote something about that in there. something to share experiences in this work with others.

  • jfajunior

    Unknown Unknown

    What is the difference between checked and unchecked exceptions?

    Checked exceptions must be treated, while unchecked exceptions doesn’t.

  • http://Javastuff.in/ Javastuff
  • karthik

    Unknown Unknown

    hi all,

    i very thanks to admin, and i feel it needs to add some more questions for our aspirants .

    thank you

  • Karmjeet Singh

    Unknown Unknown

    I know it’s not possible to cover all questions in 15 interview question , But the content you given here nice, and showed very good presentation .

    thank u Larry

  • mahesh

    Unknown Unknown

    good questions

  • Bala

    Unknown Unknown

    Yes ofcourse the question are useful for java..

    http://www.javatraininginchennai.in

  • Madhava Verma Dantuluri

    Unknown Unknown

    Good coverage.

  • NervousFirstTimeInterviewee
  • http://www.besanttechnologies.com karthick

    Unknown Unknown

    thanks a lots……

    Java Training in Chennai

  • http://www.besanttechnologies.com karthick

    Unknown Unknown

    thank u a lots…

    Java Training in Chennai

  • http://www.besanttechnologies.com karthick

    Unknown Unknown

    thank u very much….

    Web Designing Training in Chennai

  • Anil Nivargi

    Unknown Unknown

    Thanks..very nice..for more string related interview questions please go through this blog AdnJavainterview Blog.