Frequently asked interview questions on Java programming

It is very important to prepare for the interview questions that employer might ask you. Since java is the hot topic for all programmers, which is why, I thought of writing about commonly asked interview questions. These questions are easy yet tricky sometimes,because of which employer expect you to answer them without hesitation. So let’s start –

15 Interview questions on Java language.

1. Is java pure Object Oriented language or not?

Java is not pure Object-Oriented because everything in Java is not an object. For example- All primitive data types (char, boolean, byte, short, int, long, float, double) are not objects because we can not do any object-like operations on them. Hence, we can not call java a pure object oriented language.

2.  Which class is the superclass of all classes in Java?

java.lang.Object is the super class for all the java classes and we do not need to extend it.

3.  What is the importance of main method in Java?

main() method is the entry point of java program. And the syntax of main method is as given below:

public static void main(String args[]).

4.  What is overloading and overriding in java?

When more than one method with the same name in a single class but the arguments are different, then it is called as method overloading.

On the other hand, when two methods are there with same signature, one in parent class and another in child class, this is called overriding in java.

5.  Can we overload main method?

Yes, we can. We can create multiple methods with name “main” in a single class. However, if we run the class, java runtime environment will look for main method with syntax as public static void main(String args[]).

6.  What are access modifiers?

Java provides access control through public, private and protected access modifier keywords. When none of these are used, it’s called default access modifier.

To read more: Access modifier

java interview

 

 

 

 

 

 

 

7.  Is Empty .java file name a valid source file name?

Yes, It’s valid. You can save your java program by .java only, and this is how you can do it.

Compile: javac .java

Run: java your class name

Let’s take a simple example:

//save by .java only

class A{

public static void main(String args[]){

System.out.println(“Hello java”);

}

}

//compile by javac .java

//run by     java A

8.  What is constructor?

It is a special type of method that is used to initialize the object. Also Java constructor is invoked at the time of object creation.

9.  What is marker interface? 

An interface which has no data member and method is called as a marker interface for ex. Serializable, Cloneable etc.

10.             What is finally block?

Finally block is a block which is executed every time no matter what. For more details on finally block click here – more details.

11.             Difference between Swing and AWT?

AWT are heavy-weight components but Swings are lightweight components. Dueto which swing works faster than AWT.

12.             What is the difference between Vector and ArrayList in Java?

ArrayList is not synchronized however the Vector is. Due to which, ArrayList is faster because it is non-synchronized.

13.             What’s the difference between a queue and a stack?

Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule.

14.              What is servlet collaboration?

When there is communication between one servlet to another servlet, known as servlet collaboration. There are many ways of servlet collaboration such as:

  • RequestDispacher interface
  • sendRedirect() method etc.

more details…

15.             Can you call a jsp from the servlet?

Also one of the way is RequestDispatcher interface for example:

  1. RequestDispatcher rd=request.getRequestDispatcher(“/login.jsp”);
  2. forward(request,response);

more details…

Hope this information was helpful. Comment below for explanation on any particular question. Happy programming.

86 thoughts on “Frequently asked interview questions on Java programming

    1. Great question. This can be done using eclipse in java, also there is a script which can run using javascript as well.
      This is a simple program for that-

      import java.util.Scanner;

      public class seat_reservation{

      public static void main(String[] args) {

      // Initialization
      final int ROWS = 2;
      final int COLS =3;
      char [][] seats = new char [ROWS][COLS];
      int i, j, seatNum, counter=0;
      char seatLetter = ‘A’;
      int choice=0;
      String seatEnter;
      boolean cont = true; // loops of running the program

      Scanner input = new Scanner(System.in);// declare and create variable input as scanner

      while(choice!=4){
      System.out.print(“1. Assign Seats”);
      System.out.print(“2. Exit”);
      System.out.print(“Select your choice: “);

      choice=input.nextInt();

      switch(choice){
      case 1:
      }
      //Set the value.
      for (i=0; i < seats.length; i++) { for (j=0; j < seats[i].length; j++) seats[i][j] = seatLetter++; seatLetter = 'A'; // to reset the value to A for the new loop } //To display the list of seats for (i=0; i < seats.length; i++) { System.out.print((i+1)+" "); for (j=0; j < seats[i].length; j++) System.out.print(seats[i][j]+" "); System.out.println(); } //condition while (counter < 6 && cont) { do{ System.out.print("Please type the chosen seat(starts with row and column,e.g:2A):" + ""); seatEnter = (input.nextLine()).toUpperCase(); //covert to Upper case seatNum = Integer.parseInt(seatEnter.charAt(0)+""); if (seatNum != 0) seatLetter = seatEnter.charAt(1); i++; //if user enters wrong input, error message will appear. if (seatLetter!='A'){ if (seatLetter!='B'){ if(seatLetter!='C'){ if(seatLetter!='D') System.out.println ("Invalid! Please enter the correct seat:"); } } } } //continue to loop until the condition true while (seatNum < 0 || seatNum > 7 || seatLetter < 'A' || seatLetter > ‘D’);

      if (seatNum == 0) {
      cont = false;
      }
      else {
      if (seats[seatNum-1][seatLetter-65] == ‘X’)
      System.out.println(“Seat have been taken.Please choose another seat:”);
      else {
      seats[seatNum -1][seatLetter-65] = ‘X’;
      counter++;

      }

      // To display updated lists of seats
      for (i=0; i < seats.length; i++) { System.out.print((i+1)+" "); for (j=0; j < seats[i].length; j++) System.out.print(seats[i][j] + " "); System.out.println(); } System.out.println(" ") ; //} //} // displays fully booked message // if (counter == 6) // System.out.println("All seats are now fully-booked."); break; case 2: if (counter == 6) System.out.println("All seats are now fully-booked."); System.out.println("End of Program"); System.exit(0); break; default: System.out.println("Error input"); break; } }

  1. You’ve probably seen a lot lately about Bitcoin…including speculation that it may drop in the future. There are thousands of new crypto-millionaires… But will people continue to get rich investing in cryptocurrency? Follow the link below to read the full report and find out what the future has in store…… AND how you can profit in the months and years to come. Find out more here: Best regards

  2. Mannabase a new Cryptocurrency is actually giving away FREE coins every week to new users. The best part is they are a Humanitarian organisation set to be bigger than Bitcoin. This could be the Biggest Free Investment you ever make. If you have 5 Minutes spare read the Whitepaper these Guys are something else.

  3. The strategies stated in this paragraph regarding to increase traffic at you own blog are actually nice, thanks for such good paragraph.

  4. Your style is very unique compared to other people I’ve read stuff from.
    I appreciate you for posting when you have the opportunity, Guess I’ll
    just bookmark this site.

    1. Hi,

      Thank you so much for writing in. We are glad that you find the content unique and useful. Really appreciate your effort to acknowledge our work.

      I would also like to take this opportunity to tell you about our official YouTube channel for such amazing content. Do subscribe and hit the bell icon to turn the notifications on – https://www.youtube.com/channel/UCcWR1IezEQynJnAETgK8g2w?sub_confirmation=1

      Follow us on Facebook page – https://www.facebook.com/pristinetechschool

      Happy learning.

      Regards,
      Pristine Tech School Team

  5. I am actually pleased to glance at this webpage posts which
    contains plenty of valuable information, thanks for providing these statistics.

    1. Hi,

      Thank you so much for writing in. We are glad that you find the content unique and useful. Really appreciate your effort to acknowledge our work.

      I would also like to take this opportunity to tell you about our official YouTube channel for such amazing content. Do subscribe and hit the bell icon to turn the notifications on – https://www.youtube.com/channel/UCcWR1IezEQynJnAETgK8g2w?sub_confirmation=1

      Follow us on Facebook page – https://www.facebook.com/pristinetechschool

      Happy learning.

      Regards,
      Pristine Tech School Team

    1. Hi,

      Thank you so much for writing in. We are glad that you found what you were looking for.

      I would also like to take this opportunity to tell you about our official YouTube channel for such amazing content. Do subscribe and hit the bell icon to turn the notifications on – https://www.youtube.com/channel/UCcWR1IezEQynJnAETgK8g2w?sub_confirmation=1

      Follow us on Facebook page – https://www.facebook.com/pristinetechschool

      Happy learning.

      Regards,
      Pristine Tech School Team

  6. This web site definitely has all of the information and facts I wanted concerning this subject and didn’t know who
    to ask.

    1. Hi,

      Thank you so much for writing in. We are really glad that you got the answers to the questions that you were looking for.

      I would also like to take this opportunity to tell you about our official YouTube channel for such amazing content. Do subscribe and hit the bell icon to turn the notifications on – https://www.youtube.com/channel/UCcWR1IezEQynJnAETgK8g2w?sub_confirmation=1

      Follow us on Facebook page – https://www.facebook.com/pristinetechschool

      Happy learning.

      Regards,
      Pristine Tech School Team

  7. I am sure this piece of writing has touched all the internet
    viewers, its really really good piece of writing on building up new blog.

    1. Hi,

      Thank you so much for writing in. We are glad that you find the content unique and useful. Really appreciate your effort to acknowledge our work.

      I would also like to take this opportunity to tell you about our official YouTube channel for such amazing content. Do subscribe and hit the bell icon to turn the notifications on – https://www.youtube.com/channel/UCcWR1IezEQynJnAETgK8g2w?sub_confirmation=1

      Follow us on Facebook page – https://www.facebook.com/pristinetechschool

      Happy learning.

      Regards,
      Pristine Tech School Team

  8. Way cool! Some extremely valid points! I appreciate you writing this post and the rest of the website is also
    really good.

  9. What i don’t realize is actually how you are no longer
    really a lot more well-preferred than you may be now. You are so intelligent.
    You know therefore significantly in the case of this subject,
    produced me in my view consider it from a lot of numerous
    angles. Its like men and women aren’t fascinated until it’s
    one thing to do with Woman gaga! Your individual stuffs
    outstanding. All the time take care of it up!

  10. Greetings from Ohio! I’m bored at work so I decided to browse your blog
    on my iphone during lunch break. I really like the information you provide here and can’t wait to take a look when I get
    home. I’m surprised at how quick your blog loaded on my mobile
    .. I’m not even using WIFI, just 3G .. Anyways, good site!

  11. We’re a bunch of volunteers and starting a brand new scheme in our community.
    Your site provided us with useful info to work on. You have performed an impressive task and our entire community
    will be thankful to you.

  12. I really can’t believe how great this site is. Keep up the good work. I’m going to tell all my friends about this place.

  13. This site looks better and better every time I visit it. What have you done with this place to make it so amazing?!

  14. That sure is one pretty site you have there. Can I ask you a very simple question? What kind of fertilizer do you use to make it grow so wonderfully?

  15. For newest information you have to go to see world wide web and on the web I found this web page as
    a most excellent web page for latest updates.

  16. I enjoy, lead to I discovered just what I used to be
    taking a look for. You’ve ended my four day long hunt! God
    Bless you man. Have a nice day. Bye

  17. I every time spent my half an hour to read this weblog’s articles or reviews all the time along with a cup of coffee.

  18. I think that everything said was very logical. But, think about this, suppose you added a little content? I am not suggesting your content is not good, but suppose you added a post title to possibly grab a person’s attention? I mean is kinda plain. You should glance at Yahoo’s front page and note how they create article titles to get viewers interested. You might try adding a video or a pic or two to get readers excited about what you’ve got to say. Just my opinion, it would bring your posts a little livelier.

  19. Hmm it looks like your site ate my first comment
    (it was super long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly
    enjoying your blog. I as well am an aspiring blog writer but
    I’m still new to everything. Do you have any suggestions for first-time blog writers?
    I’d really appreciate it.

    1. Hey,

      Thanks for writing in.

      Well, as far as suggestions are concerned, SEO is very important. Lemme know if you want to know more.

      Thanks.

  20. I am truly delighted to glance at this web site posts which carries lots of helpful information, thanks for
    providing such statistics.

  21. Hey There. I found your blog using msn. This
    is a very well written article. I will make sure to bookmark it and come back to read more of your useful
    information. Thanks for the post. I’ll certainly return.

  22. I for all time emailed this web site post page to all my associates, since if like to read it then my friends will too.

  23. Greetings! Very helpful advice in this particular article!
    It is the little changes that make the most significant changes.
    Many thanks for sharing!

  24. I’ve been surfing online more than 3 hours today, yet I never found any interesting article like
    yours. It is pretty worth enough for me. In my opinion, if all
    webmasters and bloggers made good content as you did, the web
    will be much more useful than ever before.

  25. With havin so much written content do you ever run into any problems of plagorism or copyright infringement?
    My blog has a lot of completely unique content I’ve either written myself or outsourced
    but it appears a lot of it is popping it up all over the web without my agreement.

    Do you know any methods to help protect against content from being stolen?
    I’d certainly appreciate it.

  26. I absolutely love your blog and find many of your post’s to be just what I’m looking for.
    Do you offer guest writers to write content for you?
    I wouldn’t mind writing a post or elaborating on a lot of the subjects you write with regards to here.
    Again, awesome website!

  27. Definitely imagine that which you said. Your favorite reason appeared to be at the
    internet the easiest thing to take into account of.
    I say to you, I definitely get annoyed whilst other people consider worries that they plainly don’t
    recognise about. You controlled to hit the nail upon the highest as
    well as defined out the entire thing with no need side effect , folks can take a signal.
    Will likely be back to get more. Thanks

  28. Asking questions are in fact good thing if you are not understanding anything entirely, but this
    paragraph offers fastidious understanding yet.

  29. Hey there! Someone in my Facebook group shared this website with us so I came to look it over.
    I’m definitely loving the information. I’m bookmarking and
    will be tweeting this to my followers! Fantastic blog and outstanding design and style.

  30. Hi just wanted to give you a quick heads up and let you
    know a few of the images aren’t loading properly. I’m
    not sure why but I think its a linking issue. I’ve tried it in two different
    web browsers and both show the same results.

  31. I’m really impressed with your writing abilities and also with the structure
    for your weblog. Is that this a paid theme or did
    you modify it your self? Either way stay up the nice high quality writing, it’s rare
    to look a nice blog like this one today..

  32. Hi there, i read your blog from time to time and i
    own a similar one and i was just curious if you get a lot of spam remarks?
    If so how do you protect against it, any plugin or anything you can recommend?
    I get so much lately it’s driving me mad so any support is very much
    appreciated.

  33. I feel that is among the most vital info for me. And i am happy reading your article.

    However should observation on some general things, The site style
    is perfect, the articles is in reality nice : D.
    Good job, cheers

  34. I think everything typed was actually very logical. However, think on this, what
    if you wrote a catchier post title? I ain’t suggesting
    your content is not solid, but suppose you added a headline that makes people
    want more? I mean Frequently asked Java Interview questions –
    Solved is kinda plain. You ought to peek at Yahoo’s home page
    and see how they create article headlines to get people to
    click. You might add a related video or a related pic or two to grab readers interested about what you’ve written. Just my opinion, it would bring your blog a little
    livelier.

  35. You made some good points there. I checked on the web for additional information about the issue and found most people will
    go along with your views on this web site.

  36. Everything is very open with a clear clarification of the challenges.
    It was truly informative. Your site is extremely helpful.
    Thank you for sharing!

  37. Hi, Neat post. There is an issue together with your web site in web explorer, may test this?
    IE still is the marketplace chief and a good component
    of other folks will leave out your great writing because
    of this problem.

  38. After looking at a number of the blog posts on your web page,
    I seriously like your technique of blogging. I bookmarked it to
    my bookmark site list and will be checking back in the near future.

    Please visit my website as well and tell me how you feel.

  39. Undeniably believe that which you stated. Your favorite reason seemed to
    be on the net the simplest thing to be aware of. I say to you, I certainly get irked while people think
    about worries that they just do not know about.

    You managed to hit the nail upon the top and also
    defined out the whole thing without having side effect , people could take a signal.
    Will probably be back to get more. Thanks

  40. I all the time used to study piece of writing in news papers but now as I
    am a user of net therefore from now I am using net for articles, thanks to web.

  41. Wow, fantastic blog layout! How long have you been blogging for?
    you made blogging look easy. The overall look of
    your web site is magnificent, let alone the content!

  42. Hello are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and create my own.
    Do you require any html coding knowledge to make your own blog?
    Any help would be greatly appreciated!

  43. My brother suggested I might like this blog.
    He was totally right. This post actually made my day.
    You cann’t imagine simply how much time I had spent for this info!
    Thanks!

  44. Hey would you mind sharing which blog platform you’re using?
    I’m looking to start my own blog in the near future but I’m having a difficult time choosing
    between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and I’m looking
    for something unique. P.S Sorry for being off-topic but I had to ask!

  45. Howdy! This post could not be written any better!
    Going through this article reminds me of my previous roommate!
    He always kept preaching about this. I am going
    to forward this information to him. Fairly certain he’s going to have a great
    read. Thanks for sharing!

  46. I go to see each day a few web sites and websites to read posts, however this
    web site provides quality based posts.

  47. It’s not my first time to pay a quick visit this web site, i am
    visiting this site dailly and obtain nice data from here everyday.

  48. It’s in point of fact a nice and helpful piece of info.
    I am happy that you shared this helpful information with us.
    Please keep us up to date like this. Thank you for sharing.

  49. I am actually happy to read this web site posts which includes lots of useful data,
    thanks for providing these statistics.

  50. Somebody essentially help to make severely posts I
    might state. That is the first time I frequented your website page and thus far?
    I surprised with the analysis you made to create this particular put up amazing.
    Great job!

  51. I went over this web site and I believe you have a lot of great information, saved to bookmarks (:.

  52. Hello there, You’ve done an incredible job. I’ll
    definitely digg it and personally suggest to my friends. I am confident they will be benefited from this website.

  53. wonderful put up, very informative. I wonder why the opposite specialists of this sector do not notice this.
    You must continue your writing. I am confident, you have a huge readers’ base already!

  54. I have been absent for some time, but now I remember why I used to love this blog. Thank you, I will try and check back more frequently. How frequently do you update your website?

  55. Hey there! I just wish to give you a big thumbs up for your great information you have got here on this post. I am coming back to your blog for more soon.

  56. Howdy! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to get
    my blog to rank for some targeted keywords but I’m not seeing
    very good success. If you know of any please share.

    Thank you!

  57. It’s wonderful that you are getting thoughts from this
    piece of writing as well as from our argument made at this place.

  58. I simply want to tell you that I am all new to blogging and honestly loved this blog site. More than likely I’m want to bookmark your blog post . You definitely come with exceptional writings. Appreciate it for revealing your website page.

  59. I just want to mention I am just all new to blogging and seriously liked your web blog. Most likely I’m want to bookmark your blog . You surely come with incredible article content. Regards for sharing with us your web page.

  60. Greetings! Very helpful advice in this particular post!

    It’s the little changes that produce the largest changes. Many
    thanks for sharing!

  61. Hey there just wanted to give you a brief heads up and let you know a few of the images aren’t loading correctly.
    I’m not sure why but I think its a linking issue. I’ve tried it in two
    different web browsers and both show the same results.

Leave a Reply

Your email address will not be published. Required fields are marked *