With an estimated 9 million developers using it, Java
is one of the most popular programming languages around. In fact, some estimate that Java powers more than 3 billion devices. With so many people claiming expertise, IT managers often ask tricky technical questions to separate the novices from senior developers, says David Bolton, guide of the Dice Java Talent Community. Here are some questions you can expect to hear. What is Type Erasure?
What are the differences and similarities between an abstract class and an interface?
- What Most People Say: “Umm, I’m not sure.”
- What You Should Say: “Type erasure means the runtime has no knowledge of the types of generic objects.”
- Why You Should Say It: Most developers aren’t familiar with type erasure, which is an aspect of generics. You can prove that you’re an advanced programmer by demonstrating your understanding of generic objects and how to work around them.
How do you make Java methods virtual?
- What Most People Say: “I’m not familiar with the similarities and differences between abstract classes and interfaces, or when to use each one.”
- What You Should Say: “As for the differences, interfaces allow a form of multiple inheritance. A class can only extend one other class. And interfaces are limited to public methods and constants with no implementation, while abstract classes can have a partial implementation, protected parts, static methods, etc. Also, a class may implement several interfaces, but a class may extend only one abstract class. Interfaces tend to be slow as there is extra indirection required to find the corresponding method in the actual class, while abstract classes are faster. As for the similarities, neither abstract classes nor interfaces can be instantiated.”
- Why You Should Say It: Knowing the differences between the two is important because it drives the decision about when to use an abstract class or an interface.
See interview questions for Android developers here. What’s the difference between abstraction and encapsulation?
- What Most People Say: “I don’t know because I started my programming career in C++.”
- What You Should Say: “There is no need to make Java methods virtual. They are defined as virtual automatically.”
- Why You Should Say It: Knowing the answer shows that you’re a more experienced developer.
What’s the base class for Error and Exception?
- What Most People Say: “I always seem to confuse the two.”
- What You Should Say: “Abstraction hides the implementation details, whereas encapsulation hides the data. Abstraction lets you focus on what the object does instead of how it does it.”
- Why You Should Say It: Your answer shows that you understand the two concepts and how to apply each one.
What’s difference between throw and throws?
- What Most People Say: “I don’t know.”
- What You Should Say: “The super class or base class for Exception and Error is Throwable.”
- Why You Should Say It: It’s the right answer.
Why is the main() function defined as static?
- What Most People Say: “I don’t understand the difference between throw and throws.”
- What You Should Say: “Throw is used explicitly to throw an exception, whereas throws is used to declare an exception.”
- Why You Should Say It: You aren’t any good if you don’t know the difference.
What’s the difference between .equals() and “==”?
- What Most People Say: “I’ve used it. But to be frank, I haven’t thought about why the main() function is defined as static.”
- What You Should Say: “So it can be called without needing to create an instance.”
- Why You Should Say It: Most developers have used the function but don’t know why. A more proficient developer understands the purpose. The method is static because otherwise there would be ambiguity about which constructor should be called.
- What Most People Say: “I guess I don’t know this one either.”
- What You Should Say: “== is used to see if two objects are the same object. For example, to see if it occupies the same area in memory while equals compares values. == is done by comparing references while equals compares the contents. So two different strings with the same value would give true for equals but false for ==.”
- Why You Should Say It: The correct answer shows that you understand how objects are stored in memory.