Top 25+ Core Java Interview Questions

Java is everywhere—from apps on your phone to major websites. So, if you are preparing for a tech interview – it is important to be ready for some Core Java questions. Did you know? According to a TechRepublic report – 90% of Fortune 500 companies still rely on Java. In fact – some of the top companies in India, like – Wipro, Infosys, Capgemini, and Cognizant, highly prefer candidates with Core Java skills. So, to help you with the preparation – we have put together a list of the top 25+ Core Java interview questions for 2024. 

Get ready to walk into your next interview with confidence! 

Core Java Interview Questions for Freshers

Here are some of the most common Core Java questions asked in interview for freshers along with their answers. 

  1. What is Java?

Java is a high-level, object-oriented programming language. It’s used to create applications that run on various devices, like computers and smartphones.

  1. What are the main features of Java?

Java is known for its simplicity, object orientation, platform independence, and security. It’s also portable, meaning code written in Java can run on any device that has the Java Virtual Machine (JVM).

  1. What is a Java class?

This is one of the most important Core Java interview topics

A class in Java is a blueprint for creating objects. It defines properties (attributes) and methods (functions) that the objects created from the class will have.

  1. What is an object in Java?

An object is an instance of a class. It represents a specific entity with properties and behaviours defined by its class.

  1. What is inheritance in Java?

Inheritance allows a new class to inherit properties and methods from an existing class. This helps in code reusability and creates a hierarchical relationship between classes.

  1. What is a ClassLoader?

A ClassLoader in Java is a part of the Java Runtime Environment that dynamically loads Java classes into the JVM. It searches for class files and loads them into memory when required, guaranteeing that classes are available for execution. It helps manage class loading and initialization.

  1. What are the differences between Heap and Stack Memory in Java?

Heap memory is used for dynamic memory allocation and stores objects and class instances, which have variable sizes and lifetimes. Stack memory, on the other hand, is used for static memory allocation, storing method call frames and local variables with a fixed size and lifetime.

  1. What are access modifiers in Java?

Access modifiers define the visibility of classes, methods, and variables. The common ones are public, private, protected, and default (no modifier).

  1. What is Java String Pool?

The Java String Pool is a special memory area where Java stores string literals to optimize memory usage. When a string literal is created, Java checks the pool to see if an identical string already exists. If it does, the same reference is used, reducing memory consumption and improving performance.

Also Read - Top 25+ Interview Questions On String in Java with Answers

Core Java Interview Questions for Experienced

Here are some commonly-asked Core Java questions asked in interview for experienced candidates along with their answers. 

Core Java Interview Questions for 2 Year Experience

  1. What is the difference between ArrayList and LinkedList in Java?

ArrayList uses a dynamic array to store elements, offering faster access times for retrieving data but slower insertions and deletions. LinkedList uses a doubly linked list, making insertions and deletions faster but retrieval slower compared to ArrayList.

Also Read - Top 20 Array Interview Questions In Java
  1. How does Java handle memory management?

This is one of the most common Core Java interview topics.

Java uses garbage collection to automatically manage memory. The Java Virtual Machine (JVM) periodically frees up memory by removing objects that are no longer in use, reducing the risk of memory leaks.

Also Read - Top 20+ Java Collections Interview Questions With Answers

Core Java Interview Questions for 3 Years Experience

  1. What is the difference between final, finally, and finalize in Java?

Final is used to define constants and prevent method overriding and inheritance. Finally is a block used in exception handling to ensure that certain code is executed regardless of exceptions. Finalize is a method called by the garbage collector before an object is removed from memory.

  1. Explain the concept of method overloading and method overriding.

Method overloading occurs when multiple methods have the same name but different parameters in the same class. Method overriding happens when a subclass provides a specific implementation for a method that is already defined in its superclass.

Also Read - Top 20+ Interview Questions On Java Servlets

Core Java Interview Questions for 5 Years Experience

  1. What is the role of the transient keyword in Java?

The transient keyword is used to indicate that a field should not be serialized when an object is converted into a byte stream. This is useful for preventing sensitive data from being saved.

  1. How does Java achieve platform independence?

Java achieves platform independence through the use of the Java Virtual Machine (JVM). Java code is compiled into bytecode, which is then interpreted by the JVM on any platform, allowing the same code to run on different systems.

  1. What is the difference between synchronized and volatile in Java?

Synchronized makes sure that only one thread can access a block of code or method at a time, preventing concurrent access issues. Volatile makes sure that changes to a variable are visible to all threads immediately, but it doesn’t provide atomicity or mutual exclusion.

Also Read - Top 20+ Java Multithreading Interview Questions
  1. Explain the concept of Java Generics.

Java Generics allows you to write classes, interfaces, and methods with type parameters. This provides compile-time type checking and eliminates the need for type casting, making code more flexible and type-safe.

Core Java Interview Questions for 6 Years Experience

  1. What are design patterns? Can you name a few?

Design patterns are proven solutions to common software design problems. Examples include Singleton (guarantees only one instance of a class), Observer (notifies observers of changes), and Factory (creates objects without specifying the exact class).

  1. What is the difference between HashMap and TreeMap?

HashMap stores key-value pairs in a hash table and offers constant-time performance for basic operations. TreeMap stores pairs in a red-black tree, which keeps them sorted and allows for log-time performance for operations.

Core Java Interview Questions for 7 Years Experience

  1. What is a Java Stream?

Java Streams provide a way to process sequences of elements (like collections) in a functional style. They support operations like filtering, mapping, and reducing, making data processing more concise and readable.

Also Read - Top 20 Stream API Interview Questions with Answers
  1. Explain the Java Memory Model (JMM).

The Java Memory Model defines how threads interact through memory and what behaviours are allowed for the visibility, ordering, and atomicity of variables. It guarantees consistency and correctness in concurrent programming.

Core Java Interview Questions for 8 Years Experience

  1. What are the different types of class loaders in Java?

Java has several class loaders, including – Bootstrap ClassLoader (loads core Java classes), Extension ClassLoader (loads classes from the extensions directory), and System/Application ClassLoader (loads classes from the classpath).

  1. How does Java handle exceptions?

This is one of the most common Core Java interview topics.

Java handles exceptions using a try-catch block. Code that might throw an exception is placed in the try block, and exceptions are caught and handled in the catch block. The finally block can be used to execute code regardless of whether an exception occurs.

Also Read - Top 25+ Java Data Structures Interview Questions With Answers

Core Java Interview Questions for 10 Years Experience

  1. What is the significance of Java 8 features like Lambda expressions and Streams?

Java 8 introduced Lambda expressions to simplify the use of anonymous functions and pass behaviour as parameters. Streams provide a powerful way to process collections of data in a functional style, enhancing code readability and efficiency.

  1. How do you manage transactions in Java?

Transactions in Java are managed using the Java Transaction API (JTA) or with Java Persistence API (JPA) annotations. Transactions ensure that a series of operations are completed successfully or not executed at all, maintaining data integrity.

Also Read - Top 20+ Java Full Stack Developer Interview Questions With Answers

Core Java Tricky Interview Questions

This is a list of Core Java difficult interview questions and their answers. 

  1. Can you explain the difference between == and .equals() with respect to objects in Java? 

== checks if two references point to the same object in memory, while .equals() checks if the contents of two objects are equal. For custom objects, you should override .equals() to compare object content.

  1. What is the purpose of the clone() method in Java? 

The clone() method creates and returns a copy of the object. For it to work, the class must implement the Cloneable interface; otherwise, CloneNotSupportedException is thrown.

  1. How does Java handle multiple inheritance? 

Java does not support multiple inheritance through classes to avoid complexity and ambiguity. Instead, it supports multiple inheritance through interfaces, where a class can implement multiple interfaces.

Also Read - Top 15+ Inheritance in Java Interview Questions With Answers
  1. How can you handle alerts in Selenium WebDriver? 

You may come across Core Java interview questions for Selenium, like this one. 

In Selenium WebDriver, you can handle alerts using the Alert interface. You can switch to the alert with driver.switchTo().alert(), and then use methods like accept(), dismiss(), getText(), and sendKeys() to interact with the alert.

Also Read - Top 25+ Java Questions for Selenium Interview
  1. What is the difference between assertEquals() and assertTrue() in JUnit? 

This is one of the most common Core Java interview questions for automation testing.

assertEquals() checks if two values are equal and reports a failure if they are not. assertTrue() checks if a given condition is true and reports a failure if it is false. assertEquals() is used for exact matches, while assertTrue() is used for boolean conditions.

  1. What is a functional interface in Java 8? 

This is one of the most important Core Java 8 interview questions

A functional interface in Java 8 is an interface with a single abstract method (SAM). It can have multiple default or static methods. Functional interfaces are used as the target type for lambda expressions and method references. The @FunctionalInterface annotation is used to denote such interfaces.

Also Read - Top 35+ Java 8 Interview Questions With Answers

Core Java Viva Questions

Here are some questions that you may come across during the Core Java quiz.

  1. What is the difference between public, protected, and private access modifiers in Java?
  • public: The member is accessible from any other class.
  • protected: The member is accessible within the same package and subclasses, even if they are in different packages.
  • private: The member is accessible only within the same class.
  1. What is the significance of the static keyword in Java?

The static keyword means that a member (variable or method) belongs to the class rather than instances of the class. It can be accessed without creating an instance of the class. Static members are shared among all instances of the class.

  1. What are constructors in Java? How are they different from methods?

Constructors are special methods used to initialize objects when they are created. They have the same name as the class and no return type. Unlike methods, constructors are not called explicitly; they are called automatically when an object is instantiated.

  1. What is the purpose of the super keyword in Java?

The super keyword refers to the superclass of the current object. It is used to call the superclass’s methods and constructors. It helps access or override methods from the superclass and resolves methods or variable hiding issues.

  1. What is the difference between throw and throws in Java?

Throw is used to explicitly throw an exception from a method or block of code. Throws is used in a method signature to declare that a method can throw certain types of exceptions, signalling that the calling code should handle them.

Core Java Interview Programming Questions

Here are some important Core Java programs asked in interview and their answers. 

  1. Write a Java program to check if a number is prime.

public class PrimeChecker {

    public static void main(String[] args) {

        int number = 29;

        boolean isPrime = isPrime(number);

        System.out.println(“Is ” + number + ” a prime number? ” + isPrime);

    }

    public static boolean isPrime(int n) {

        if (n <= 1) return false;

        for (int i = 2; i <= Math.sqrt(n); i++) {

            if (n % i == 0) return false;

        }

        return true;

    }

}

  1. Write a Java program to calculate the sum of digits of a number.

public class SumOfDigits {

    public static void main(String[] args) {

        int number = 12345;

        int sum = sumOfDigits(number);

        System.out.println(“Sum of digits of ” + number + ” is ” + sum);

    }

    public static int sumOfDigits(int n) {

        int sum = 0;

        while (n > 0) {

            sum += n % 10;

            n /= 10;

        }

        return sum;

    }

}

Also Read - Top 20 JMeter Interview Questions and Answers
  1. Write a Java program to sort an array of integers.

This is one of the most common Core Java coding interview questions

import java.util.Arrays;

public class SortArray {

    public static void main(String[] args) {

        int[] array = {3, 1, 4, 1, 5, 9};

        Arrays.sort(array);

        System.out.println(“Sorted array: ” + Arrays.toString(array));

    }

}

  1. Write a Java program to check if a given string is a palindrome.

public class PalindromeChecker {

    public static void main(String[] args) {

        String str = “madam”;

        boolean isPalindrome = isPalindrome(str);

        System.out.println(“Is the string \”” + str + “\” a palindrome? ” + isPalindrome);

    }

    public static boolean isPalindrome(String str) {

        int left = 0;

        int right = str.length() – 1;

        while (left < right) {

            if (str.charAt(left) != str.charAt(right)) {

                return false;

            }

            left++;

            right–;

        }

        return true;

    }

}

  1. Write a Java program to remove duplicates from an array.

import java.util.Arrays;

public class RemoveDuplicates {

    public static void main(String[] args) {

        int[] array = {1, 2, 2, 3, 4, 4, 5};

        int[] result = removeDuplicates(array);

        System.out.println(“Array without duplicates: ” + Arrays.toString(result));

    }

    public static int[] removeDuplicates(int[] array) {

        return Arrays.stream(array).distinct().toArray();

    }

}

Core Java MCQs

These are some common Core Java multiple choice questions and their answers. 

  1. Which of the following is not a valid Java identifier?

A) myVariable

B) _variable

C) 2variable

D) myVariable2

Answer: C) 2variable

  1. What is the default value of a boolean variable in Java?

A) true

B) false

C) null

D) 0

Answer: B) false

  1. Which keyword is used to prevent a method from being overridden in Java?

A) static

B) final

C) abstract

D) synchronized

Answer: B) final

  1. What is the size of int in Java?

A) 4 bytes

B) 2 bytes

C) 8 bytes

D) 1 byte

Answer: A) 4 bytes

  1. Which of the following classes is used to handle input from the user in Java?

A) InputStream

B) Scanner

C) FileReader

D) BufferedReader

Answer: B) Scanner

  1. What is the result of the following expression in Java: 3 + 2 * 2?

A) 7

B) 10

C) 8

D) 12

Answer: A) 7

Wrapping Up

Preparing for a Java interview requires understanding both basic and advanced concepts. These top 25+ Core Java interview questions and their answers will help you get ready. 

And if you are looking for IT jobs in India, visit Hirist. It is an online job portal where you can find the latest job openings in the top IT companies in India. You can also install the Hirist app on your smartphone to search for jobs on the go. Good luck with your interview preparation!

Related posts

Top 15+ PySpark Interview Questions and Answers (2024)

Top 15+ Advanced Java Interview Questions

Top 5+ Most Common GD Interview Topics with Answers