Important Java Interview Questions for Freshers


Java is a programming language and computing platform. It hits the top list of all the programming languages and has a wide range of job opportunities. The following Java Interview Questions for Freshers have been created specifically to get you to familiarize yourself with the nature of the question you can experience during your interview for the Java Programming Language subject. If you are interested to learn the language, Java Training in Chennai at FITA is the right place for you to explore your career.

  1. What are the different access specifiers for Java classes?
    Access classifiers are said to be the keywords that are used before a class name which refers to the access scope in Java. The below types of access classifiers are highly important and also frequently asked Java Interview Questions.
    public: field, method, class is accessible from anywhere.
    protected: field and method can be accessed from the same class to where they belong or from subclasses, and from same package class, but not from outside.
    default: field, method, the class can be accessed from the same package only and not from outside of the native package.
    private: field, the method can be accessed from the same class to where they belong.
    2. What is the difference between an Inner class and a Subclass?
    It is a Core Java Interview Questions when you are a beginner go through the answer carefully.
    An inner class has been nested within the other class. An inner class has access rights for the class that is nesting it and can access all methods and variables that are defined in the outer class.
    A subclass inherits from the other class known as the superclass. Sub-class can access all protected and public fields and methods of its superclass.
    3. What is known as data encapsulation and explain it’s the significance?
    Encapsulation is the concept that is asked frequently in most Core Java Interview Questions for Freshers.
    Encapsulation is said to be a concept in Object Oriented Programming for combining methods and properties in a single unit. Encapsulation helps the programmers in following a modular approach for software development as each object has its unique set of variables and methods and serves its functions independently of other objects. Encapsulation is also used for data hiding purposes.
  2. What is the purpose of static variables and static methods?
    When there is a need to share a variable or a method between multiple objects of a class rather than creating separate copies for each object. To make a variable or method shared for all objects, we use.
  3. What is called Loops in Java? What are the three types of loops?
    This is a Java Basic Interview Questions to know mandatorily before attending any interviews.
    Looping is used in programming to implement a statement or a statement block repeatedly. There are three types of loops in Java:
    a. For Loops:
    For loops are used in java to implement statements regularly for a given no of times. For loops are used when no time to implement the statements is referred to as the programmer.
    b. while Loops:
    While loop is used if certain statements require being implemented regularly until a condition is satisfied. The condition is tested first before the implementation of statements in while loops.
    c. Do While Loops:
    Do while loop is similar to while loop with the only difference which condition is examined after implementation of statement blocks. Thus in the do-while loop case, statements are implemented at least once.
  4. What is a singleton class? Give an example
    In Java, a singleton class can have only one instance and thus all its variables and methods belong to one instance. The concept of a singleton class is used for the situations while there is a requirement to limit the no of objects for a class.
    A good example of a singleton usage scenario is while there is a limit of having an only single connection to a database due to some limitations of the driver or any licensing issues.
  5. Explain the difference between break and continue statement?
    When you are asked to explain the Break and Continue concept in Java Interview Questions for Freshers, I suggest you give examples to attract the interviewer.
    Break and continue statements are the two main keywords used in loops. When a break keyword is used in a loop, instantly the loop is broken while when continue keyword is used, the current iteration is broken and the loop continues with the next iteration.
    When the counter reaches 4, the loop is broken in the below example.
    1 For (counter=0; counter<10; counter++)
    2 System.out.println(counter);
    3
    4 if (counter==4) {
    5
    6 break;}
    7
    8 }
    When counter reaches 4, loop just jumps to the next iteration in the below example and after the continue keyword any statements are skipped for the current iteration.
    1 for (counter=0; counter<10; counter++)
    2 system.out.println(counter);
    3
    4 if (counter==4) {
    5
    6 continue;
    7
    8 }
    9
    10 system.out.println(“This will not get printed when counter is 4”);
    11
    12 }
  6. What is known as infinite loop? Explain how infinite loop is declared?
    An infinite loop runs infinitely and without any condition. An infinite loop may be broken by explaining any breaking logic in the statements blocks body.
    An infinite loop is proclaimed as follows
    1 for (;;)
    2
    3 {
    4
    5 // Statements to execute
    6
    7 // Add any loop breaking logic
    8
    9 }
  7. What is known as a final keyword in Java? Give an example
    A constant is proclaimed using the keyword final in Java. The value may be assigned once and after the assignment, the value of a constant cannot be changed.
    A constant with the name const_val has been assigned and declared value in the below example:
    Private Final int const_val=100
    It cannot be overridden by the subclasses if a method is declared as final. This method is considered to be faster than any other method because it has been resolved at the compiled time.
    It can’t be subclassed, when a class is declared as final. E.g., integer, string, and other wrapper classes.
  8. Explain the difference between float and double variables in Java?
    Float always takes about 4 bytes in memory while double takes about 8 bytes in memory in Java. The float is said to be a single-precision floating-point decimal number and the double is the double-precision decimal number.

Leave a Reply