Latest java Interview Questions and Answers 2024 for Freshers and Experienced

Java: Frequently Asked Interview Questions and answers. Java is a popular, general-purpose programming language that is widely used for developing desktop, web, and mobile applications. It is known for its "write once, run anywhere" philosophy, which allows Java code to be executed on multiple platforms without modification.


Home->Java Interview Questions and Answers

If you're looking for current Java interview questions and answers, you've come to the right place! This Latest 2024 Question List will provide you with a comprehensive list of trending Java interview questions and answers asked in Top Companies interview round.

Java Interview Questions and Answers Play Quiz On Java  |  More Q&A Click Here

# Question Options Answer
1 Which of those doesn’t have an index based structure?
  • List
  • Set
  • Map
  • Queue
  • Set
    2 java.util.Collections is a:
  • Class
  • Interface
  • Object
  • None of the above
  • Class
    3 Methods such as reverse, shuffle are offered in:
  • Object
  • Collection
  • Collections
  • Apache Commons Collections
  • Collections
    4 Which of those allows duplicate elements?
  • Set
  • List
  • All
  • None of the above
  • List
    5 Which allows the storage of a null key and null values?
  • Hashtable
  • HashMap
  • Set
  • None of the above
  • HashMap
    6 Which interface should be implemented for sorting on basis of many criteria’s?
  • Comparator
  • Comparable
  • Serializable
  • None of the above
  • Comparator
    7 What guarantees type-safety in a collection?
  • Generics
  • Abstract classes
  • Interfaces
  • Collection
  • Generics
    8 The most used interfaces from the collection framework are?
  • List
  • Map
  • Set
  • Queue
  • Map
    9 The root interface of Java collection framework hierarchy is –
  • Collection
  • Root
  • Collections
  • List/Set
  • List/Set
    10 Which of those is synchronized?
  • ArrayList
  • LinkedList
  • Vector
  • None of the above
  • Vector
    11 ArrayList implements that of the following?
  • List
  • RandomAccess
  • Cloneable
  • All of these
  • All of these
    12 Which of those permits the storage of the many null values?
  • Set
  • List
  • None of these
  • All of these
  • All of these
    13 Which doesn’t permit to store a null value?
  • TreeSet
  • LinkedHashSet
  • HashSet
  • None
  • TreeSet
    14 TreeMap implements?
  • Dictionary
  • HashMap
  • AbstractMap
  • Navigable Map
  • Navigable Map
    15 Which of these standard collection classes implements a dynamic array?
  • LinkedList
  • AbstractSet
  • AbstractList
  • ArrayList
  • ArrayList
    16 Which of these method of ArrayList class is used to obtain present size of an object?
  • capacity()
  • index()
  • size()
  • length()
  • size()
    17 Which of the below does not implement Map interface?
  • HashMap
  • Hashtable
  • Vector
  • EnumMap
  • Vector
    18 How to externally synchronize hashmap?
  • HashMap.synchronize(HashMap a);
  • Collections.synchronizedMap(new HashMap());
  • HashMap a = new HashMap();
  • Collections.synchronize(new HashMap());
  • Collections.synchronizedMap(new HashMap());
    19 How can we remove an object from ArrayList?
  • remove() method and using Iterator
  • delete() method
  • using Iterator
  • remove() method
  • remove() method and using Iterator
    20 Which class provides thread safe implementation of List?
  • ArrayList
  • List
  • HashList
  • CopyOnWriteArrayList
  • CopyOnWriteArrayList
    21 What is the relation between hashset and hashmap?
  • HashMap is the interface; HashSet is the concrete class
  • HashMap internally implements HashSet
  • HashSet internally implements HashMap
  • HashSet is the interface; HashMap is the concrete class
  • HashSet internally implements HashMap
    22 Which of these object stores association between keys and values?
  • Map
  • Array
  • Hash table
  • String
  • Map
    23 Which of these classes provide implementation of map interface?
  • LinkedList
  • ArrayList
  • HashMap
  • DynamicList
  • HashMap
    24 Which of these methods can be used to obtain set of all keys in a map?
  • keyall()
  • getAll()
  • getKeys()
  • keySet()
  • keySet()
    25 Which of these are legacy classes?
  • Vector
  • All of the mentioned
  • Stack
  • Hashtable
  • All of the mentioned
    26 Which of the following is not OOPS concept in Java?
  • Inheritance
  • Encapsulation
  • Polymorphism
  • Compilation
  • Compilation
    27 When does method overloading is determined?
  • At run time
  • At compile time
  • At coding time
  • At execution time
  • At compile time
    28 When Overloading does not occur?
  • More than one method with same name but different method signature and different number or type of parameters.
  • More than one method with same name, same signature but different number of signature.
  • More than one method with same name, same signature, same number of parameters but different type
  • More than one method with same name, same number of parameters and type but different signature
  • More than one method with same name, same number of parameters and type but different signature
    29 Which concept of Java is a way of converting real world objects in terms of class?
  • Polymorphism
  • Encapsulation
  • Abstraction
  • Inheritance
  • Abstraction
    30 Which concept of Java is achieved by combining methods and attribute into a class?
  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation
    31 What is it called where child object gets killed if parent object is killed?
  • Aggregation
  • Composition
  • Encapsulation
  • Association
  • Composition
    32 Which component is used to compile, debug and execute java program?
  • JVM
  • JDK
  • JIT
  • JRE
  • JDK
    33 Which component is responsible for converting bytecode into machine specific code?
  • JVM
  • JDK
  • JIT
  • JRE
  • JVM
    34 Which component is responsible to run java program?
  • JVM
  • JDK
  • JIT
  • JRE
  • JRE
    35 Which component is responsible to optimize bytecode to machine code?
  • JVM
  • JDK
  • JIT
  • JRE
  • JIT
    36 Which of the below is invalid identifier with the main method?
  • public
  • static
  • private
  • final
  • private
    37 What is use of interpreter?
  • They convert bytecode to machine language code
  • They read high level code and execute them
  • They are intermediated between JIT and JVM
  • It is a synonym for JIT
  • They read high level code and execute them
    38 Which of the following is a valid declaration of an object of class Box?
  • Box obj = new Box();
  • Box obj = new Box;
  • obj = new Box();
  • new Box obj;
  • Box obj = new Box();
    39 Which of these operators is used to allocate memory for an object?
  • malloc
  • alloc
  • new
  • give
  • new
    40 Which of the following statements is correct?
  • Public method is accessible to all other classes in the hierarchy
  • Public method is accessible only to subclasses of its parent class
  • Public method can only be called by object of its class
  • Public method can be accessed by calling object of the public class
  • Public method is accessible to all other classes in the hierarchy
    41 What is the process of defining more than one method in a class differentiated by method signature?
  • Method overriding
  • Method overloading
  • Method doubling
  • None of the mentioned
  • Method overloading
    42 Which of the following is a method having same name as that of it’s class?
  • finalize
  • delete
  • class
  • constructor
  • constructor
    43 Which method can be defined only once in a program?
  • main method
  • finalize method
  • static method
  • private method
  • main method
    44 Which keyword is used by the method to refer to the object that invoked it?
  • import
  • catch
  • abstract
  • this
  • this
    45 Which function is used to perform some action when the object is to be destroyed?
  • finalize()
  • delete()
  • main()
  • none of the mentioned
  • finalize()
    46 What is false about constructor?
  • Constructors cannot be synchronized in Java
  • Java does not provide default copy constructor
  • Constructor can have a return type
  • “this” and “super” can be used in a constructor
  • Constructor can have a return type
    47 Which of these access specifier must be used for class so that it can be inherited by another subclass?
  • public
  • private
  • protected
  • none of the mentioned
  • public
    48 What is the process by which we can control what parts of a program can access the members of a class?
  • Polymorphism
  • Abstraction
  • Encapsulation
  • Recursion
  • Encapsulation
    49 Which of these is used as default for a member of a class if no access specifier is used for it?
  • public
  • public, within its own package
  • protected
  • private
  • private
    50 What is use of interpreter?
  • They are intermediated between JIT and JVM
  • It is a synonym for JIT
  • They convert bytecode to machine language code
  • They read high level code and execute them
  • They read high level code and execute them
    51 What is the extension of compiled java classes?
  • .txt
  • .class
  • .js
  • .java
  • .class
    52 Which of the below is invalid identifier with main method?
  • private
  • final
  • static
  • public
  • private
    53 Which of these package is used for text formatting in Java programming language?
  • java.awt
  • java.awt.text
  • java.io
  • java.text
  • java.text
    54 Which environment variable is used to set java path?
  • CLASSPATH
  • JAVA_HOME
  • MAVEN_HOME
  • JAVA
  • JAVA_HOME
    55 Which of these can not be used for a variable name in Java?
  • identifier
  • identifier & keyword
  • keyword
  • None of these
  • keyword
    56 Literals in java must be appended by which of these?
  • L
  • L and I
  • D
  • l
  • L and I
    57 What is true of final class?
  • Final class cannot be instantiated
  • Final class cannot be inherited
  • Final class cause compilation failure
  • Final class cause runtime failure
  • Final class cannot be inherited
    58 All the variables of interface should be ?
  • default and static
  • default and final
  • protect, static and final
  • public,static and final
  • public,static and final
    59 How can a protected modifier be accessed?
  • accessible by all
  • accessible only within package
  • accessible only within the class
  • accessible within package and outside the package but through inheritance only
  • accessible within package and outside the package but through inheritance only
    60 Which of the following modifier means a particular variable cannot be accessed within the package?
  • protected
  • default
  • private
  • public
  • private
    61 All the variables of class should be ideally declared as ?
  • default
  • private
  • public
  • protected
  • private
    62 Which one of the following is not an access modifier?
  • Void
  • Protected
  • Private
  • Public
  • Void
    63 Which of the following is not a valid flow control statement?
  • continue
  • break
  • return
  • exit()
  • exit()
    64 What is true about do statement?
  • do statement executes the code more than once always
  • do statement executes the code of a loop at least once
  • do statement does not get execute if condition is not matched in the first iteration
  • do statement checks the condition at the beginning of the loop
  • do statement executes the code of a loop at least once
    65 Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?
  • while
  • for
  • if
  • do-while
  • do-while
    66 Which of these method of class StringBuffer is used to find the length of current character sequence?
  • Length()
  • capacity()
  • Capacity()
  • length()
  • length()
    67 Which of these method of class String is used to remove leading and trailing whitespaces?
  • Trim()
  • doTrim()
  • startsWith()
  • trim()
  • trim()
    68 Which of this method of class String is used to extract a substring from a String object?
  • Substring()
  • tostring()
  • substring()
  • SubString()
  • substring()
    69 Which of these method of class String is used to compare two String objects for their equality?
  • Isequal()
  • isequal()
  • Equals()
  • equals()
  • equals()
    70 Which of these is an incorrect statement?
  • String objects are mutable, they cannot be changed
  • StringBuffer class is used to store string in a buffer for later use
  • String object can point to some other reference of String variable
  • String objects are immutable, they cannot be changed
  • StringBuffer class is used to store string in a buffer for later use
    71 Which of this method of class String is used to obtain a length of String object?
  • Sizeof()
  • length()
  • get()
  • lengthof()
  • length()
    72 Which of these methods can be used to search an element in a list?
  • get()
  • binaryserach()
  • sort()
  • find()
  • binaryserach()
    73 Which of these cannot be declared static?
  • variable
  • method
  • class
  • object
  • object
    74 Which of these keywords is used to prevent content of a variable from being modified?
  • last
  • final
  • constant
  • static
  • final
    75 Arrays in Java are implemented as?
  • object
  • class
  • variable
  • method
  • object
    76 Where is array stored in memory?
  • first generation memory
  • stack space
  • heap space and stack space
  • heap space
  • heap space
    77 Can you make an array volatile?
  • No
  • Not possible
  • True
  • False
  • True
    78 Which of these is an incorrect Statement?
  • Array can be initialized when they are declared.
  • Array can be initialized using comma separated expressions surrounded by curly braces.
  • It is necessary to use new operator to initialize an array.
  • None of these
  • It is necessary to use new operator to initialize an array.
    79 Which of these classes is super class of Exception class?
  • Class
  • RunTime
  • Throwable
  • System
  • Throwable
    80 Which of these methods return description of an exception?
  • obtainException()
  • obtainDescription()
  • getMessage()
  • getException()
  • getMessage()
    81 Which of these statements is incorrect?
  • try can be followed by both catch and finally block
  • try need not to be followed by anything
  • try block need not to be followed by catch block
  • try block can be followed by finally block instead of catch block
  • try need not to be followed by anything
    82 Which of these keywords are used for generating an exception manually?
  • check
  • try
  • catch
  • throw
  • throw
    83 Which of these keywords are used for the block to handle the exceptions generated by try block?
  • check
  • throw
  • try
  • catch
  • catch
    84 Which of these keywords are used for the block to be examined for exceptions?
  • try
  • catch
  • throw
  • check
  • try
    85 What is the use of try and catch?
  • It allows to fix errors
  • It prevents automatic terminating of the program in cases when an exception occurs
  • It allows us to manually handle the exception
  • All of Above
  • All of Above
    86 Which of these exceptions will occur if we try to access the index of an array beyond its length?
  • ArrayIndexException
  • ArithmeticException
  • ArrayIndexOutOfBoundsException
  • ArrayException
  • ArrayIndexOutOfBoundsException
    87 A single try block must be followed by which of these?
  • try
  • finally
  • catch
  • finally & catch
  • finally & catch
    88 Which of these clause will be executed even if no exceptions are found?
  • catch
  • throw
  • finally
  • throws
  • finally
    89 Which of these class is related to all the exceptions that are explicitly thrown?
  • Exception
  • Throw
  • Error
  • Throwable
  • Throwable
    90 Which of these keywords is used to generate an exception explicitly?
  • catch
  • throw
  • finally
  • try
  • throw
    91 What exception thrown by parseInt() method?
  • NullPointerException
  • NumberFormatException
  • ArithmeticException
  • ClassNotFoundException
  • NumberFormatException
    92 Which of these handles the exception when no catch is used?
  • throw handler
  • Java run time system
  • Default handler
  • finally
  • Default handler
    93 Which of these class is related to all the exceptions that cannot be caught?
  • Exception
  • RuntimeExecption
  • Error
  • All of above
  • Error
    94 Which part of code gets executed whether exception is caught or not?
  • throw
  • try
  • finally
  • catch
  • finally
    95 Which of the following keywords is used for throwing exception manually?
  • catch
  • throw
  • try
  • finally
  • throw
    96 What would be the result if a class extends two interfaces and both have a method with same name and signature?
  • Code runs successfully
  • First called method is executed successfully
  • Runtime error
  • Compile time error
  • Compile time error
    97 Which of the following is used for implementing inheritance through class?
  • implements
  • inherited
  • using
  • extends
  • extends
    98 Which of the following is used for implementing inheritance through an interface?
  • extends
  • inherited
  • implements
  • using
  • implements
    99 Static members are not inherited to subclass.
  • return 0
  • return values
  • False
  • True
  • False
    100 If super class and subclass have same variable name, which keyword should be used to use super class?
  • this
  • classname
  • super
  • upper
  • super

    Are you preparing for a Java developer interview? Brush up on your skills with our comprehensive collection of Java interview questions. Covering everything from basic syntax to advanced concepts, our questions will help you demonstrate your knowledge and experience with the Java programming language.This page is designed to test a candidate's understanding of the key concepts in the Java programming language and their ability to apply that knowledge to real-world situations. Get ready to impress your interviewer and land your dream job with our Java interview question page

    This page provides a comprehensive collection of Java questions and answers, covering a wide range of topics related to the language, such as:

    • Basic syntax and data types
    • Object-oriented programming concepts
    • Control structures, such as loops and conditions
    • Exception handling
    • Collections and generics
    • Multithreading and concurrency
    • Advanced topics such as functional programming and design patterns

    Additionally, you will also find useful tips on how to prepare for your Java interview, such as reviewing your coding skills, studying up on the latest technologies and trends, and practicing your interviewing skills.

    Whether you are a junior developer or an experienced professional, this guide will help you ace your Java interview and land your dream job. So, whether you are looking for your first job as a developer or looking to make a change in your career, this guide will be a valuable resource for you.