Java Interview Questions



The best way to prepare for interview questions is to close your eyes and imagine the questions being asked by the interviewrs. And then imagine the answer that you will be giving.

You not only have to answer the questions, but you also need to answer in a way that impresses the interviewers. We have compiled a set of real life interview questions.

Try to answer these questions yourself and see if you can make it better than the one presented here. The answers here are not the best ones but it is required that you have at least the basic answer ready.

Even if you are a seasoned Java programmer, you need to refresh your basics to be able to present your thoughts in a coherent fashion. If you are a beginner or a fresher you need to keep continuig practice real life problems besides going through these questions.

Explain difference between private, protected, and public keywords?

The keywords in the three cases differ in their ability to allow privileges to classes and methods.

Public kwywords are accessible to all classes
Private keywords are accessible only to the class to which they belong
Protected keywords accessible to the class to which they belong and any subclasses.
Other Sources : http://www.freejavaguide.com/java-interview-questions.html

  1. /*
  2.   ReferenceDesigner.com Tutorial for beginners
  3.   Arithmetic operators
  4.  */
  5. class arithmetic{
  6.  
  7. public static void main (String args[]) {
  8. int x = 50;
  9. int y = 25;
  10. int z1,z2,z3,z4,z5;
  11. z1 = x + y;
  12. z2 = x - y;
  13. z3 = x * y;
  14. z4 = x/y;
  15. z5 = x%y;
  16. System.out.println("The value of x + y is " + z1);
  17. System.out.println("The value of x - y is " + z2);
  18. System.out.println("The value of x * y is " + z3);
  19. System.out.println("The value of x / y is " + z4);
  20. System.out.println("The value of x % y is " + z5);
  21.  
  22. }
  23.  
  24. }


If you compile and run this program, you will get the output as follows


C:\Program Files\Java\jdk1.7.0_17\bin>java arithmetic
The value of x + y is  75
The value of x - y is  25
The value of x * y is  1250
The value of x / y is  2
The value of x % y is  0