Skip to content
My blog

My blog

Just another WordPress site

  • Azure
  • Business Analyst
  • Cybersecurity
  • Java
  • Python
  • Salesforce
  • Snowflake
  • SQL and PLSQL
  • Toggle search form

Top 10 Core Java Interview Questions and Answers

Posted on February 1, 2025February 1, 2025 By admin No Comments on Top 10 Core Java Interview Questions and Answers
1.What are the main features of Java?

Java is known for:

  • Object-Oriented – Everything is based on objects and classes.
  • Platform Independent – Runs on any OS using JVM (Write Once, Run Anywhere).
  • Secure – Uses bytecode verification and access control.
  • Robust – Exception handling and memory management with garbage collection.
  • Multithreading – Supports concurrent execution using threads.
  • High Performance – Uses JIT (Just-In-Time) compiler for faster execution.
2.What is the difference between JDK, JRE, and JVM?
FeatureJDK (Java Development Kit)JRE (Java Runtime Environment)JVM (Java Virtual Machine)
DefinitionProvides tools for developing, compiling, and running Java programsProvides libraries and JVM to run Java applicationsExecutes Java bytecode
IncludesJRE + development tools (compiler, debugger, etc.)JVM + libraries and classesConverts bytecode to machine code
Needed for?DevelopersEnd-users running Java applicationsRuns Java programs
3.What is the difference between == and equals()?
  • == compares references (memory addresses) of objects.
  • equals() compares values of objects (content comparison).

Example:

String s1 = new String("Java");
String s2 = new String("Java");

System.out.println(s1 == s2);       // false (different objects in memory)
System.out.println(s1.equals(s2));  // true (content is the same)
4.What is a constructor in Java?

A constructor is a special method used to initialize an object. It has the same name as the class and does not have a return type.

Example:
class Car {
    String model;
    
    // Constructor
    Car(String m) {
        model = m;
    }
    
    public void display() {
        System.out.println("Car model: " + model);
    }
    
    public static void main(String[] args) {
        Car c = new Car("Tesla");
        c.display();
    }
}
Types of constructors:
  1. Default Constructor – No parameters.
  2. Parameterized Constructor – Accepts parameters.
5.What is the difference between static and instance variables?
FeatureStatic VariableInstance Variable
KeywordstaticNo static
Memory LocationClass-level (shared across objects)Separate for each object
AccessCan be accessed without an objectRequires an object to access
Example:
class Example {
    static int staticVar = 10; // Shared across all objects
    int instanceVar = 20; // Separate for each object
}
6.What is method overloading and method overriding?
FeatureMethod OverloadingMethod Overriding
DefinitionSame method name, different parameters in the same classSame method name and parameters in parent and child class
PurposeAchieve compile-time polymorphismAchieve runtime polymorphism
ExampleMultiple add() methods with different parametersSubclass overrides a method from superclass
Example of Overloading:
class MathUtils {
    int add(int a, int b) {
        return a + b;
    }
    double add(double a, double b) {
        return a + b;
    }
}
Example of Overriding:
class Parent {
    void show() {
        System.out.println("Parent class");
    }
}

class Child extends Parent {
    void show() { // Overriding
        System.out.println("Child class");
    }
}
7.What is the difference between abstract class and interface?
FeatureAbstract ClassInterface
MethodsCan have both abstract and concrete methodsOnly abstract methods (before Java 8)
VariablesCan have instance variablesOnly final and static variables
InheritanceSupports single inheritanceSupports multiple inheritance
Example of Abstract Class:
abstract class Animal {
    abstract void sound(); // Abstract method
    void sleep() { // Concrete method
        System.out.println("Sleeping...");
    }
}
Example of Interface:
interface Animal {
    void sound(); // Abstract method (implicitly public)
}
8.What is the difference between ArrayList and LinkedList?
FeatureArrayListLinkedList
Data StructureDynamic arrayDoubly linked list
Insertion/DeletionSlow (shifting required)Fast (modifies pointers)
Access TimeFast (O(1) for index)Slow (O(n) for index)
9.What is a Java Stream?

A Stream in Java (introduced in Java 8) is used for functional-style operations on collections.

Example:
import java.util.*;
import java.util.stream.*;

class StreamExample {
    public static void main(String[] args) {
        List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
        
        // Convert to uppercase using streams
        List<String> upperNames = names.stream()
                                       .map(String::toUpperCase)
                                       .collect(Collectors.toList());

        System.out.println(upperNames);
    }
}
10.What is the difference between HashMap and HashSet?
FeatureHashMapHashSet
StoresKey-value pairsOnly unique values
Allows Duplicates?Keys must be unique (values can duplicate)No duplicate values
ImplementsMap interfaceSet interface
Example:
HashMap<Integer, String> map = new HashMap<>();
map.put(1, "A");
map.put(2, "B");

HashSet<String> set = new HashSet<>();
set.add("A");
set.add("B");
Java

Post navigation

Previous Post: Most Important business analyst interview question and answers
Next Post: Python Technical Interview Questions and Answers

Related Posts

UNDERSTANDING JAVA OOPS CONCEPTS WITH REAL-WORLD EXAMPLES Java

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • DATA SCIENCE TOP MOST IMPORTANT QUESTION & ANSWERS
  • Understanding Snowflake Architecture: A Deep Dive for Developers
  • Overview of Cloud Computing and Introduction to Microsoft Azure
  • Introduction to Salesforce
  • DATA SHARING & CLONING IN SNOWFLAKE

Recent Comments

No comments to show.

Archives

  • March 2025
  • February 2025
  • January 2025

Categories

  • Azure
  • Business Analyst
  • Cybersecurity
  • Data Science
  • DBT
  • Java
  • Python
  • Salesforce
  • Snowflake
  • SQL and PLSQL

Copyright © 2024 blog.ndredtech.com– All Rights Reserved 

Copyright © 2025 blog.ndredtech.com All Rights Reserved

Powered by PressBook Masonry Blogs