PhaseZero Interview Experience

Sharing a few PhaseZero interview questions for the Java Developer role. The questions were very basic.

PhaseZero Interview Experience questions -

  • What is the difference between Extend and Implement? - 
  1. Extends is used when we are extending the base class. Implements is used when we are implementing an interface. 
  2. A class can extend only one class but can implement any number of interfaces. For example, ArrayList implements 4 interfaces, i.e. List, RandomAccess, Cloneable, and Serializable.
  3. A class must implement all the methods from an interface.

  • What is the difference between Hashmap and Hashtable?
  1. Hashmap is non-synchronized. It cannot be shared between many threads without proper synchronization code, whereas Hashtable is synchronized. However, Hashmap can be made synchronized by inserting a code.
  2. Hashmap allows one null key and multiple null values, whereas Hashtable doesn't allow any null key or value.
  3. Hashmap is comparatively faster than Hashtable.
  4. Hashmap is traversed by Iterator and Hashtable can be traversed by the Iterator as well as Enumerator.
  5. Hashmap inherits AbstractMap class whereas Hashtable inherits Dictionary class.

  • Difference between ClassNotFoundException vs ClassDefNotFoundException?
When a classpath is not defined with the updated JARS, a runtime exception is thrown which is known as ClassNotFoundException Whereas, like the name says ClassDefNotFoundException, during run time when a class is not declared, an error is thrown saying that ClassDefNotFound, it can be a case, that the class was present at compile time but couldn't be found during runtime.


  • How to create customException in Java?
User-defined exceptions can be created in java using the throw keyword.


  • What is the root class of Exception?
The answer is Throwable. Please find below block diagram.

Exception in Java

  • Difference between Interface and Abstract class?
We have already covered this topic in another post.

  • Given a table with dept_id and dept_name columns and Student table with name, dept_id and marks, write query to
    select students with marks greater than 75 of given dept name.

Select b.marks
from students b
INNER JOIN Department b
ON a.dept_id = b.dept_id Where marks > 75;


  • Final methods and variables in Java?
Final is a keyword that can be applied to variables, methods, classes and local variables in java the value assigned cannot re-initialized. A method or class used with the Final keyword cannot be over-ridden.

  • Difference between the Singleton and Factory design patterns?
Singleton design pattern is a pattern in java where a single instance of a class is created and a single object is used by all other classes. For instance, a single DB connection shared by all other classes. 

Implementation of Singleton Pattern -
class SingletonImpl{
...
private static singletonInstance = null;
...
private SingletonImpl(){
...
}
public synchronized static getSingleton(){
if(singletonInstance == null) singletonInstance = new SingletonImpl();
return singletonInstance;}
...
}

Note that the Constructor is declared private.

Factory Design Pattern-  Factory design patterns creates a new instance of the object whenever the factory method is being called.


  • What are the different ways of creating objects?
There are basically 4 different ways using which we can create an object in Java -
  1. By using the new keyword
  2. using Class.forName() keyword
  3. using Clone()
  4. using object deserialization
  • What are the different methods in Object Class?
There are lots of methods used in Object class, some of them are listed below -

Methods in Object Class

  • Explain the life cycle of thread?
There are 5 states of Thread life-cycle -
  1. New
  2. Runnable
  3. Running
  4. Non-runnable(Blocked)
  5. Terminated
Thread Life-cycle




  • Difference between Start() and Run() method?
When program calls start() method, a new thread is created and code inside Run() method is executed in a new thread, while run() method will create no new thread and code inside Run() will execute in the current method.


Comments

Popular posts from this blog

Azure Tutorials Series - Azure Networking

Coforge Interview Questions | Automation Testing profile

Testing in CI/CD