Edali Preloader

Top 20 Core Java Interview Questions and Answers

Core Java refers to the fundamental features and components of the Java programming language, which are essential for building general-purpose applications. It includes the basic concepts, libraries, and tools necessary for developing a wide range of applications from desktop to server-side software.

1. What is Java?

Java is a high-level, class-based, object-oriented programming language designed to have as few implementation dependencies as possible. It is platform-independent because of the Java Virtual Machine (JVM), which allows Java applications to run on any device that has the JVM installed.

2.What is the difference between an abstract class and an interface?

Abstract Class: Can have both abstract and concrete methods, supports instance variables, can have constructors, and allows method implementation. Interface: Only abstract methods (until Java 8 introduced default and static methods), no instance variables, no constructors, all methods are implicitly public.

3.What is the difference between JDK, JRE, and JVM?

JDK (Java Development Kit): It is a software development environment used for developing Java applications, containing tools like the compiler (javac), JRE, and libraries. JRE (Java Runtime Environment): It provides the libraries, Java Virtual Machine (JVM), and other components necessary for running Java applications. JVM (Java Virtual Machine): It is a virtual machine that executes Java bytecode and provides platform independence.

4.What are the access modifiers in Java?

Java provides four access modifiers:Private: Accessible only within the class. Default (no modifier): Accessible within the same package. Protected: Accessible within the same package and subclasses. Public: Accessible from everywhere

5.What is a static keyword in Java?

The static keyword can be used with variables, methods, blocks, and nested classes. It means the member belongs to the class rather than instances of the class. Static members are shared across all instances.

6.What is the difference between == and equals() for strings?

==: Compares references (whether two references point to the same object). equals(): Compares the actual content of the strings.

7.What is the this keyword in Java?

The this keyword refers to the current instance of the class. It is used to differentiate instance variables from local variables or to invoke another constructor in the same class.

8.What is the default value of a local variable?

Local variables do not have a default value and must be explicitly initialized before use.

9.What is the finalize() method in Java?

The finalize() method is called by the garbage collector on an object when the garbage collection is about to destroy that object. It allows the object to clean up resources before being reclaimed, though its execution is not guaranteed.

10.What is the difference between ArrayList and LinkedList?

ArrayList: Backed by a dynamic array, offers constant-time access but slower insertions and deletions. LinkedList: Backed by a doubly-linked list, offers faster insertions and deletions but slower access time.

11. What is multithreading in Java?

Multithreading is the ability of a Java program to execute multiple threads simultaneously. Threads are lightweight sub-processes that improve the performance of programs by utilizing CPU resources efficiently.

12.What are the ways to create a thread in Java?

There are two main ways to create a thread:By implementing the Runnable interface and overriding its run() method. By extending the Thread class and overriding its run() method.

13. What is synchronization in Java?

Synchronization in Java is the capability to control the access of multiple threads to shared resources. It helps prevent thread interference and inconsistency. It can be achieved using the synchronized keyword.

14. What is the difference between HashMap and HashTable?

HashMap: Non-synchronized, allows null keys and values. HashTable: Synchronized, doesn’t allow null keys or values.

15.What is the difference between ArrayList and Vector?

ArrayList: Non-synchronized, faster but not thread-safe. Vector: Synchronized, slower but thread-safe.

16.What is the purpose of the instanceof keyword in Java?

The instanceof keyword is used to check whether an object is an instance of a specific class or implements a particular interface.

17.What are wrapper classes in Java?

Wrapper classes are used to convert primitive data types into objects. For example, int can be wrapped into Integer, char into Character, and so on.

18.What is autoboxing and unboxing in Java?

Autoboxing: Automatic conversion of primitive types to their corresponding wrapper classes (e.g., int to Integer). Unboxing: Automatic conversion of wrapper types to their corresponding primitive types (e.g., Integer to int).

19.What is a null pointer exception (NPE) in Java?

A NullPointerException occurs when an application attempts to use an object reference that has not been initialized (i.e., is null), such as calling a method on a null object.

20.What is the String pool in Java?

The String pool is a special memory region where Java stores string literals to save memory. When you create a string using a literal (e.g., "abc"), Java checks the string pool first and creates a new string only if one does not already exist.

10000+ students have changed their careers with Trendnologies?

You have been successfully Subscribed! Ops! Something went wrong, please try again.

Follow us!

TRENDING COURSES

TRENDING COURSES

Our Branches

OUR BRANCHES

CHENNAI

COIMBATORE

Copyright 2024 Trendnologies | All rights reserved.

Register Your Demo Slot

    Wait!! Don't skip your Dream Career

    Signup & Get 10% Instant Discount

      Get in Touch with us


        5 + 6 =