If you are an interviewee -- You have no control over what questions will be asked in Java job interviews, but there are a few Java interview questions that are very frequently asked in job interviews, and it really pays to prepare for those questions. Here are a few such questions. This is based on some of my recent interviews. Brushing up on these answers will boost your success rate in Java job interviews.
The focus is on judging your experience. So, go through your resume and reflect back on your hands-on experience. Many of these answers will also serve you well in selling your technical strengths to open ended questions like -- tell me about yourself? , why do you like software development?, when reviewing others' work, what do you look for?, what was your most significant accomplishment?, etc
Q1. Can you describe the high level architecture of the application that you had worked on recently? or Can you give a 100 feet bird's eye view of the application you were involved in as a developer or designer?
A1. The purpose is to judge your overall experience. Here are a few links that will prepare for this most sought-after question, especially for the experienced professionals.
- 3 to n-tier enterprise Java architecture, the MVC-2 design pattern, the distinction between physical and logical tiers, and the layered architecture.The logical tiers shown in the diagrams for the above link are basically layers, and the layers are used for organizing your code. Typical layers include Presentation, Business and Data – the same as the traditional 3-tier model. But when talk about layers, we’re only talking about logical organization of code. Physical tiers however, are only about where the code gets deployed and run as war, ear or jar. Specifically, tiers are places where layers are deployed and where layers run. In other words, tiers are the physical deployment of layers.
- high level architectural patterns and the pros and cons of each approach. Discusses a number different architectual styles like MVC, SOA, UI Component, RESTful data composition, HTML data composition, Plug-in architecture, and Event Driven Architecture (EDA). Also, covers a sample enterprise architecture, which is a hybrid of a number of architectural styles.
- knowing the difference between a component and a service. Covers the differences between components and services and CBA (Component Based Architecture) Vs, SOA (Service Oriented Architecture). Also, briefly covers single page web design and SCA (Service Component Architecture)
- Understanding of various types of application integration styles. Enterprise applications need to be integrated with other systems, and this post covers different integration styles like sharing the same database, feed based, RPC style (e.g. web services), and exchanging JMS messages.
- Good working knowledge of popular and sought-after technologies and frameworks like Maven, Spring, Hibernate, JSF, etc. Covers a number of tutorials using sought-after frameworks and technologies like like Spring, Maven, JSF, JDBC, and RESTful web service.
Q2. How would you go about deciding between SOAP based web service and RESTful web service?
A2. Web services are very popular and widely used to integrate disparate systems. It is imperative to understand the differences, pros, and cons between each approach. Recently, I have been asked these questions very frequently, here is the answer that discusses the pros and cons of SOAP vs. RESTful web services in detail.
Q3.How will you go about ensuring that you build a more robust application? or How do you improve quality of your application?
A3. This question is very popular with the interviewers because they want to hire candidates who write good quality application. Here are some useful links to prepare for this question.
- Java interview questions and answers on code quality. Gives a high level over view as to things you can do and tools you can use to improve code quality. A common popular job interview question answered is -- What is the difference between fake objects, mock objects, and stubs?
- Unit testing with mock objects interview questions and answers. Tutorial that explains how to write JUnit tests with mock objects using the Mockito and Power mock frameworks.
- Unit testing Spring MVC controllers for web and RESTful services with spring-test-mvc. Tutorial for writing Spring MVC unit tests.
- Selenium and Web Driver for unit testing Java GUI. Tutorial for writing functional unit tests for web applications to test display logic.
- Hibernate Interview Questions and Answers: integration testing the DAO layer. Tutorial for unit testing the DAO layer using hibernate.
- Java Interview Questions and Answers - performance testing your Java application. A high level overview as to how you can go about monitoring performance. Many applications face performance issues and this is a very popular question with the interviewers.
- Using JMeter for performance testing Java application.A JMeter tutorial for conducting performance tets
Q4. What are some of the best practices regarding SDLC? Have you worked in an agile development environment? Did you use test driven development and continuous integration?
- Know the SDLC and the best practices . Gives a high level overview of SDLC.
A5: You will be asked to write a small function or a program. The interviewer will be looking for things like
- How well you analyze the requirements and the solution? Ask relevant questions if the requirements are not clear. Think out loud so that the interviewer knows that how you are approaching the problem.The approach is more important that arriving at the correct solution.
- List all possible alternatives.
- Write pseudo code.
- Write unit tests.
- Where required, brainstorm with the interviewer.
- Find ways to improve your initial solution. Talk through thread safety and best practices where applicable.
- Java coding interview questions and answers:. Covers a number of coding questions with answers. These are some of the popular coding interview questions like reversing a string, calculating the Fibonacci number, recursion vs iteration, equals versus ==, etc.
Q6. How would you go about designing a car parking station?
Map out the requirements:
- The car park needs to cater for different types of car parks like regular, handicapped, and compact.
- It should keep track of empty and filled spaces.
- It should also cater for valet parking.
- A CarPark class to represent a parking station.
- A ParkingSpace can be an abstract class or an interface to represent a parking space, and RegularParkingSpace, HandicappedParkingSpace, CompactParkingSpace, etc are subtypes of a ParkingSpace. This means a RegularParkingSpace is a ParkingSpace.
- A CarPark has a (i.e. composition) finite number of ParkingSpaces. A CarPark also keeps track of all the parking spaces and a separate list of all the vacant parking spaces.
- A Vehicle class uses a (i.e. delegation) ParkingSpace. The Vehicle class will hold attributes using enum classes like VehicleType and ParkingType. The vehicle types could be Compact, Regular, and Handicapped. The parking types could be Self or Valet. Depending on the requirements, the self or valet types could be designed as subtypes of the Vehicle class.
Q7: Can you design the classes that represent a restaurant?
A7: Very popular. Good understanding of OO design is vital to job interview success. Learn the SOLID design principles, know why you favor composition over inheritance, and don't under estimate the power of coding to interface.
- Java OO Interview Questions and Answers. A step-by-step tutorial explaining how you would go about designing your classes. The "Core Java Career Essentials" PDF covers more examples on SOLID design principles with working code.
How would you go about identifying thread safety issues in an application? How would you go about identifying memory leaks issues? How would you go about identifying performance issues?, etc to judge your experience. I am yet to work on a project that didn't face problems relating to thread safety, memory leaks, and performance issues. Hence, it really pays to market your skills and experience in fixing issues relating to these common challenges.
Q8. How will you go about fixing memory leaks in Java?
A8. Again, a very common problem, and a thorough answer will go a long way in securing your next Java job.
- Detecting and fixing memory leak issues in Java. Tools and techniques to detect memory leaks in Java.
- Memory profiling in Java. Tutorial on memory profiling a Java application.
Q9: How will you go about fixing performance issues in Java?
- Detecting performance issues in Java. A basic tutorial covering -- how to detect performance issues.
- Also, refer to the JMeter tutorials in this blog as to learn how you can put load on your application to simulate concurrent users.
Q10: How will you go about detecting and fixing thread-safety issues in Java?
A10: Debugging concurrency issues and fixing any thread starvation, dead lock, and contention requires skills and experience to identify and reproduce these hard to resolve issues. Here are some techniques to detect concurrency issues.
- Manually reviewing the code for any obvious thread-safety issues. There are static analysis tools like Sonar, ThreadCheck, etc for catching concurrency bugs at compile-time by analyzing their byte code.
- List all possible causes and add extensive log statements and write test cases to prove or disprove your theories.
- Thread dumps are very useful for diagnosing synchronization problems such as deadlocks. The trick is to take 5 or 6 sets of thread dumps at an interval of 5 seconds between each to have a log file that has 25 to 30 seconds worth of runtime action. For thread dumps, use kill -3
in Unix and CTRL+BREAK in Windows. There are tools like Thread Dump Analyzer (TDA), Samurai, etc. to derive useful information from the thread dumps to find where the problem is. For example, Samurai colors idle threads in grey, blocked threads in red, and running threads in green. You must pay more attention to those red threads.
- There are tools like JDB (i.e. Java DeBugger) where a “watch” can be set up on the suspected variable. When ever the application is modifying that variable, a thread dump will be printed.
- There are dynamic analysis tools like jstack and JConsole, which is a JMX compliant GUI tool to get a thread dump on the fly. The JConsole GUI tool does have handy features like “detect deadlock” button to perform deadlock detection operations and ability to inspect the threads and objects in error states. Similar tools are available for other languages as well.
Java Interview Questions 11- 13 for experienced developers