Java Interview Questions - Concepts to Remember

Java Interview Questions - Concepts to Remember

Since last year as I became more active & started conducting frequent surveys among Java communities, I observed that there are different types of active learners:

-Beginners/College students who want to learn basics of Java

-Professionals who want to improve their Java skills

-Learners who are keen to practice more Java programs

But there is one query which is common among everyone - ‘Java Interview Questions’. In my previous LinkedIn post I curated list of top Java programs asked in technical interviews. In this blog I would be focusing on Java Interview questions which are asked to check the concepts and logical ability of the candidate. If your concepts for the below given questions are crystal clear, solving Java programs in real-time will never be a problem. Here it goes:

  1. Difference between various data types in Java.

The data types are broadly classified into two types - Primitive and Non-Primitive data types.

The primitive data types are inherently supported by programming languages whereas non-primitive data types are defined using the primitive ones.The below snapshot shows categorization of different data types in detail. Read further here

2. How to find factorial using recursion in Java?

class FactorialUsingRecursion

{

   public static void main(String s[])

   {

       System.out.println("Factorial of 5 is " + factorial(5) );

   }

   public static int factorial(int i)

   {

       if( i == 1 )   // LINE A

       {

           return 1;

       }   

       return i * factorial(i - 1); // LINE B

   }

}

Check the output and reasoning here ..

3. What is the difference between for, while and do-while loops?

  • While loop checks for the condition first. so it may not even enter into the loop, if the condition is false.
  • do while loop, execute the statements in the loop first before checks for the condition. At least one iteration takes places, even if the condition is false.
  • for loop is similar to while loop except that initialization statement, usually the counter variable initialization a statement that will be executed after each and every iteration in the loop, usually counter variable increment or decrements

Understand the difference, check out the programs here .

4. Explain various types of sorting on Arrays.

Bubble Sort, Insertion Sort and Selection Sort are few important types of arrays you must know. The algorithm for Bubble and Selection sort is given below:

Bubble Sort

  • compare 1st and 2nd elements
  • if 1st larger than 2nd, swap
  • compare 2nd and 3rd, and swap if necessary
  • continue until compare the last two elements
  • the largest element is now the last element in the array.
  • repeat starting from the beginning until no swaps are performed (i.e.,
  • the array is sorted)
  • each time you go through the elements bubbling up the largest element
  • no need to try the last i elements for the ith run since the end
  • elements are already sorted

Selection Sort

  • array to be sorted: A
  • array to be returned: B
  • find smallest element in A and put in B
  • mark space in A with null so it won’t be chosen again
  • repeat last two steps until B is sorted array

See example of How to use Bubble Sort?

5. Define Class Hierarchy.

The class hierarchy defines the inheritance relationships between classes. Refer the program to understand it better.

6. Explain Class Composition.

Refer the program here to understand it better.

7. Define Abstract Classes vs Interfaces and give their examples.

Read in detail here.

8. Exceptions - How does a try, catch, finally block work?

Exception causes abnormal termination of program and consume lot of resources compared to the normal code of execution. The difference between error and exception is explained in the diagram given below.

Please refer the program here.

9. Threads + I/O - File Copy from one directory to another using threads.

Thread groups are created to avoid confusion between various individual threads and help them identify better. The thread methods can be understood better here.

Hope this article was helpful for you. Please share your views in the comment section and for any further queries feel free to reach me at siva.nookala@meritcampus.com

Happy Learning!

Thanks sir, it's very helpful and It would be very great if u make more articles like this

Like
Reply

Can you please tell or describe clone

Like
Reply

To view or add a comment, sign in

More articles by Siva Nookala

  • Webinar: Quick Learning Tips for 'Best Programming Practices'

    On 25th April I conducted one hour webinar on 'Best Programming Practices'. You can check the recording here.

  • Bored of Developing Android Apps?

    Your bank of mobile apps in the smartphone has definitely made life easier and faster without any second doubt. But do…

    2 Comments
  • Technology Aimed to Change the Way We Learn

    In 2012 when Sreenivas and I had to invest over 2-3 months to just train new employees for our software company, we…

    2 Comments
  • The Top Programming Language to Learn in 2017 - Java. Why?

    Ever since I have started writing on Linkedin, my focus has been to aid prospecting programmers with better ways to…

    3 Comments
  • Top Java Programs asked in an Interview

    The placement season is almost a month away for most of you and I am sure there is enough hullabaloo around - what to…

  • Effective Programming for Real-Time Projects

    A typical client project starts with a set of requirements and thereafter never-ending additional demands which…

  • Play Framework - Modern and Scalable Web Framework

    When we were starting Merit Campus a few years back, we had to choose 'Ruby On Rails (RoR)' and ready made gems for…

    2 Comments
  • Online Platforms to Become Java Expert

    Over the years, I have been recommending online learning courses to everyone over traditional ways. This is not because…

    1 Comment
  • How to prepare for Java interview in less than 7 days?

    As an everyday ritual, I help people by answering lot of simple and complicated questions on quora, and the most common…

    1 Comment
  • Struggling to learn Java?

    Have you ever tried learning new foreign language? Or maybe we can also talk about learning new local language? If yes,…

    2 Comments

Others also viewed

Explore content categories