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
201 Which of these keywords are used to define an abstract class?
  • abst
  • abstract
  • Abstract
  • abstract class
  • abstract
    202 Which of these is not abstract?
  • Thread
  • AbstractList
  • List
  • None of the Mentioned
  • Thread
    203 If a class inheriting an abstract class does not define all of its function then it will be known as?
  • Abstract
  • A simple class
  • Static class
  • None of the mentioned
  • Abstract
    204 Which of these is not a correct statement?
  • Every class containing abstract method must be declared abstract
  • Abstract class defines only the structure of the class not its implementation
  • Abstract class can be initiated by new operator
  • Abstract class can be inherited
  • Abstract class can be initiated by new operator
    205 Which of these packages contains abstract keyword?
  • java.lang
  • java.util
  • java.io
  • java.system
  • java.lang
    206 Which of these class is superclass of String and StringBuffer class?
  • java.util
  • java.lang
  • ArrayList
  • None of the mentioned
  • java.lang
    207 Which of these operators can be used to concatenate two or more String objects?
  • +
  • +=
  • &
  • ||
  • +
    208 Which of this method of class String is used to obtain a length of String object?
  • get()
  • Sizeof()
  • lengthof()
  • length()
  • length()
    209 Which of these constructors is used to create an empty String object?
  • String()
  • String(void)
  • String(0)
  • None of the mentioned
  • String()
    210 Which of these is an incorrect statement?
  • String objects are immutable, they cannot be changed
  • String object can point to some other reference of String variable
  • StringBuffer class is used to store string in a buffer for later use
  • None of the mentioned
  • StringBuffer class is used to store string in a buffer for later use
    211 Which of this method of class String is used to extract a substring from a String object?
  • substring()
  • Substring()
  • SubString()
  • None of the mentioned
  • substring()
    212 Which of these method of class String is used to remove leading and trailing whitespaces?
  • startsWith()
  • trim()
  • Trim()
  • doTrim()
  • trim()
    213 What is the value returned by function compareTo() if the invoking string is greater than the string compared?
  • zero
  • value less than zero
  • value greater than zero
  • none of the mentioned
  • value greater than zero
    214 Which of the following statement is correct?
  • replace() method replaces all occurrences of one character in invoking string with another character
  • replace() method replaces only first occurrences of a character in invoking string with another character
  • replace() method replaces all the characters in invoking string with another character
  • replace() replace() method replaces last occurrence of a character in invoking string with another character
  • replace() method replaces all occurrences of one character in invoking string with another character
    215 Which of these method of class String is used to compare two String objects for their equality?
  • equals()
  • Equals()
  • isequal()
  • Isequal()
  • equals()
    216 Which of these methods is used to compare a specific region inside a string with another specific region in another string?
  • regionMatch()
  • match()
  • RegionMatches()
  • regionMatches()
  • regionMatches()
    217 Which of these methods of class String is used to check whether a given object starts with a particular string literal?
  • startsWith()
  • endsWith()
  • Starts()
  • ends()
  • startsWith()
    218 What is the value returned by function compareTo() if the invoking string is less than the string compared?
  • zero
  • value less than zero
  • value greater than zero
  • none of the mentioned
  • value less than zero
    219 Which of these data type value is returned by equals() method of String class?
  • char
  • int
  • boolean
  • all of the mentioned
  • boolean
    220 Which of these class is used to create an object whose character sequence is mutable?
  • String()
  • StringBuffer()
  • String() & StringBuffer()
  • None of the mentioned
  • StringBuffer()
    221 Which of this method of class StringBuffer is used to concatenate the string representation to the end of invoking string?
  • concat()
  • append()
  • join()
  • concatenate()
  • append()
    222 Which of these method of class StringBuffer is used to find the length of current character sequence?
  • length()
  • Length()
  • capacity()
  • Capacity()
  • length()
    223 Which of the following statement is correct?
  • reverse() method reverses all characters
  • reverseall() method reverses all characters
  • replace() method replaces first occurrence of a character in invoking string with another character
  • replace() method replaces last occurrence of a character in invoking string with another character
  • reverse() method reverses all characters
    224 Which of these methods of class StringBuffer is used to extract a substring from a String object?
  • substring()
  • Substring()
  • SubString()
  • None of the mentioned
  • substring()
    225 Which of this method of class StringBuffer is used to reverse sequence of characters?
  • reverse()
  • reverseall()
  • Reverse()
  • reverseAll()
  • reverse()
    226 Which of this method of class StringBuffer is used to get the length of the sequence of characters?
  • length()
  • capacity()
  • Length()
  • Capacity()
  • length()
    227 Which of these is a process of writing the state of an object to a byte stream?
  • Serialization
  • Externalization
  • File Filtering
  • All of the mentioned
  • Serialization
    228 Which of these process occur automatically by the java runtime system?
  • Serialization
  • Garbage collection
  • File Filtering
  • All of the mentioned
  • Serialization
    229 Which of these is an interface for control over serialization and deserialization?
  • Serializable
  • Externalization
  • FileFilter
  • ObjectInput
  • Externalization
    230 Which of these interface extends DataOutput interface?
  • Serializable
  • Externalization
  • ObjectOutput
  • ObjectInput
  • ObjectOutput
    231 Which of these is a method of ObjectOutput interface used to finalize the output state so that any buffers are cleared?
  • clear()
  • flush()
  • fflush()
  • close()
  • flush()
    232 Which of these is method of ObjectOutput interface used to write the object to input or output stream as required?
  • write()
  • Write()
  • StreamWrite()
  • writeObject()
  • writeObject()
    233 Which of these is a process of extracting/removing the state of an object from a stream?
  • Serialization
  • Externalization
  • File Filtering
  • Deserialization
  • Deserialization
    234 Which of these process occur automatically by java run time system?
  • Serialization
  • Memory allocation
  • Deserialization
  • All of the mentioned
  • All of the mentioned
    235 Which of these interface extends DataInput interface?
  • Serializable
  • Externalization
  • ObjectOutput
  • ObjectInput
  • ObjectInput
    236 Which of these class extend InputStream class?
  • ObjectStream
  • ObjectInputStream
  • ObjectOutput
  • ObjectInput
  • ObjectInputStream
    237 How an object can become serializable?
  • If a class implements java.io.Serializable class
  • If a class or any superclass implements java.io.Serializable interface
  • Any object is serializable
  • No object is serializable
  • If a class or any superclass implements java.io.Serializable interface
    238 What is serialization?
  • Turning object in memory into stream of bytes
  • Turning stream of bytes into an object in memory
  • Turning object in memory into stream of bits
  • Turning stream of bits into an object in memory
  • Turning object in memory into stream of bytes
    239 What is deserialization?
  • Turning object in memory into stream of bytes
  • Turning stream of bytes into an object in memory
  • Turning object in memory into stream of bits
  • Turning stream of bits into an object in memory
  • Turning stream of bytes into an object in memory
    240 How many methods Serializable has?
  • 1
  • 2
  • 3
  • 0
  • 0
    241 What type of members are not serialized?
  • Private
  • Protected
  • Static
  • Throwable
  • Static
    242 If member does not implement serialization, which exception would be thrown?
  • RuntimeException
  • SerializableException
  • NotSerializableException
  • UnSerializedException
  • NotSerializableException
    243 Which of the following methods is used to avoid serialization of new class whose super class already implements Serialization?
  • writeObject()
  • readWriteObject()
  • writeReadObject()
  • unSerializaedObject()
  • writeObject()
    244 Which of the following methods is not used while Serialization and DeSerialization?
  • readObject()
  • readExternal()
  • readWriteObject()
  • writeObject()
  • readWriteObject()
    245 Which of these package contains classes and interfaces for networking?
  • java.io
  • java.util
  • java.net
  • java.network
  • java.net
    246 Which of these is a protocol for breaking and sending packets to an address across a network?
  • TCP/IP
  • DNS
  • Socket
  • Proxy Server
  • TCP/IP
    247 How many ports of TCP/IP are reserved for specific protocols?
  • 10
  • 1024
  • 2048
  • 512
  • 1024
    248 How many bits are in a single IP address?
  • 8
  • 16
  • 32
  • 64
  • 32
    249 Which of these is a full form of DNS?
  • Data Network Service
  • Data Name Service
  • Domain Network Service
  • Domain Name Service
  • Domain Name Service
    250 Which of these class is used to encapsulate IP address and DNS?
  • DatagramPacket
  • URL
  • InetAddress
  • ContentHandler
  • InetAddress
    251 Which of these interface abstractes the output of messages from httpd?
  • LogMessage
  • LogResponse
  • Httpdserver
  • httpdResponse
  • LogMessage
    252 Which of these class is used to create servers that listen for either local or remote client programs?
  • httpServer
  • ServerSockets
  • MimeHeader
  • HttpResponse
  • ServerSockets
    253 Which of these is a standard for communicating multimedia content over email?
  • http
  • https
  • Mime
  • httpd
  • Mime
    254 Which of these methods is used to make raw MIME formatted string?
  • parse()
  • toString()
  • getString()
  • parseString()
  • parse()
    255 Which of these class is used for operating on request from the client to the server?
  • http
  • httpDecoder
  • httpConnection
  • httpd
  • httpd
    256 Which of these method of MimeHeader is used to return the string equivalent of the values stores on MimeHeader?
  • string()
  • toString()
  • convertString()
  • getString()
  • toString()
    257 Which of these is an instance variable of class httpd?
  • port
  • cache
  • log
  • All of the mentioned
  • All of the mentioned
    258 Which of these methods of httpd class is used to read data from the stream?
  • getDta()
  • GetResponse()
  • getStream()
  • getRawRequest()
  • getRawRequest()
    259 Which of these method of httpd class is used to get report on each hit to HTTP server?
  • log()
  • logEntry()
  • logHttpd()
  • logResponse()
  • logEntry()
    260 Which of these methods are used to find a URL from the cache of httpd?
  • findfromCache()
  • findFromCache()
  • serveFromCache()
  • getFromCache()
  • serveFromCache()
    261 Which of these variables stores the number of hits that are successfully served out of cache?
  • hits
  • hitstocache
  • hits_to_cache
  • hits.to.cache
  • hits.to.cache
    262 Which of these method of httpd class is used to write UrlCacheEntry object into local disk?
  • writeDiskCache()
  • writetoDisk()
  • writeCache()
  • writeDiskEntry()
  • writeDiskCache()
    263 Which of these method is used to start a server thread?
  • run()
  • start()
  • runThread()
  • startThread()
  • run()
    264 Which of these method is called when http daemon is acting like a normal web server?
  • Handle()
  • HandleGet()
  • handleGet()
  • Handleget()
  • handleGet()
    265 Which of these standard collection classes implements a dynamic array?
  • AbstractList
  • LinkedList
  • ArrayList
  • AbstractSet
  • ArrayList
    266 Which of these class can generate an array which can increase and decrease in size automatically?
  • ArrayList()
  • DynamicList()
  • LinkedList()
  • MallocList()
  • ArrayList()
    267 Which of these method of ArrayList class is used to obtain present size of an object?
  • size()
  • length()
  • index()
  • capacity()
  • size()
    268 Which of these methods can be used to obtain a static array from an ArrayList object?
  • Array()
  • convertArray()
  • toArray()
  • convertoArray()
  • toArray()
    269 Which of these method is used to reduce the capacity of an ArrayList object?
  • trim()
  • trimSize()
  • trimTosize()
  • trimToSize()
  • trimToSize()
    270 Map implements collection interface?
  • True
  • False
  • No idea
  • All of the above
  • False
    271 Which of the below does not implement Map interface?
  • HashMap
  • Hashtable
  • EnumMap
  • Vector
  • Vector
    272 What is the premise of equality for IdentityHashMap?
  • Reference equality
  • Name equality
  • Hashcode equality
  • Length equality
  • Reference equality
    273 What happens if we put a key object in a HashMap which exists?
  • The new object replaces the older object
  • The new object is discarded
  • The old object is removed from the map
  • It throws an exception as the key already exists in the map
  • The new object replaces the older object
    274 If two threads access the same hashmap at the same time, what would happen?
  • ConcurrentModificationException
  • NullPointerException
  • ClassNotFoundException
  • RuntimeException
  • ConcurrentModificationException
    275 If large number of items are stored in hash bucket, what happens to the internal structure?
  • The bucket will switch from LinkedList to BalancedTree
  • The bucket will increase its size by a factor of load size defined
  • The LinkedList will be replaced by another hashmap
  • Any further addition throws Overflow exception
  • The bucket will switch from LinkedList to BalancedTree
    276 How can we remove an object from ArrayList?
  • remove() method
  • using Iterator
  • remove() method and using Iterator
  • delete() method
  • remove() method and using Iterator
    277 How to sort elements of ArrayList?
  • Collection.sort(listObj);
  • Collections.sort(listObj);
  • listObj.sort();
  • Sorter.sortAsc(listObj);
  • Collections.sort(listObj);
    278 When two threads access the same ArrayList object what is the outcome of the program?
  • Both are able to access the object
  • ConcurrentModificationException is thrown
  • One thread is able to access the object and second thread gets Null Pointer exception
  • One thread is able to access the object and second thread will wait till control is passed to the second one
  • ConcurrentModificationException is thrown
    279 How is Arrays.asList() different than the standard way of initialising List?
  • Both are same
  • Arrays.asList() throws compilation error
  • Arrays.asList() returns a fixed length list and doesn’t allow to add or remove elements
  • We cannot access the list returned using Arrays.asList()
  • Arrays.asList() returns a fixed length list and doesn’t allow to add or remove elements
    280 What is the difference between length() and size() of ArrayList?
  • length() and size() return the same value
  • length() is not defined in ArrayList
  • size() is not defined in ArrayList
  • length() returns the capacity of ArrayList and size() returns the actual number of elements stored in the list
  • length() returns the capacity of ArrayList and size() returns the actual number of elements stored in the list
    281 Which class provides thread safe implementation of List?
  • ArrayList
  • CopyOnWriteArrayList
  • HashList
  • List
  • CopyOnWriteArrayList
    282 Which of the below is not an implementation of List interface?
  • RoleUnresolvedList
  • Stack
  • AttibuteList
  • SessionList
  • SessionList
    283 What does Collections.emptySet() return?
  • Immutable Set
  • Mutable Set
  • The type of Set depends on the parameter passed to the emptySet() method
  • Null object
  • Immutable Set
    284 What is the relation between hashset and hashmap?
  • HashSet internally implements HashMap
  • HashMap internally implements HashSet
  • HashMap is the interface; HashSet is the concrete class
  • HashSet is the interface; HashMap is the concrete class
  • HashSet internally implements HashMap
    285 What is the difference between TreeSet and SortedSet?
  • TreeSet is more efficient than SortedSet
  • SortedSet is more efficient than TreeSet
  • TreeSet is an interface; SortedSet is a concrete class
  • SortedSet is an interface; TreeSet is a concrete class
  • SortedSet is an interface; TreeSet is a concrete class
    286 What happens if two threads simultaneously modify TreeSet?
  • ConcurrentModificationException is thrown
  • Both threads can perform action successfully
  • FailFastException is thrown
  • IteratorModificationException is thrown
  • ConcurrentModificationException is thrown
    287 What is the unique feature of LinkedHashSet?
  • It is not a valid class
  • It maintains the insertion order and guarantees uniqueness
  • It provides a way to store key values with uniqueness
  • The elements in the collection are linked to each other
  • It maintains the insertion order and guarantees uniqueness
    288 Which of these standard collection classes implements a linked list data structure?
  • AbstractList
  • LinkedList
  • HashSet
  • AbstractSet
  • LinkedList
    289 Which of these classes implements Set interface?
  • ArrayList
  • HashSet
  • LinkedList
  • DynamicList
  • HashSet
    290 Which of these method is used to add an element to the start of a LinkedList object?
  • add()
  • first()
  • AddFirst()
  • addFirst()
  • addFirst()
    291 Which of these method of HashSet class is used to add elements to its object?
  • add()
  • Add()
  • addFirst()
  • insert()
  • add()
    292 Which of these methods can be used to delete the last element in a LinkedList object?
  • remove()
  • delete()
  • removeLast()
  • deleteLast()
  • removeLast()
    293 Which of this method is used to change an element in a LinkedList Object?
  • change()
  • set()
  • redo()
  • add()
  • set()
    294 Which of these object stores association between keys and values?
  • Hash table
  • Map
  • Array
  • String
  • Map
    295 Which of these classes provide implementation of map interface?
  • ArrayList
  • HashMap
  • LinkedList
  • DynamicList
  • HashMap
    296 Which of these method is used to remove all keys/values pair from the invoking map?
  • delete()
  • remove()
  • clear()
  • removeAll()
  • remove()
    297 Which of these method Map class is used to obtain an element in the map having specified key?
  • search()
  • get()
  • set()
  • look()
  • get()
    298 Which of these methods can be used to obtain set of all keys in a map?
  • getAll()
  • getKeys()
  • keyall()
  • keySet()
  • keySet()
    299 Which of these method is used add an element and corresponding key to a map?
  • put()
  • set()
  • redo()
  • add()
  • put()
    300 Which of these class object can be used to form a dynamic array?
  • ArrayList
  • Map
  • Vector
  • ArrayList & Vector
  • ArrayList & Vector

    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.