Top 10 Frequently Asked Java Interview Questions | With Answers, Tricky Ques

Top 10 Frequently Asked Java Interview Questions | With Answers, Tricky Ques

0 97

Top 10 Frequently Asked Java Interview Questions

Top 10 Frequently Asked Java Interview QuestionsTo clear any exam/Interview it’s important to have the idea of the nature of questions you may encounter. Actually it is a strategy to clear any Interview with ease. So here we’ve come up with the Top 10 Frequently Asked Java Interview Questions that are mostly asked by recruiters. Before facing java technical interview you must go through these java tricky questions along with their answers to crack the interview. The most happened fact with interviewee is that they are unable to recognize the question and hence answer it in a wrong way. If you don’t want to face this issue, than go through this page. The below listed frequently asked java interview questions for experienced as well as fresher, will give you an idea of the type of questions you may face during your Interview. Have a look!!

Top 10 Frequently Asked Java Interview Questions

#1. What is difference between Executor.submit() and Executer.execute() method ?

There is a distinction while gazing exception handling. If your tasks throws an exception and if it was absolutely submitted with execute then this exception can attend the uncaught exception handler (when you do not have provided one expressly, the default one can simply print the stack trace to System.err).

If you submitted the task with submit any thrown exception, checked exception or not, is then a part of the task’s come back standing. For a task that was submitted with submit which terminates with an exception, the Future.get can re-throw this exception, wrapped in an ExecutionException

Must Check: Top 10 Programming Languages

#2. When is the super keyword used?

Super keyword is used to refer:

  • immediate parent class constructor,
  • immediate parent class variable,
  • immediate parent class method.

#3. JMM semantics for Volatile fields

Read & write to volatile variables have same memory linguistics as that of effort and cathartic a monitor victimization synchronal code block that the visibility of volatile field is secure by the JMM. Furthermore after Java one.5, volatile reads and writes don’t seem to be reorderable with the other memory operations (volatile and non-volatile both). So once Thread A writes to a volatile variable V, and after Thread B reads from variable V, any variable values that were visible to A at the time V was written will surely be visible to B.

Using the following code you’ll be able to understand this more clearly:

Data data = null;

volatile boolean flag = false;

Thread A


data = new Data();

flag = true;  <– writing to volatile will flush data as well as flag to main memory

Thread B


if(flag==true){ <– as=”” barrier=”” data.=”” flag=”” font=”” for=”” from=”” perform=”” read=”” reading=”” volatile=”” well=”” will=””>

use data;  <!— data is guaranteed to visible even though it is not declared volatile because of the JMM semantics of volatile flag.


Check Out Here List Of: Top 10 Best Backup Software For PC 2017

#4. What is the difference between StringBuffer and String?

String is changeless category class, i.e. you’ll not be able to modify its content once created. Whereas StringBuffer could be a changeable category, suggests that you’ll be able to modification its content later. Whenever we have a tendency to alter content of String object, it creates a replacement string and confer with that, it doesn’t modify the prevailing one. This is often the fact that the performance with StringBuffer is best than with String.

#5. What is the issue with following implementation of compareTo() method in Java?

public int compareTo(Object o)


Employee emp = (Employee) emp;

 return –;


 #6. Why multiple inheritance is not supported in java?

Java supports multiple inheritance however not through categories, it supports solely through its interfaces. The rationale for not supporting multiple inheritance is to avoid the conflict and complexness arises because of it and keep Java a straightforward Object homeward Language. If we tend to recall this in C++, there’s a special case of multiple inheritance (diamond problem) wherever you’ve got a multiple inheritance with 2 categories that have strategies in conflicts. So, Java developers set to avoid such conflicts and didn’t enable multiple inheritance through categories in any respect.

Must Hit: 20 Best Google Chrome Extensions that Must Install Now

#7. Explain Final keyword in java?

Final keyword in java is used to restrict usage of variable, class and method.

  • Variable: Value of Final variable is constant, you can not change it.
  • Method: you can’t override a Final method.
  • Class: you can’t inherit from Final class.

#8. What is the difference between ‘throw’ and ‘throws’ in Java Exception Handling?

To know thw difference between two read the below given details:

Throw keyword is used to throw Exception from any method or static block whereas throws is used to indicate that which Exception can possibly be thrown by this method. If any method throws checked Exception, then caller can either handle this exception(using try catch block )or can re throw it by declaring another ‘throws’ clause in method declaration.

For Example:


  • throw new Exception(“You have some exception”)
  • throw new IOException(“Connection failed!!”)


  • throws IOException, NullPointerException, ArithmeticException

#9. What will happen if you put System.exit(0) on try or catch block? Will finally block execute?

By calling System.exit(0) in attempt or catch block, we are able to skip the finally block. System.exit(int) methodology will throw a SecurityException. If Sysytem.exit(0) exits the JVM while not throwing that exception then finally block won’t execute. But, if System.exit(0) will throw security exception then finally block will execute.

Check Now: 7 Best Microsoft Office Alternatives for 2017

 #10. What is the issue with following implementation of compareTo() method in Java

public int compareTo(Object o){

   Employee emp = (Employee) o;

   return –;


where an id is an integer number?

There is nothing wrong during this Java question till you guarantee that id is often positive. This Java question becomes difficult once you cannot guarantee that id is positive or negative. The difficult half is, If ID becomes negative than subtraction could overflow and manufacture an incorrect result.

Hope now you must have got an idea of which type of question are asked in Java Interviews, by reading the above given Top 10 Frequently Asked Java Interview Questions. We’ll keep adding more new questions on this page only, so bookmark this page by pressing Ctrl + D.

You Can Also Check This Section:

Ten Best Operating Systems6 Best Google Chrome Extensions
The 10 Best External Hard DrivesComputer Accessories Online Shopping Sites


Leave a Reply