Basic core java interview questions and answers for freshers

 Part 4

Basic core java interview questions and answers for freshers covered in this post:


    Basic core java interview questions and answers for freshers

        What is the purpose of Arrays utility class?

    -        Array utility class contained in java.util.Arrays package.

    -       This class provides some utility methods for manipulating the arrays like sorting, searching, converting an array into a collection etc.


        What is Stack and what are the characteristics of Stack?

    -          Stack is a linear data structure.

    -          Stacks works with LIFO (Last In First Out).

    -          Stack is a child class of Vector.

    -    Real-Life example: We have observed many times in the cafeteria, Waiter always picks the top of the plate to serve the food to each customer.


     

    Click here to Purchase on AmazonClick here to Purchase on Amazon

    Click here to Purchase on Amazon

    Note: Please click on Image to Purchase the books from Amazon.in

        What are the characteristics of Hashset?

    -          Duplicate objects are not allowed.

    -          Insertion order not preserved.

    -          Based on Hashcode of Object.

    -          Only one null insertion is possible.

    -          Heterogeneous (Different types of Object) objects are allowed.

    -   HashSet is Serializable because HashSet implements a Serializable interface.

    -          HashSet is Clonable because HashSet implements a Clonable interface.

    -          HashSet has not implemented RandomAccess.

    -     Duplicate objects are not allowed and still, you are trying to add duplicate objects then you won’t get any compile-time or run-time exception just simply return false if the object is present and return true when the object is not presented.


        What are the characteristics of Queue Interface?

    -     Queue interface is used to hold the element about to be processed in FIFO(First In First Out).

    -       A Queue is a collection for holding elements prior to processing.

    -       Queue is a child interface of the Collection interface.

    -      Besides basic Collection operations, queues provide additional insertion, removal, and inspection operations.

    -        Please refer the queue interface and its method.

    public interface Queue<E> extends Collection<E> {

        E element();

        boolean offer(E e);

        E peek();

        E poll();

        E remove();

    }



        Which data structure has implemented LIFO strategy?

    -          Stack data structure has implemented LIFO (Last In First Out) strategy.

    -          Please refer to the below example.

    package simplifiedjava.crackedInterview; 

    import java.util.Stack; 

    public class StackDemo { 

          public static void main(String[] args) {

                Stack<Integer> s = new Stack<Integer>();

                s.push(10);

                s.push(20);

                s.push(30);

                System.out.println(s);

                s.pop();

                System.out.println(s);       

          }

    }

    Output:

    [10, 20, 30]

    [10, 20]

     

    -          Graphical representation of Stack implementation.



        Which data structure has implemented FIFO strategy?

    -    Queue data structure has implemented FIFO (First In First Out) strategy.

    -     Please refer to the below example.

    package simplifiedjava.crackedInterview; 

    import java.util.LinkedList;

    import java.util.Queue; 

    public class QueueDemo { 

          public static void main(String[] args) {

                Queue<Integer> queue = new LinkedList<Integer>();

                queue.offer(10);

                queue.offer(20);

                queue.offer(30);

                System.out.println(queue);

                queue.peek();

                System.out.println(queue);

                queue.poll();

                System.out.println(queue);

          }

    }

    Output:

    [10, 20, 30]

    [10, 20, 30]- Pick() just retrieved the value but not removed.

    [20, 30] – Poll() retrieved the value and removed as well.

     

     

    -          Graphical Representation of Queue.





        What is the difference between List and Set?

     

    List

    Set

    1.

    Duplicate elements are allowed in the list.

    Duplicates are strictly not allowed.

    2.

    Insertion order of elements are preserved.

    Insertion order of elements are not preserved.

    3.

    Implementation classes are as Follows.

            1.       ArrayList

            2.       LinkedList

            3.       Vector

            4.       Queue

    Implementation classes are as Follows.

            1.       HashSet

            2.       LinkedHashSet

            3.       TreeSet

            4.       Queue



        What is the class loader and what are the types of class loaders?

    -          ClassLoader loads the classes dynamically into memory whenever required by Java Runtime Environment.

    -          ClassLoader is an abstract class in Java Runtime Environment.

    -          There are three types of class loaders available in java.

    a.       BootStrap Class Loader :

    This is a parent loader of all existing loaders. Bootstrap loaders load all JDK files from jre/lib/rt.jar. 

    b.      Extension Class Loader :

    Extension class loader loads the extensions of java core classes from jre/lib/ext directory. Extension class loader is a child loader of Bootstrap class loader. 

    c.       System Class Loader :

    System class loader loads the application level classes. System class loader is a child loader of Extension class loader.


        Can I have multiple abstract methods in functional interface?

    -     No, we cannot have multiple abstract methods in the functional interface.

    -   If you declare multiple abstract methods inside an interface and an interface is not annotated with @FunctionalInterface then it will become a regular interface.

    -  If you declare multiple abstract methods inside an interface and an interface is annotated with @FunctionalInterface then it will give a compile-time error.

    -   If you declare only one abstract methods and multiple default and static method but not annotated with @FunctionalInterface then it is also functional interface.



        Can you create your own functional interface?

    -          Yes, we can create our functional interface.

    -          You have to just create normal interface.

    -  Create only one abstract method into it and annotated with @FunctionalInterface.


    • Java interview questions and answers all MNC - Click here
    • Basic core java interview questions and answers for freshers - Click here
    • Core java interview questions for 3 years experience - Click here
    • Core java interview questions and answers for 3-5 years exp - Click here
    • Core java interview questions and Answers for 5 - 7 Years exp - Click here
    • Basic Java Interview Questions and Answers - Click here
    • Java interview questions and answers on oops - Click here
    • Java interview questions and answers on Strings - Click here
    • Java interview questions on exception handling - Click here
    • Interview questions on multithreading in java for experienced - Click here
    • Interview questions on serialization in java for experienced - Click here

    • Interview questions on inner class in java for experienced - Click here
    • Interview questions on Collections in java for experienced - Click here


    Upcoming questions in next post:


    41. Can you declare constructor static, final, abstract and synchronized.

    42. Can we override or overload constructor.

    43. What is the difference between HashMap and TreeMap.

    44. What is the difference between JVM, JRE and JDK.

    45. Can we trigger the garbage collection from java code.

    46. What are the features introduced in java 8.

    47. In functional interface how many default methods can be declared.

    48. What is predicate functional interface.

    49. What is Stream.

    50. Can you call static method with method reference.


    Previous Post                                                                    Next Post



    Thank you techies for visiting this blog. I hope you enjoyed this blog and got more technical knowledge. I have tried to cover all types of questions and provided examples tested on eclipse as much as I can. Guys, please don’t just mug up the questions and answers. Try to clear your concepts with examples. Try to write a code on eclipse once you read the concepts. It will help you to memorize the concepts for a very long time. Simultaneously you will be prepared for interview programs as well. It will help you to survive in the IT sector for a long time. It may be easy to crack an interview but it's really tough to survive in the IT industry with inadequate knowledge and skills. 

    I have collected all the questions from actual interviews attended by my friends, colleagues, college mate and classmate. I have covered frequently asked questions as well as challenging questions. I have included many programs to understand the concept thoroughly. I will try to explain the concept with the help of a real-time program in eclipse. 

    You can share more questions which are not covered in this blog or post. Always welcome your suggestions and queries. I will definitely try to resolve it. 

    Please comment your queries and new set of questions under the comment sections. I will create a new post for those questions. 

    My total experience is 10. Initially I had worked on some support projects and then I moved to java projects. I had worked with many multi-national companies like R-Systems, Tata Consultancy Services, Cybage Softwares.  Fortunately, TCS and Cybage has given me an opportunity to take interviews for experienced candidates. I have conducted more than 1000 interviews by now.

    Mock sessions will be conducted for minimal charges. I will guide you personally on how to crack interviews. All sessions will be online sessions only. My interview book will be provided free of cost if you enroll for personal training. Once you have done practice then I assured you will definitely crack almost all java interviews. 

    I have published my book named with "All MNC Java Interview" which is available on amazon. You can go through it or you can directly contact to me if you are interested to read the book. I will give you special discount. I have covered near about 550 questions and answers with program tested on eclipse and necessary diagram. 

    I have covered interview questions asked in all reputed MNC like TCS, Infosys, Capgemini, Tech Mahindra, Cognizant, City Bank, Barclays, Amdocs, Mindtree etc. My purpose behind this book is, help you to get a job in your dream company. I can understand this is a struggling period for job seekers and freshers. Everybody must have gone from this phase. so never give up. Keep upgrading yourself. I am sure you will get a job in your dream company. All the best!!! 

    Please reach out to me for personal training for interview preparation. 

    You can reach out to me at mncjavainterview@gmail.com.

     


    Post a Comment

    0 Comments