Please navigate to the bottom of the page for Table of Contents

Saturday, June 18, 2011

Basic JAVA interview questions

Having covered a lot of topics in .NET, let’s shift our attention to some JAVA questions. In this post, we will cover a few basic JAVA interview questions to get started. We will advance in complexity in later posts.

SO, first, let’s start with constructors.

Question: What is the difference between constructors and other regular methods?

Constructors must have the same name as the class name and cannot return a value. The constructors are called only once per creation of an object while regular methods can be called many times.

Question: What happens if you do not provide a constructor?

Java does not actually require an explicit constructor in the class description. If you do not include a constructor, the Java compiler will create a default constructor in the byte code with an empty argument. If a class includes one or more explicit constructors, the java compiler does not create the default constructor.

Question: Can you call one constructor from another?

Yes, the key is to use the this() construct.

public Shape(int id) { = id; // "this" means this object

public Shape(int id, String type) {
this(id); // calls constructor public Shape(int id)
this.type = type; // "this" means this object

Question: How can you invoke the base class constructor in the derived class?

You can use the super() syntax. Note that this has to be the first statement in the function.

public Circle(int id) {
super(id); //must be the very first statement in the constructor.

Question: How can you invoke base class methods in the derived class?

To call a regular method in the base class use “super.myMethod( )”. This can be called at any line.

public class Circle extends Shape 
public void setUp()
// do circle stuff

public void reset() throws Throwable
// Do stuff here to rest your object
catch (Throwable t) {}
super.reset(); //clean up your parent class. Unlike constructors super.regularMethod() can be called at any line.

Question: Explain static initializers with an example.

When a class is loaded, all blocks that are declared static and don’t have function name (i.e. static initializers) are executed even before the constructors are executed. As the name suggests they are typically used to initialize static fields.

public class StaticInitializer 
public static final int x = 5;
public static final int y;
//note that since y is final, it can be initialized only once.

//Static initializer block, which is executed only once when the class is loaded.
if(x == 5)
y = 10;
y = 5;

//constructor is called only after static initializer block
public StaticInitializer(){}

The code above sets the value of x to 5 and y to 10.


  1. Given stuff and logical thinking are very good!

  2. When coming to the java point there will be definitely asking the Questions
    on the constructors!So i hope this is the good introduction for the java questions!

  3. ya this is very very important to the interview, because constructors are the base for the objects creation....

  4. This comment has been removed by a blog administrator.

  5. Write a program where the user enters the number of asterisk for the first row printed. The user will then enter another number (that is less than the number entered first). This number will be the number that each row will be decreased by. For example: User will enter 8 first and 3 second (row 1 - 8 asterisks, row 2 - 5 asterisks, row 3 - 2 asterisks. What will be printed is:

    You can't print less asterisks than the decrement value (in the example you can't go below 2 because 3 was the decrement number).

    1. This is quite simple:
      static void PrintStars(int startCount, int decrementValue)
      // error checks
      if ((startCount > 0) && (startCount >= decrementValue))
      while (startCount >= 0)
      // print current star count
      Console.WriteLine(new String('*', startCount));

      // decrement for next round
      startCount -= decrementValue;
      Console.WriteLine("Please provide valid input values");

    2. Sain Bainuu,

      Thank you! Thank you! Thank you! Your blog was a total game changer!

      Hello people, So I am having trouble uploading a file to my bucket. I have the proper credentials all set. The problem is when I try doing a
      putRequest('bucket', 'keyName', 'fileFullPath') it will only save the file name and not the bytes. So I try sending it as an input stream to a byte array. This way it says there is no such file at specified location? I am running linux so It says no specified file at /home/{user}/pictures/example.jpg This is the problem I believe because it is searching from /home and not /

      It was cool to see your article pop up in my google search for the process yesterday. Great Guide.
      Keep up the good work!

      Thanks a heaps,

    3. Hola,

      What a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this.

      I have two methods and they do almost same thing, but at some most inner nested level one of method have additional command.

      Java Code:
      ... same code ...
      for {
      ... same code ...
      ... same code ...

      Follow my new blog if you interested in just tag along me

      in any
      social media platforms!


  6. Copper Wire Co. sells spools of copper wiring for $100 each. Write a program that display the status of an order. The program should have a function that asks for the following information:

    The number of spools ordered.
    The number of spools in stock.
    If there are special shipping and handling charges.

    (Shipping and handling is normally $10 per spool.) If there are special charges, it should ask for the special chargers per spool.

    Output: number of spools shipped, number of spools back ordered, subtotal of portion ready to ship, total shipping and handling charges on portion ready to ship, total of order ready to ship.

    Validate: do not accept numbers less than one for spools ordered. Do not accept a number less than 0 for spools in stock or shipping and handling charges.

    Once an order is printed, ask the user for the next order. Use a sentinel value to stop (q for quit or -1)

  7. very nice. for java examples, visit site

  8. I came across your guide and found exact Basic-java Interview Q/A’s which I was looking for. Thanks for such a useful information’s. But I had found one good website related to Java interview Q/A’s. More Info: java-interview-questions


  9. The share your really gives us excitement. Thanks for your sharing. If you feel tired at work or study try to participate in our games to bring the most exciting feeling. Thank you!
    hotmail sign in | red ball game |

  10. Looking for best selenium training in Chennai, Credo Systemz is the no 1 selenium Training institute in Chennai offering professional selenium course by selenium experts.

  11. I will do niche blog comment Just in 5$ .All comment relevant with your niche and UNIQUE .This off-page seo will increase your traffic and promote your business

  12. Your good knowledge and kindness in playing with all the pieces were
    very useful. I don’t know what I would have done if I had not
    encountered such a step like this.

    java Training in Bangalore

    java training in chennai

  13. Thanks for sharing such agreat article, really very helpful information. Keep sharing.

    Best Software company in New jersey, USA


  14. wow...nice blog, very help full information. Thanks for sharing.


  15. Grate blog to read its very nice explanation about Internet Of Things
    Internet Of Things

  16. Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles.
    Best Cloud Solutions | Austere Technologies

  17. Great article, really very helpful content you made. Thank you, keep sharing.

    Best IT Security Services | Austere Technologies

  18. Really great blog, it's very helpful and has great knowledgeable information. Thanks for sharing, keep updating such a good informative blog.

    Quality Managment Services | Austere Technologies

  19. Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles
    Austere Technologies|Mobility

  20. Good one.I appreciate you for sharing this knowledge.Thank you so much for the examples.Its very helpful for me and newbies.I learned much .Have a look on yii2 development company,

  21. Excellent information you made in this blog, very helpful information. Thanks for sharing.

    Best chartered accountant courses| Avinash college of commerce

  22. Great article, really very helpful content you made. Thank you, keep sharing.

    Best Software Testing Services | Austere Technology

  23. I must be thankful for sharing your ideas.Thank you for the good writeup.its a brellint job
    java training in chennai
    java course in chennai

  24. Thanks for sharing this informative article..!!
    Keep posting waiting for next post.

    iOS Training in Bangalore Java Training in Bangalore

  25. Hi Thanks for the nice information its very useful to read your blog. We provide Software Development Services

  26. The blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.

    Digital Marketing Course in Chennai
    Digital Marketing Training in Chennai
    Online Digital Marketing Training
    SEO Training in Chennai

  27. Wow...Excellent informative blog, really helpful. Thank you.

    Best CAM Training in hyd | ISFS

  28. Very useful information Big Classes has been constantly pioneering and evolving in the Online Training Industry. With an experience of over a decade and half in the training industry, Big Classes is today a name to be reckoned with for any kind of IT trainings in online model. With an army of trainers and a wide array of courses, Big Classes guarantees high quality training at an extremely competitive price, ensuring 100% value for money.
    Online IT Training

  29. Excellent informative blog. Keep sharing, thank you.

    cpa courses in hyderabad | ISFS

  30. Your article gives lots of information to me. Thanks for sharing.
    acca course in hyderabad | ISFS

  31. I like your blog, I read this blog please update more content on hacking,
    Nice post,and good information Thanks for sharing further check it once at
    .NET Online Course

  32. Wow...What an excellent informative blog, really helpful. Thank you. Best Oracle DBA Course Training| orskl

  33. Thank you for the information, i found the information very useful.
    If anyone looking for Java training in Bangalore i suggest Apponix Technologies, they provide best Java training. For more information visit :

  34. Wow...What an excellent informative blog, really helpful. Thank you. Best Oracle DBA Course Training| orskl

  35. It was thinking about whether I could utilize this review on my other site, I will connect it back to your site though.Great Thanks. basic English vocabulary

  36. Wow...What an excellent informative blog, really helpful. Thank you. Best Oracle DBA Course Training| orskl

  37. Comfortabl y, the post is really the freshest on that deserving topic. I harmonise with your conclusions and definitely will thirstily look forward to your next updates.

    website builder for reseller

  38. Thank you for the link building list.I am going jot down this because it will help me a lot.Great blog! Please keep on posting such blog.

    private label website builder

  39. Comfortabl y, the post is really the freshest on that deserving topic. I harmonise with your conclusions and definitely will thirstily look forward to your next updates.

    white label website builder

  40. I admire this article for the well-researched content and excellent wording
    seo company in chennai

  41. The information is meaningful and magnificent which is shared here about the article. I really thank you for such a innovative post. if you want to take training in java, then is best for you. Summer internship program in jaipur

  42. Next time I read a blog, Hopefully it won't fail me as much as this one. I mean, I know it was my choice to read, but I truly thought you would have something interesting to say. All I hear is a bunch of complaining about something that you could possibly fix if you weren't too busy seeking attention.
    best service center in marathahalli

    Samsung Galaxy S9+ authorized service center near me

    oppo A77 service center near me

    oneplus 5T authorized service center in banglore

    realme 2 Pro authorized service center in banglore

  43. This comment has been removed by the author.

  44. It's a nice article, Which you have shared here about the java. Your article is very useful for those who are want to learn java programming course. I would like to thanks for sharing this post here. Best Core Java With Data Structures Course In Delhi

  45. For Devops training in Bangalore visit:Devops training in Bangalore

  46. For IOT Training in Bangalore Visit:
    IOT Training in Bangalore

  47. Excellent web site you have got here.. It’s difficult to find good quality writing like yours these days.
    best service center bangalore
    I really appreciate individuals like you! Take care!!
    Vivo display replacement Marathahalli
    This is a topic that's near to my heart... Cheers! Exactly where are your contact details though?
    Motorola display replacement Marathahalli

  48. I seriously love your site.. Great colors & theme. Did you develop this website yourself?
    Huawei display replacement Marathahalli
    Please reply back as I’m looking to create my own website and would like to learn where you got this from or what the theme is named. Kudos!
    Asus display replacement Marathahalli
    Everyone loves it whenever people get together and share ideas. Great website, stick with it!
    LG display replacement Marathahalli

  49. Looking for CDR Report Writing who can provide the best quality CDR report writing help service to engineers, visit at We will help you to get A+ Grades in CDR report.
    cdr report writing

  50. Great blog thanks for sharing Your website is the portal to your brand identity. The look and feel of every page carry a strong message. This is why your brand needs the best web design company in chennai to capture your visions and make it art. Adhuntt Media is graced with the most creative design team in Chennai.
    digital marketing company in chennai

  51. Nice blog thanks for sharing Evolve past boring simple rooftops and bling them up by converting your upstairs to a terrace garden. Interested? Get your very own at Karuna Nursery Gardens - the best terrace garden service in Chennai.
    plant nursery in chennai

  52. Excellent blog thanks for sharing It’s time you upgraded your Salon to meet global standards. Do that with the best wholesale cosmetic market in Chennai - The Pixies Beauty Shop.
    Cosmetics Shop in Chennai

  53. Great Article. Thank you for sharing! Really an awesome post for every one.

    IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

  54. The article explains value of Java and it is role inside Information Technology sector. It highlights the key role that Java plays in creating Online Advanced JAVA Training

  55. Very useful blog thanks for sharing IndPac India the German technology Packaging and sealing machines in India is the leading manufacturer and exporter of Packing Machines in India.

  56. This comment has been removed by the author.

  57. Effective blog with a lot of information. I just Shared you the link below for Courses .They really provide good level of training and Placement,I just Had Java Classes in this institute,Just Check This Link You can get it more information about the Java course.

    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

  58. Very useful blog. excellent Information . Thank you . keep sharing
    Best BBA College in Hyderabad

  59. This comment has been removed by the author.

  60. Thanks a lot for sharing such a good source with all, i appreciate your efforts taken for the same. I found this worth sharing and must share this with all.

    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery

  61. IEEE Cloud computing DOamin is a general term for anything that involves delivering hosted services over the Internet. cloud computing projects The cloud projects for cse is a metaphor for a global network of remote servers which operates as a single ecosystem, commonly associated with the Internet. IEEE FInal Year Networking Projects for CSE Domains Networking Projects cloud computing is the delivery of computing projects services—including servers, storage, databases, networking projects, software, analytics, and intelligence

    JavaScript Training in Chennai

    JavaScript Training in Chennai

  62. ethical hacking is the upcoming, valuable and job oriented solution that IT companies and other industrial sectors are adapting today. machine learning courses in hyderabad

  63. After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.
    Ethical Hacking Course in Bangalore
    Certified Ethical Hacker Course

  64. Wow! Such an amazing and helpful post this is. I really really love it. I hope that you continue to do your work like this in the future also.
    Ethical Hacking Training in Bangalore
    Ethical Hacking Training

  65. The blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much. i appreciate your efforts taken for the same. I found this worth sharing and must share this with all.

    digital marketing company in bhubaneswar
    website design and development

  66. Thumbs up guys your doing a really good job. It is the intent to provide valuable information and best practices, including an understanding of the regulatory process.
    Cyber Security Course in Bangalore

  67. I am so happy to found your blog post because it's really very informative. Please keep writing this kind of blogs and I regularly visit this blog. Have a look at my services.
    Cyber Security Training Course in Chennai | Certification | Cyber Security Online Training Course | Ethical Hacking Training Course in Chennai | Certification | Ethical Hacking Online Training Course | CCNA Training Course in Chennai | Certification | CCNA Online Training Course | RPA Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course Chennai | SEO Training in Chennai | Certification | SEO Online Training Course

  68. Nice article i was really impressed by seeing this article, it was very interesting and it is very useful for me.It was very interesting and meaningful.I gained many unknown information, the way you have clearly explained is really fantastic.keep posting such useful information.
    Full Stack Training in Chennai | Certification | Online Training Course
    Full Stack Training in Bangalore | Certification | Online Training Course

    Full Stack Training in Hyderabad | Certification | Online Training Course
    Full Stack Developer Training in Chennai | Mean Stack Developer Training in Chennai
    Full Stack Training

    Full Stack Online Training

  69. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us.This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    DevOps Training in Chennai

    DevOps Online Training in Chennai

    DevOps Training in Bangalore

    DevOps Training in Hyderabad

    DevOps Training in Coimbatore

    DevOps Training

    DevOps Online Training

  70. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    Artificial Intelligence Training in Chennai

    Ai Training in Chennai

    Artificial Intelligence training in Bangalore

    Ai Training in Bangalore

    Artificial Intelligence Training in Hyderabad | Certification | ai training in hyderabad

    Artificial Intelligence Online Training

    Ai Online Training

    Blue Prism Training in Chennai

  71. Your site is amazing and your blogs are informative and knowledgeable to my websites.This is one of the best tips in my life. I have in quite some time.
    PHP Training in Chennai

    PHP Online Training in Chennai

    Machine Learning Training in Chennai

    iOT Training in Chennai

    Blockchain Training in Chennai

    Open Stack Training in Chennai

  72. 1. PHP VS Java: Performance & Speed. In a nutshell: While comparing the Java vs PHP performance, Java is clearly a winner as it is faster and efficient than PHP to write enterprise applications. Like developers have to build mobile enterprise applications to streamline complex business processes and operation
    Java Training in Chennai

    Java Training in Bangalore

    Java Training in Hyderabad

    Java Training in Coimbatore

    Java Training

  73. Good post and informative. Thank you very much for sharing this good article, it was so good to read and useful to improve my knowledge as updated, keep blogging.Thank you for sharing wonderful information with us to get some idea about that content.
    oracle training in chennai

    oracle training institute in chennai

    oracle training in bangalore

    oracle training in hyderabad

    oracle training

    oracle online training

    hadoop training in chennai

    hadoop training in bangalore