We provide IT Staff Augmentation Services!

Delete This

Java Interview Questions

  • We are interested in your best answers to the following questions it gives us good insight into the detail of your work. If you are short on time, you may defer work on questions 7a, 11,and 13, but you should be prepared to discuss their solutions if a phone interview is scheduled. Please try to finish all questions highlighted in grey.
  • Core Java:
  • Question 1 What is the difference between an abstract class and an interface and when would you choose one over the other
  • Question 2 What is reflection in java and can you suggest a design pattern that can use reflection. Please write pseudo-code to explain how reflection is used by the design pattern.
  • Question 3 Write an enumtype that has members , length and width. Define various constants baseball, soccer, football within the enum. Write a method within the enumthat returns area of the enum constant. I,esoccer.calculateArea .
  • Question 4 Explain use cases of the key words final, finally, finalized in java.
  • Question 5 A class opens a Filestream for writing in the constructor. How can you assure that the file stream is closed when the garbage collector kicks in What is a better alternative in java to process files for writing while assuring that they are closed properly

Java/Generics:

  • Question 6 Write the signature of PushAll and PopAll methods of a custom generic stack that stores objects of multiple types that inherit from the same base class.
  • Spring/Jdbc
  • Question 7 a
  • You are given the following database table. Please follow the following steps to answer the question.
  • Step A Write a class Person that has members variables :FirstName, LastName Address
  • Step B Write a class that implements spring's org.springframework.jdbc.core.RowMapperinteface.
  • Step C Use org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate to query the database table via using the class in Step B . As part of this step write a method that returns list of class Person that was written in Step A
  • Question 7 - b
  • If you need to create one singleton object of the class Person above e.g. President of the country and use references to it in your application how will you create it using Spring framework Any new methods and annotations need to be added to the class Person or other classes storing reference to president
  • Threading
  • Question 8
  • Sketch out the code for a thread-safe queue, in particular the pushBack and popFront functions that would be suitable for a producer/consumer problem. The consumer threads should be able to wait efficiently for items to be produced.
  • Data Structures
  • Question 9
  • Please report the appropriate container of choice for each of the following scenarios. Justify your choice.
  • 1. You are passed an unknown number of elements that need to be stored in a container can be as few as 5, and as many as 100000 . We have a use case to search the container and find the appropriate element.
  • 2. Random set of data is passed to us, we need to store the data in a container and later report it to the user in a sorted fashion. The insertion in to our container needs to be as fast as possible. We can take a small hit on performance during presentation when the data needs to be sorted.
  • General Questions
  • Question 10
  • You are given the following dependencies between files. Write pseudo-code for a function that prints the order in which the files can be processed assuming no cyclical dependencies between files.
  • File A depends on B, file C depends on A, file D depends on E and A. File E depends on file F.
  • Question 11
  • You are passed a sorted array, write code that finds the number of 0s in the array. Please try to implement this as a log N solution. If short on time write pseudo-code and explain your implementation.
  • Question 12
  • Write a function that takes a list of integer ranges and an additional range and efficiently prints all non-overlapping ranges from the additional range. For example, given a list or ranges 6000000 10000000 , 17000000 24000000 , 15000000 19000000 and a new range 8000000 28000000 , your function should print 10000001 14999999 , 24000001 - 28000000 . The only guarantee is the range is valid i.e. range.start

Hire Now