Friday, November 3, 2017

Java Interview Questions for above 5 years experience

In this post we will know about who having above 5 years experience as a Java Programmer what topics he must covered before facing interview and what types questions he or she should face questions. If you are a Java programmer with 4 to 8 years experience of working in Java and looking for job change then its better to know what is expected from a 4 to 8 years experienced Java programmer in a typical core Java or J2EE interview. 

Since 4 to 8 years is  a huge experience so you must have cover these topics such as Garbage collection tuning or designing complex Java applications or even creating concurrent Java design pattern. Due to J2EE and various framework it’s difficult to survive as Java Developer, you must have some understanding of these framework before going for an interview.For designing perspective learn Design Patterns,Polyglot Persistence.earn Spring MVC with Hibernate, first learn basics then design some CRUD (CREATE,Read,Update,Delete Web App).Mutexes, ReadWriteLock, ConcurrentHashMap, ArrayBlockingQueue, Thread pools, LinkedList vs ArrayList, Object Pooling, Read-Modify-Write, java.util.concurrent, java.util.concurrent.atomic, CAS, Collections, ADT, Java 5 Generics,Java Memory Model, Weak references,Jini, JMS, Javaspaces, JGroups, Hibernate trivia,,best practices in API design,Service Oriented Architecture / Web Services - SOAP / Rest.But if experience is 6+ then expectation is bit higher and my most preferred questions are -Questions from Executer framework like semaphore, barrier, latch, thread pool, callable, etc. Thread safety, Explicit locking, etc.Servlets thread safety, Servlets listeners. 
ORM, why use ORM, which ORM to use, ORM with cache, problems in using ORM like Concurrency and persistence exceptions. JAX-WS, web services, REST, where to use REST
One framework is a must. Cloud computing concept and architecture. Messaging advanced, guaranteed delivery and integration, and where to use messaging and where to use web services.

The following are some of the interview questions must Read:

1) why we use Generics?

Ans: Using Generics we have lots of benefits. They are
  • Stronger type checks at compile time. And thus avoid casting errors at run-time.
  • No need of casting. No extra code for casting like String s = (String) list.get(0).
  • Better, Intelligent, Generic, and good looking programming.  

2)How can you tell that instance is never garbage collected?

Ans: This is nothing but a singleton kind of pattern. There's a static reference to a singleton, so it won't be eligible for garbage collection until the classloader is eligible for garbage collection.

3) Can we write final method in interface

Ans: NO, because interface methods do not have body . It need to be implement in implemented class.

4)How to implement a polling mechanism in Java?  How if I want to poll something. How if client is sending some requests to server and if request doesn't arrives in within time limit or if no requests for like 2 minutes, stop expecting more requests and suspend operation/listening/waiting ?

Ans: Using Class ArrayBlockingQueue. Also, an useful method of ArrayBlockingQueue -

Example: 

public E poll(long timeout,TimeUnit unit)throws InterruptedException

5) When are class garbage collected, when are classes unloaded?
Ans: The only way that a Class can be unloaded is if the Classloader used is garbage collected. 

6)Why does Java not support operator overloading?

Ans: Operator overloading makes the code very difficult to read and maintain. To maintain code simplicity, Java doesn't support operator overloading.

7)Difference between synchronized  block and synchronized method ?

Ans : Synchronized Method defines a self contained block and  its easy to handle in multi-threaded environment. Both act as similar; there is no major advantage over each other. The difference is that a synchronized block can choose which object it synchronizes on. A synchronized method can only use 'this' (or the corresponding Class instance for a synchronized class method).

8)Difference between java.util.date and java.sql.date ?

Ans : As we know every database support most three form of entry i.e. date, time and  timestamp. In java JDBC having all those supports using java.sql.Date, java.sql.Time, java.sql.TimeStamp. Internally all these JDBC classes extends java.util.Date.

9)How to handle the runtime exception in jsp?

Ans : In jsp page directive you can use isErrorPage=true.

10) Difference between Cyclic Barrier and Countdown Latch ?
Ans: 
  • 1. Important thing in barrier is number(which is increment till it reaches its limit) and in latch is count(which is decremented till it reaches 0). 
  • 2. Any thread can lower the count of latch by calling countDown(), i.e. without waiting, this can't happen in barrier. 
  • 3. Latch can't be reused. 
  • 4. In barrier we can have a BarrierAction, nothing similar is in Latch. 
11) What are the protocols for web services?

Ans: 


JSON-RPC (RPC) : All transfer types are single objects, serialized using JSON. https://code.google.com/p/json-rpc/wiki/Usage
JSON-RPC is lightweight remote procedure call protocol similar to XML-RPC

SOAP (SOA, needs WSDL):
SOAP like XML-RPC, but lot more features, requires WSDL. 

REST:
SOAP uses interfaces and named operations to expose business logic. REST uses (generally) URI and methods like (GET, PUT, POST, DELETE) to expose resources.

12)I want to print "Hello" even before main() is executed. How will you achieve that?

Ans: Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main() method. And it will be executed only once.

13)Should a main() method be compulsorily declared in all java classes?
Ans: No not required. main() method should be defined only if the source class is a java application.

14)I have 1 to 100 elements in array unordered, one element missed find that one?

Ans : There is existing old formula. Calculate the sum of all numbers stored in the array of size 11 means it hold 12 data. Then, subtract the sum from (12 * 13)/2

Basic Formula: n * (n + 1) / 2. 

15)We can get the container object through Bean factory and Application context what is the difference in both?

Ans: A BeanFactory is used to just instantiates and configures beans. An ApplicationContextalso does that, andit provides the supporting infrastructure to enable lots of enterprise-specific features such as transactions and AOP.

16)We have equals() to compare two methods then why comparator again ?

Ans : Because , equals() method will only compare the content . It cannot compare two different objects. Comparator interface has compareTo()  method  which compare 2 different object.

17)What is the difference between web server and app server?

Answer: A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols.

18) How does a 3 tier application differ from a 2 tier one?

Ans: Tiers are the physical units of separation or deployment, while layers are the logical units of separation.Imagine that you’re designing an e-commerce website. A 3 tier architecture would consist of web pages, a web server and a database, with the corresponding 3 layers being the “Presentation”, “Business Logic” and “Database” layers.
If you take the database tier and layer out then your have a 2 tier architecture.
Source.

19)How does the version control process works?

Ans: Initiate, pull, branch, merge, commit, push.
(Init) Make your own repository. (Pull) Download an existing repository from a url. (Branch / Merge )Make revisions. Commit then push your modifications.

20) Explain about Spring MVC?

Answer is huge...please check this  here Spring MVC tutorial

21)What are the ways to access Hibernate by using Spring?

Ans:  There are two ways to access Hibernate with Spring: They are
  • Inversion of Control with a Hibernate Template and Callback
  • Extending HibernateDAOSupport and Applying an AOP interceptor node.

22)What are the benefits of the Spring Framework's transaction management?


Ans: There are mainly 3 types of benefits. They are

  1. It integrates very will with spring's various data access abstractions.
  2. It provides consistent programming model across different transaction APIs such as JDBC,JPA,Hibernate and JDO.
  3. It supports declarative transaction management
23) Does Spring Security support password hashing? What is salting?

Ans: Yes, Spring Security provides support for password hashing. The salt is used to prevent dictionary attacks against the key in the event your encrypted data is compromised.

24)How is Security mechanism implemented using Spring?

Ans:  Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications. Spring Security is a framework that focuses on providing both authentication and authorization to Java applications. Like all Spring projects, the real power of Spring Security is found in how easily it can be extended to meet custom requirements. 

Spring makes use of the DelegatingFilterProxy for implementing security mechanisms. It is a Proxy for standard Servlet Filter, delegating to a Spring-managed bean that implements the Filter interface. Its the starting point in the springSecurityFilterChain which instantiates the Spring Security filters according to the Spring configuration

Some of the features of Spring Security are: 
Comprehensive and extensible support for both Authentication and Authorization
Protection against attacks like session fixation, clickjacking, cross site request forgery, etc
Servlet API integration Optional integration with Spring Web MVC.

25)How to enable Spring Security in Web Application?

Ans: You can enable the Spring security by adding the Filter org.springframework.web.filter.DelegatingFilterProxy in your application’s web.xml.

Watch Video:  Java Interview Questions for experienced Developers

No comments:

Post a Comment

High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...