Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Questions every good Java/Java EE Developer should be able to answer? [closed]

What is the relationship between hashCode() and equals()? What is the significance of these methods? What are the requirements for implementing them?


What is the difference between Set, Map and List?

I'm still amazed how many people don't know this one in a telephone interview.


Can an interface extend multiple interfaces?

Most people answer "no", because they know java doesn't have multiple inheritance. But an interface can still extend multiple interfaces (but a class can't extend multiple classes). This doesn't lead to the diamond problem.

If the answer is "no", the interviewer should ask "why would it be forbidden?". Then you start thinking about it and you should realize that there is not problem with it.

So you learned something (by yourself) in the interview and you showed the interviewer that you are able to reason about classes, objects, inheritance, polymorphism, etc. It's actually much better than a candidate who knows the answer by heart but doesn't understand why


Usage of final keyword in method calls. For example why does the method test in below code does not give any compile error despite using final qualifier for the method parameter.

class Name {
    private String name;

    public Name (String s) {
        this.name = s;
    }

    public void setName(String s) {
        this.name = s;
    }
}

private void test (final Name n) {
    n.setName("test");
}


One sure is comparison of string. Difference between

String helloWorld = "Hello World";
helloWorld == "Hello World";
"Hello World".equals(helloWorld);


Trick question: What kinds of parameters are passed by reference in Java?

It's amazing how many people still parrot the "primitives are passed by value, objects are passed by reference" mantra.


You said "Good","Developer". Here are my 2 cents too.. :)

  • What does a "checked exception" mean?
  • Which one is better to use and when: Assertions or Exceptions to handle unexpected conditions?
  • Why String class is final? (or is it not? ;) )
  • are the wait, notify and notifyAll methods in Object class?
  • Why isn't Thread class final? Why would I extend Thread, ever?
  • Why there are two Date classes; one in java.util package and another in java.sql?
  • What happens if an exception is thrown in finally block? Is the remaining finally executed or not?
  • There is a garbage collector alright, but then is memory leak totally absent in a Java applications? If not, how so?

For J2EE:

  • Is it good to have instance/static variables in a servlet? Why not? Then where do you store "state"?
  • continuing on above question: what & where is a "state" for a (web) application?
  • What happens if I started creating/closing DB connections in "JSP"?
  • What are the ways to handle JSP exceptions? try-catch? Hmmm.. is there anything else?

I can think many, many, many more of 'em but this'll do for now :)