Basic core java interview questions and answers for freshers

Part 1

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


    Basic core java interview questions and answers for freshers

        What are the uses of the super keyword? Where it is applicable and what are the rules to use this keywords?

    -          The super keyword can be used to refer parent class instance variable.

    -          Super keyword can be used to invoke the parent class method.

    -          Super keyword can be used to invoke parent class constructor.


        Can we declare the main method as a final? if not then why not?

    -          Yes. We can declare a main() method as a final.

    package simplifiedjava.crackedInterview; 

    public class Child extends Parent{ 

          public static final void main(String[] args) {

                System.out.println("Hi");

          }

    }

    O/P : Hi


        Can we execute a program without a main method?

    -     Yes, we can execute a program without a main method. We can simply write code inside static block but after execution completed of a static block, you will get an error java.lang.NoSuchMethodError: main. Java 7 onwards is not possible because JVM checks the presence of the main method before initializing the class.

    -   Please refer below example.

    package simplifiedjava.crackedInterview; 

    public class WithoutMainMethodDemo { 

          static {

                System.out.println("Without Main Method");

          }

    }

    output: you will get an error “main method not found in the class”.


     

    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 is the purpose of static method and static variable?

    -          Static Method:

    1.       Without instantiating the class we can invoke the method with the class name.

    -          Static Variable:

                1.       Static variable can be used to refer common property for all objects. 

    -       Please refer the below example. 

    package simplifiedjava.crackedInterview; 

    public class StaticKeywordDemo { 

          public static void main(String[] args) {                   

                Greetings.greetings(); // Call a Method without creating object.

                System.out.println("Inside Main Method Greetings Counter = "+ Greetings.counter);

                // Call static variable without object.

          }          

    } 

    class Greetings{     

          static int counter = 10;     

          public static void greetings() {

                System.out.println("Total Greetings Count = "+ counter);

          }    

    } 

    Output: 

    Total Greetings Count = 10

    Inside Main Method Greetings Counter = 10


        Can you overload the static method?

    -          Yes. We can overload the static method. 

    -      Please refer the below example.

    package simplifiedjava.crackedInterview; 

    public class StaticMethodOverloadDemo { 

          public static void main(String[] args) {

                addition(10,20);

                addition("Advanced Java");

          }     

          public static void addition(int num1, int num2) {

                int total = num1 + num2;           

                System.out.println("Addition is = "+ total);

          }     

          public static void addition(String str) {

                int length = str.length();

                System.out.println("Length of String is = "+ length);

          }    

    } 

    Addition is = 30

    Length of String is = 13


        Can we declare multiple constructors in a single class?

    -          Yes. One class can have multiple constructors.

    -    If one class has multiple constructors then it is called constructor overloading.

    -      Please refer the below example.

    package simplifiedjava.crackedInterview; 

    public class Aeroplane { 

          private int flightNo;

          private String companyName;     

          public Aeroplane() {

                           

          }     

          public Aeroplane(int fligtNo) {

                this.flightNo = fligtNo;

          }     

          public Aeroplane(int fligtNo, String companyName) {

                this.flightNo = fligtNo;

                this.companyName = companyName;          

          }     

          public static void main(String[] args) {

               

          }    

    }

      

        What is the difference between Path and class path?

    -     Path: Path is used to define where the system can find executables(.exe) files.

    -     Classpath: Classpath is used to specify the location of the .class file.  


        Can you explain the following command java, javaw and javaws?

    -   java: Java application executor which is associated with a console to display output/errors

    -   javaw: (Java windowed) application executor not associated with the console. So no display of output/errors. It can be used to silently push the output/errors to text files. It is mostly used to launch GUI-based applications.

    -   javaws: (Java web start) to download and run the distributed web applications. Again, no console is associated.


        What is interpreter?

    -   The computer program that converts high-level language into Assembly level language is called Interpreter.

    -    It is designed to read the source code and interpret the source code line by line.

    -   All errors of each line displays one by one.

    -   An Interpreter does not generate an intermediate machine code.   

    -   Program execution speed is slower than compiler.

    -   Very less amount of time is spent on analyzing and processing the program.    


        Which annotation can be used to make functional interface?

    -   @FunctionalInterface Annotation can be used to make any Interface as functional interface.

    -      Please refer to the below example.

    package simplifiedjava.crackedInterview.java8; 

    @FunctionalInterface

    public interface FunctionalInterfaceDemo {

          public void add();

    }


    • 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 coming post:

    11. What is the difference between method and constructor.

    12. What is the difference between Interface and Abstract Class.

    13. Will the code compile if I have single abstract method but doesn't declare class as a abstract.

    14. Can we declare concrete method in abstract class.

    15. Can we use static member inside non-static area.

    16. What are the exceptions.

    17. Can you explain exception hierarchy.

    18. What is deserialization?

    19. What are the characteristics of List Interface.

    20. What are the characteristics of Map Interface.



    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