Resume Java Job Interview
Resume Java Job Interview
Java - Fundamentals
Q 01: Give a few reasons for using Java?
Java is built-in support multi-threading, socket communication, and memory management
with automatic garbage collector.
Object Oriented (OO)
It's work in different platforms and operating systems.
Q 02: What is the main difference between the Java platform and the other software
platforms?
Java platform is a software only platform, which run on top of other hardwares-base
platforms like Unix, Windows, etc.
It has two components:
- Java Virtual Machine (JVM) and Java Application Programming Interface (Java API)
Q 04: What are the usages of Java packages?
It helps resolve naming conflicts when different package have classes with the same name.
This also helps you to organize files within your project.
Q 06: What is the difference between constructors and other regular methods? What
happens if you do not provide a constructor? Can you call one constructor from
another? How do you call the superclasss constructor?
Constructors must have the same name at the class name. The constructors are called only
once per creation but method can be called many times. If I not provide a constructor, Java
will create a default constructor with empty arguments. Yes you can call one constructor
from another using the keyword this. I can call the super class with the keyword super.
Q 07: What are the advantages of Object Oriented Programming Languages (OOPL)?
Directly represent the real life objects like customers, cars, account, etc. The pillars of the
OO are polymorphism, inheritance and encapsulation.
Q 08: How does the Object Oriented approach improve software development?
The key benefits are:
- Re-use of previous work, Real mapping of objects and modular architecture.
Q 10: What do you mean by polymorphism, inheritance, encapsulation, and dynamic
binding?
POLYMORPHISM, ability to create a subclass of an existing class and redefine how a method
works.
INHERITANCE, is the inclusion of behavior (methods) and state (variables) of a base class in
a derived class so that they are accessible in that derived class. Code reuse.
They are two types of inheritance:
1. Implementation Inheritance, public abstract class NameClass { public void metohodName()
}.
2. Interface inheritance with composition, public abstract NameInterface { public abstract
void methodName() }
ENCAPSULATION, keeping all related members (method and variables) together in a object.
Q 12: What is the difference between an abstract class and an interface and when
should you use them?
Abstract Class, are used to declare common characteristics of subclasses. An abstract class
cannot be instantiated. It can only be used as a superclass for other classes that extend the
abstract class.
Interfaces, Have no implementation code, cannot be instantiated, all method are abstract. It
can be using for polymorphic interface inheritance.
Q 13: Why there are some interfaces with no defined methods (i.e. marker interfaces)
in Java?
This interface are like markers, also known as "tag".
Q 14: When is a method said to be overloaded and when is a method said to be
overridden?
Overloaded, multiple methods in the same class with the same name but different methods
signatures.
Overridden, deals with two methods, one in the parent class and the other one in the child
class and has the same signature and name.
Q 15: What is the main difference between an ArrayList and a Vector? What is the
main difference between HashMap
and Hashtable? What is the difference between a stack and a queue?
Vectors and HashTable, original classes before the introduction of Collections API, are
synchronized.
ArrayList and HashMap, no synchronized with better performance. It has some convenient
methods like add(..) or remove(..) also support index base searches with indexOf(..) and
lastIndexOf(..) methods.
Queue, this mechanism is called Fist In First Out (FIFO)
Stack, this is called Last In Firts Out (LIFO)
Q 16: Explain the Java Collections Framework?
Set (HashSet, TreeSet), a Set is a collection with unique elements, is a ordered HashSet,
witch implements the SortedSet interface.
List (ArrayList, LinkedList, Vector, etc), is a collection with an ordered sequence of elements
and may contain duplicated.
Map (HashMap, TreeMap and Hashtable), can contain duplicate values, but keys in map must
be distinct. TreeMap is ordered HashMap, witch implements the SortedMap interface.
Iterator, is a object to access the objects stored in a collection
Q 21: What is the main difference between a String and a StringBuffer class?
String, is immutable. You can't modify a string object but you can replace it creating a new
instance but it's expensive.
StringBuffer, is mutable you can modify content but it's not synchronized.
Q 23: What is serialization? How would you exclude a field of a class from serialization
or what is a transient variable?
What is the common use? What is a serial version id?
Serialization, is a process of reading an writing an object. It is a process of saving an
object's state to a sequence of bytes. A common use of serialization is to use it to send an
object over the network or if the state of an object need to be persisted to a flat file or a
database.
Transient Variable, cannot be serialized the object will not be transmitted in the byte stream.
Java Serial Version Id, is a unique identifier.
Q 27: What is the difference between an instance variable and a static variable? How
does a local variable compare to
an instance or a static variable? Give an example where you might use a static
variable?
Static variable (Class Variable), there is only one occurrence of a class variable per class
loader. It's used in a singleton pattern. Is used with final modifier to define constant.
Instance variable (Member Variable or Field), are non-static and there is one occurrence of
an instance variable in each class instance.
Q 28: Give an example where you might use a static method?
Is useful to create a utility classes, singleton classes and factory methods.
Q 29: What are access modifiers?
public, a class or interface may be accessed from outside the package. Outer classes,
interfaces, constructors, inner classes, methods and field variables may be accessed
wherever their class is accessed.
protected, accessed by other class in the same package or any subclasses of the class in
witch they are referred (Same package or different package), used with constructors, inner
classes, methods and field variables.
private, accessed only within the class in witch they are referred.
No modifier(package by default), accessed only from within the package in witch they are
declared.
Q 30: Where and how can you use a private constructor?
Is used if you do not want other classes instantiate the object to prevent subclassing, it's
using in a singleton design pattern and in a factory method.
Q 31: What is a final modifier? Explain other Java modifiers?
A final class can't be extended or be subclassed. A final method can not be overridden when
its class is inherited. You can not change a value of a final variable (it's a constant).
Modifier
Class
Method
Variable
static
A static method is
called by
classname.method.
Can only access
static variables.
abstract
N/A
synchronizer
N/A
N/A
transient
N/A
N/A
final
native
N/A
Platform dependent.
N/A
No body, only
signature
Q 34: How does Java allocate stack and heap memory?
Each time an object is created in Java goes into the area of memory called heap. The
primitive variable like double and int are allocated in the stack.
Q 35: Explain Outer and Inner classes (or Nested classes) in Java? When will you use
an Inner Class?
The inside class is called an inner class and the enclosing class is called an outer class. So
when you define an inner class, it is a member of the outer class in much the same way as
other
members like attributes, methods and constructors.
Outer Class, package member class or interface. Top level class. Only type JVM can
recognize.
//package scope
class Outside{}
Outside.class
Inner class, static or interface. Must be static & can access static members of its containing
class.
//package scope
class Outside {
static class Inside{ }
}
Outside.class ,Outside$Inside.class
member class, defined within the context of outer class, but non-static.
class Outside{
class Inside(){}
}
Outside.class , Outside$Inside.class
Local class, Defined within a block of code. Can use final local variables and final method
parameters.
class Outside {
void first() {
final int i = 5;
class Inside{}
}
}
Outside.class , Outside$1$Inside.class
Q 43: Explain different ways of creating a thread? Which one would you prefer and
why?
Threads can be used by either :
- Extending the Thread class
- Implementing the Runnable interface.
The Runnable interface is preferred, as it does not require your object to inherit a thread
because when you need multiple inheritance, only interfaces can help you.
Q 44: Briefly explain high-level thread states? Why synchronization is important?
- Runnable:waiting for its turn to be picked for execution by the thread scheduler based on
thread priorities.
- Running: The processor is actively executing the thread code. It runs until it becomes
Strengths:
- Taking initiatives and being pro-active
- Design skills
- Ability to work in a team environment as well as independently
Q 01: What is J2EE? What are J2EE components and services? What are Web and EJB
containers?
J2EE is a 3-tier (or n-tier) system. Each tier is logically separated and loosely coupled from
each other, and may be
distributed.
EJB are interfaces between client tier and application tier.
Q 03: Explain MVC architecture relating to J2EE?
It divides the functionality of displaying and maintaining of the data and act as the glue
between a model and a view.
Model (Entity/Session Bean EJB) View (JSP, javabeans) Controllers (Servlet).