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. |
|
| ||||
- Interview Questions and Answers for 'Intermediate' - 107 question(s) found - Order By Rating | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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. | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||