- Interview Questions and Answers for 'Intermediate' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



- Interview Questions and Answers for 'Intermediate' - 107 question(s) found - Order By Rating

next 30
 Q1. What are the different ways to avoid multi Threading related problems in Java ?Core Java
Ans. Synchronization,
Concurrent classes,
Volatile keyword,
Implementing concurrent Lock interface,
Immutable classes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     multithreading  threads  ways to avoid thread related problems  synchronization  volatile  concurrent collections      Intermediate


 Q2. How many VTables are there for each class ? Core Java
Ans. There is one VTable for each class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     virtual table method  vtable  runtime polymorphism  object oriented programming (oops)  oops concepts   method overriding      intermediate        rare


 Q3. Describe structure of a Web application.architecture
Ans. WEB APP |WEB-INF - META-INF | | | META-INF.MF | lib - WEB.xml - Classes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     web application     Asked in 3 Companies      intermediate        frequent


 Q4. Can we use Prototype Bean scope with Autowiring ?Spring
Ans. Default Bean scope in auto wiring is Singleton but Yes, that can be changed by specifying the Bean scope explicitly.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     spring boot   spring mvc  autowiring  bean scope   prototype bean scope      intermediate


 Q5. Write Java code that would cause deadlock ?Core Java
Ans. https://howtodoinjava.com/java/multi-threading/writing-a-deadlock-and-resolving-in-java/

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     multithreading  threads  deadlock     Asked in 1 Companies      intermediate


 Q6. How do you check memory leak in Java?Core Java
Ans. You need to capture heap dump when it's in the healthy state. Start your application. Let it take real traffic for 10 minutes. At this point, capture heap dump. Heap Dump is basically the snapshot of your memory. It contains all objects that are residing in the memory, values stored in those objects, inbound

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory leaks  heap dump     Asked in 1 Companies      intermediate


 Q7. what is fail fast and Fail Safe in collections?Core Java
Ans. Iterators in java are used to iterate over the Collection objects.

Fail-Fast iterators immediately throw ConcurrentModificationException if there is any addition, removal or updation of any element.

Fail-Safe iterators don't throw any exception if a collection is structurally modified while iterating over it. This is because, they operate on the clone of the collection and not on the original collection.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     ail fast   fail saf     Asked in 9 Companies      intermediate


 Q8. How can we ensure thread safety in static method ?Core Java
Ans. By using synchronized static method or synchronized block

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     threads  synchronization  static methods     Asked in 2 Companies      intermediate


Usually asked in relation to casting and ClassCastException.
 Q9. What is instanceOf operator ? Explain it's use ?Core Java
Ans. The operator instanceOf is used to verify if the specified object is the instance of specified class or interface.

Syntax if(x instanceOf ABC)

where x is an object reference and ABC could be a class name or interface name. The above statement will be true if x holds an object that is an instance of ABC or any of the child class of ABC or if x holds an object that implements ABC.

instanceOf operator is used to verify in case of downcasting. For ex -

DerivedClass extends BaseClass

x is the reference of BaseClass but holds DerivedClass object ( Polymorphism )

There is an operation that is defined in Derived Class, let's say derivedClassMethod()

We cannot call derivedClassMethod() directly using x as x is reference of BaseClass and not DerivedClass and hence can only access methods that are defined in BaseClass and overridden in derived class.

Though we can cast it to DerivedClass as following
((DerivedClass)x).derivedClassMethod();

But it may throw ClassCastException in case x doesn't hold an instance of DerivedClass at that point.

So before casting it to DerivedClass we may like to make sure that it is an instance of DerivedClass and hence won't throw ClassCastException.

So we make a check for it

if(x instanceOf DerivedClass) {
((DerivedClass)x).derivedClassMethod();
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     instanceOf  instanceOf operator  Why we need instanceOf operator  use of instanceOf operator     Asked in 2 Companies      Intermediate        frequent


 Q10. Can we catch errors in Java ? Core Java
Ans. Yes we can

try {
// code
} catch (Error ex) {
// handling code
}

but we shouldn't ideally do that as errors are mostly JVM based and not application based and there is rarely we can do something about it. Very likely catching and not re throwing would lead to muting their response or trace.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exception handling  error handling  errors     Asked in 1 Companies      intermediate


 Q11. What is the purpose of String Pool ? Don't you think it's a performance overhead to have unnecessary check for string in string pool ?Core Java
Ans. String Pool makes Java more memory efficient by providing a reusable place for string literals. It might be a little performance inconvenience but results in good amount memory saving.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     string pool  memory management      Intermediate


 Q12. Which are the most commonly used Design Patterns ?Design
Ans. Builder ( While Writing Unit Tests )
Prototype ( Cloning )
Adapter ( asList , toString )
Chain Of Responsibility ( Logging )
Singleton
Factory ( Action Mapping )
Proxy
Observer ( Event Listener )
MVC ( Web frameworks )
Filter ( Criteria )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Design Patterns  widely used Design patterns      intermediate        frequent

Try 1 Question(s) Test


 Q13. How to create list that will sort it's elements dynamically?Algorithm
Ans. Override the behavior of collection class to sort the list upon each element addition. Though it's not recommended as list are sorting heavy data structures.

List<MyType> list = new ArrayList<MyType>() {
public boolean add(MyType mt) {
super.add(mt);
Collections.sort(list, comparator);
return true;
}
};

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies      intermediate


 Q14. What is Exception Wrapping ?
Ans. Exception wrapping is wrapping an exception object within another exception object and then throwing the outer exception.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exception handling  exception wrapping  exceptions      intermediate        rare


 Q15. Which is your favorite Design pattern, each in Creational , Structural and Behavioral and Why ?Design
Ans. [Open Ended Answer]

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Design Patterns      Intermediate


 Q16. Name few Behavioral Design Patterns ?Design
Ans. Interpreter,Chain of Responsibility,Command,Iterator,Observer,Mediator,Memento

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Behavioral Design Patterns      Intermediate


 Q17. Name few structural Design Patterns ?Design
Ans. Adapter,Bridge,Composite,Decorator,Facade,Flyweight,Proxy

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Design Patterns  Structural Design Patterns      Intermediate


 Q18. Name few creational design patterns ?Design
Ans. Factory,Abstract Factory,Singleton,Prototype and Builder

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Design Pattrns  Creational Design Patterns      Intermediate


 Q19. What will be the output of following code ?

Base Interface

public interface BaseInterface {
   int i = 4;
}

Derived Interfaces

public interface DerivedInterface1 extends BaseInterface{
   int i = 5;
}

public interface DerivedInterface2 extends BaseInterface{
   int i=6;
}

Implementing Class

public class Class implements DerivedInterface1,DerivedInterface2 {
int i=10;   

public static void main(String[] args){
      System.out.println(new Class().i);
   }
}

What will be the output upon executing main and Why ?
Core Java
Ans. 10

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interfaces  coding  code      intermediate


 Q20. What will be the output of following code ?

Base Interface

public interface BaseInterface {
   int i = 4;
}

Derived Interfaces

public interface DerivedInterface1 extends BaseInterface{
   int i = 5;
}

public interface DerivedInterface2 extends BaseInterface{
   int i=6;
}

Implementing Class

public class Class implements DerivedInterface1,DerivedInterface2 {
   public static void main(String[] args){
      System.out.println(BaseInterface.i);
   }
}

What will be the output upon executing main and Why ?
Core Java
Ans. It will print 4 because member elements of an interface are implicitly static and hence the concept of overriding doesn't work.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interfaces  coding  code  extending interfaces  diamond interfaces     Asked in 1 Companies      intermediate


 Q21. What is the difference between

File f = new File("homexyz.txt");

and

File f = File.createTempFile("xyz",".txt","home"); ?
Core Java
Ans. First will not create physical file in storage whereas the second will.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     file handling  File.createTempFile  file handling      intermediate        rare


 Q22. Can you name some of the Java frameworks in different domains ?Frameworks
Ans. Web Framework - Spring , Struts, Play
Dependency Injection frameworks - Google Guice , PicoContainer and Dagger
ORM Framework - Hibernate
Big Data / ETL Frameworks - Apche Hadoop , Apache Crunch, Apache Spark.
View Frameworks - JSF , Apache Wicket,jtwig.
Java Gui Frameworks - SWT , AWT, JavaFX
Testing - Junit, Mockito, PowerMock, EasyMock, JMock, JMockit
Rest Web services - Jersey , Restlet , RestX, RestEasy ,Restfulie

Here is the big list for reference - http://javasearch.buggybread.com/home2.php?keyword=

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     frameworks     Asked in 2 Companies      intermediate        frequent


 Q23. What are the benefits of creating immutable objects ?Core Java
Ans. 1. Security and Safety - They can be shared across multiple threads as they are thread safe. Moreover, it protects then from bad state due to interception by the other code segment. One such problem due to mutability and access by alternate code segment could be the change of hash code and then the impact on its search with hash collections.

2. Reuse - In some cases they can be reused as only one copy would exist and hence it can be relied upon. For example - String Pool

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     immutable  immutability objects     Asked in 1 Companies      Intermediate        frequent


 Q24. What is memory leak ? How Java helps countering memory leaks compared to C++ ?Core Java
Ans. Memory Leak is a situation wherein we have a reserved memory location but the program has lost its reference and hence has no way to access it.

Java doesn't have concept of Pointers, Moreover Java has concept of Garbage collection that frees up space in heap that has lost its references.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory leak  garbage collection      intermediate        frequent


 Q25. how to access the methods of an inner class?Core Java
Ans. It depends on the type of inner class

To access non static inner class method

new OuterClass().new InnerClass().getMethod();

To access static method of static inner class

new OuterClass.InnerClass().getMethod();

  Sample Code for inner class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inner classes  nested aclasses     Asked in 1 Companies      Intermediate        frequent


 Q26. Can we convert a numeric IP address to a web host name ?Java EE
Ans. Yes, using InetAddress.getByName("<IP Address>").getHostName();

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     ip address to hostname  INETAddress      intermediate


 Q27. What is an IO Filter ?Core Java
Ans. It's an object that reads from one stream and writes to another.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java io  io filter      intermediate


 Q28. What is the difference between the Reader/Writer java.io hierarchy and the Stream class hierarchy?Core Java
Ans. The Reader/Writer hierarchy is character oriented, whereas the Stream class hierarchy is byte oriented.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java io  streams      intermediate


 Q29. What kind of thread is garbage collection thread ?Core Java
Ans. Daemon thread

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     garbage collection      intermediate

Try 2 Question(s) Test


 Q30. What is nested interface?Core Java
Ans. Interface that is declared inside the interface or class, is known as nested interface. It is static by default.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interface  nested interface      intermediate

Try 1 Question(s) Test


next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: