Top 50 Java Interview Questions for Freshers

Upasana | May 05, 2019 | 3 min read | 153 views


Core OOP Concepts

Collections Framework

  1. What is the criteria for a class to be eligible for key in Hashmap ?

  2. What are benefits of making a class Immutable? How will you make a class Immutable?

  3. What is difference between ArrayList and Vector? Which one shall be preferred?

  4. Discuss how Hashtable works?

  5. Write code to remove entries from hashmap while iterating over it?

  6. What is difference between fail-safe and fail-fast iterators? Give example of each in Java Collections framework?

  7. What is the difference between the size and capacity of a Vector? Answer : The size is the number of elements actually stored in the vector, while capacity is the maximum number of elements it can store at a given instance of time.

Concurrency & multi-threading

  • What is difference between Callable and Runnable interface?

  • Explain visibility and atomicity problems faced in multi-threaded environment?

  • What is use of Volatile variables in Java ? Explain working of volatile with respect to register cache & main heap memory?

  • Can volatile keyword be used to make a non-atomic operation as atomic?

  • What is difference between wait() and sleep() method in Java?

  • How will you implement a thread-safe singleton in Java?

  • Which one of the following would be easy to write? thread-safe code for for 10 threads or 2 threads?

  • How do you call wait() method? using if block or loop? Why? Provide a example for your explanation.

  • How do you take thread dump in Java on Windows and Unix machine?

  • What is a thread local variable in Java? Give an example where you will you a ThreadLocal variable?

  • Write wait-notify code for producer-consumer problem?

  • What is an immutable object? How and why do you create an Immutable object in Java?

Database

  • How will you join two Tables A and B where data in Table B is optional, i.e. even if no matching record exists in Table B, rows of Table A shall appear in the query result? Answer : Hint is Left Outer Join between A and B

  • How will you find nth highest salary from Employee Table using SQL?

  • What is difference between Cluster and non-cluster index in RDBMS?

  • How is ManyToMany relationship implemented in database? Give a practical example of ManyToMany relationship?

  • What is difference between inner join and outer join?

  • When will you choose a RDBMS over NoSql and vice versa?

Unix OS

  1. How will you create a service in unix (ubuntu/centos) that automatically starts at reboot.

  2. How will you kill a process in linux?

  3. How to continuously check last 200 lines of a log file?

  4. How to find remaining disk space in linux server?

  5. How to make any script file executable?

  6. How to schedule a repeating job in UNIX using crontab?

  7. What is piping of commands in Unix? Any example?


Buy my ebook for complete question bank

Most of these questions has been answered in my eBook "Cracking the Core Java Interview" updated on June 2018, that you can buy from this link:

Buy from Shunya (DRM Free PDF download with updates)

Top articles in this category:
  1. Top 50 Spring Interview Questions
  2. Multi-threading Java Interview Questions for Investment Bank
  3. Sapient Global Market Java Interview Questions and Coding Exercise
  4. BlackRock Java Interview Questions
  5. Citibank Java developer interview questions
  6. UBS Java Interview Questions
  7. Morgan Stanley Java Interview Questions

Recommended books for interview preparation:

Find more on this topic: