
Prepare for core Java interviews with a curated collection of interview questions and detailed explanations from diverse Java developers.
Compare string and StringBuffer: string is immutable, StringBuffer is mutable and faster for concatenations, while StringBuffer is synchronized and string is not, with + working only on string.
Compare StringBuffer and StringBuilder to understand thread safety and performance trade-offs. Choose StringBuffer for thread-safe operations, while StringBuilder offers better performance; both are mutable.
Explain how Java's object law governs hashCode and equals, showing that equal objects have matching hashcodes, and that overriding equals requires overriding hashCode.
Explain interface features in Java, including public static final variables and abstract methods by default. Java 8 adds default and static methods, main method inside interfaces, and no Object inheritance.
Learn how to call a super class constructor in Java with super(), why it must be the first statement, and how Bowler extends Player to invoke the parent constructor.
If a subclass does not call a superclass constructor, the superclass's no-argument constructor runs automatically; if that constructor doesn't exist, the compiler errors unless the subclass uses super with arguments.
Explain nested and regular inner classes as full-fledged outer-class members with access modifiers and optional abstract or final modifiers, and how to instantiate them using an outer-class reference.
Explain method-local inner classes defined inside a method, including their instantiation and the rule that they cannot access non-final variables or use access modifiers; they can be abstract or final.
Explain the protected access modifier, showing access within the same package and by all subclasses, while non-subclasses in different packages cannot access protected members, as Vehicle and Car illustrate.
Explore the enhanced for loop, a compact form of iteration for arrays and collections, and see how it makes code easier to read and write.
Explore scenarios where a finally block may not run, such as when the JVM exits during try or catch, or when the executing thread is interrupted or killed.
discover how varargs simplify adding multiple numbers by using the final argument position, allowing a sequence of arguments or an array, without overloading methods.
Explain automatic garbage collection by identifying in-use versus unreferenced objects in heap memory and reclaiming memory. The JVM destroys eligible objects, and you can request collection via System.gc() or Runtime.getRuntime().gc().
Serialization converts an object's state to a platform independent byte stream, enabling persistence. Objects become serializable by implementing java.io.Serializable or java.io.Externalizable.
Learn how the iterator replaces Enumeration in the Java collections framework, enabling removal of elements during iteration with well-defined semantics, via hasNext, next, and remove methods.
Learn how to sort an ArrayList using the Comparator interface by creating comparator classes, implementing compare for id and name, and passing them to Collections.sort.
Explore whether enumeration is fail-fast by examining a scenario where a collection changes during iteration, causing no exception and revealing that enumeration is not fail-fast.
Vector is synchronized, allowing one thread at a time, unlike ArrayList which is not. Vector supports Enumeration and Iterator; ArrayList uses only Iterator, with Vector slower due to synchronization.
Explore NavigableSet, a sorted set with navigation methods like lower, floor, higher, and ceiling, plus pollFirst and pollLast, to retrieve or remove boundary elements in ascending order.
Explain the default toString() behavior in Java when not overridden: it returns the class name followed by '@' and the toHexString of the hashCode, with a Student example.
Explore the BlockingQueue interface, focusing on blocking put and take, and the timed offer and poll variants for producer-consumer patterns in a thread-safe arrayblockingqueue.
Explore how NavigableMap extends SortedMap and is implemented by TreeMap and ConcurrentSkipListMap, and examine navigation methods such as lowerEntry, floorEntry, lowerKey, floorKey, and ceilingKey.
CopyOnWriteArrayList is a thread-safe variant of ArrayList in java.util.concurrent, where mutative operations copy the underlying array; iterators operate on a snapshot, not reflecting concurrent changes.
Observe how fail-fast iterators throw ConcurrentModificationException on structural modification after creation, whereas fail-safe iterators on concurrent collections avoid the exception by updating on a separate copy.
Declare a generic class by placing a type parameter after the class name in angle brackets. Use a type argument to form a parameterized type and instantiate with new.
Describe the thread life cycle from new to dead, covering ready-to-run, running, sleeping, waiting, and blocked states such as I/O, join, lock acquisition, and notifications.
Explain how wait() and notify() drive producer-consumer synchronization with synchronized blocks, object locks, and handling illegal monitor state exceptions during thread wake-up.
Learn Java class naming conventions by using noun class names in mixed case, with each internal word capitalized, keeping names simple and descriptive, avoiding acronyms.
Learn how to declare multiple classes in one .java file, ensuring one class shares the file name and at most one public class matches the file name.
Explore two synchronization approaches in Java: synchronized methods and synchronized blocks, with threads acquiring locks on BankAccount objects for addAmount and withdrawAmount, and on myString for getBalance.
Explain how the interrupt() method signals a thread to stop and how a thread responds through its own interruption handling, potentially terminating or continuing based on its code.
Explain how nested classes in Java group classes that are used in one place. Show how encapsulation is enhanced by hiding nested classes inside their outer classes.
Learn how the Java compiler does not create a default no-argument constructor when a class defines a parameterized constructor, as shown by the Configuration example.
explain why static methods cannot be overridden in Java. Static methods are hidden in subclasses with the same signature, and calls are resolved at compile time by reference type.
Use static imports in Java to access static members without qualifying with their class. Use them sparingly; overuse harms readability and pollutes the namespace, so import only needed members.
Define immutable objects by preventing state changes after construction, using private final fields, no setters, and final classes. Copy mutable references to avoid external modification, a strategy for concurrent applications.
Explore how the executor interface decouples task submission from execution mechanics like thread use and scheduling. Learn how to use executor.execute() to run Runnable tasks without creating threads.
Explains how executorService.shutdown initiates an orderly shutdown, letting previously submitted tasks run while rejecting new ones and not waiting for their completion, with the main thread continuing.
Explain how awaitTermination blocks until all tasks finish after shutdown, or a timeout occurs, or the thread is interrupted. Returns true if terminated, otherwise false on timeout.
Learn how the scheduled executor service extends executor service to schedule runnable or callable tasks with relative delays and periods, including schedule, scheduleAtFixedRate, and scheduleWithFixedDelay.
Explore the java.util.concurrent Executors class, offering factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory, and Callable with configurable options.
CompletionService decouples task production from result consumption, enabling processing of completed tasks in order of completion via take from a queue of futures inside an executor service.
Explain how the cancel() method of the Future class cancels execution, using a boolean argument to decide interruption (true to interrupt, false to not), and returns true or false.
Explore tight coupling and loose coupling in object oriented design through a Journey example with Car and bike, using a Vehicle interface to decouple changes.
Explore restrictions on Java generics, including no primitive type instantiation, no type-parameter instances, no static fields with type parameters, no casts or instanceof, and no arrays of parameterized types.
Explore how private methods in interfaces boost code reusability by encapsulating common functionality for default methods, reducing redundancy in interfaces such as SubjectPrinter.
Demonstrate using the diamond operator with anonymous classes, enabled from Java 9, with a practical example that shows how it works.
Explore implicit casting as automatic type conversion when types are compatible and the target type is larger, illustrated by an integer cast to long.
Describe how string literals are stored in the string constant pool on the heap and reused if identical, while new String() creates a separate heap object with no reuse.
Compare the == operator and the equals() method in Java, showing that == checks memory location while equals() compares object values.
Explain the Externalizable interface and its custom serialization, showing how writeExternal and readExternal control which fields, like name and age, are stored while dateOfBirth is ignored.
Learn exception handling best practices, including logging and not hiding errors, declaring and catching specific exceptions, avoiding flow control with exceptions, standardizing logging, and wrapping stack traces in custom exceptions.
Name the methods of an object class, including clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, and wait. These describe cloning, garbage-collection, runtime class, hash codes, and inter-thread synchronization.
Understand when a Java collection throws UnsupportedOperationException by exploring unmodifiable list views, fixed-size lists from asList, and why add on these lists is not supported.
Shows that with Serializable, the no-argument constructor is not invoked during deserialization, while with Externalizable, the constructor is invoked, illustrated via an Employee example.
Compare the lock interface with synchronized blocks, showing flexible locking, multiple condition objects, and hand-over-hand techniques, and learn non-blocking and timed acquisitions like tryLock and lockInterruptibly.
Choose string types based on mutability and concurrency: use String for constants, and StringBuffer or StringBuilder for concatenation; use StringBuilder for single thread access and StringBuffer for multiple thread access.
Learn the five object creation methods in Java: new, Class.newInstance, Constructor.newInstance, clone, and deserialization, where clone does not invoke constructors and deserialization bypasses constructors.
Explore exception chaining by wrapping lower-layer exceptions with custom exceptions across DAO, service, and main layers, preserving the stack trace from the lowest to the highest layer.
Develop the collection of core java interview questions by gathering and analyzing java developers' interview experiences, then add the curated questions to this course.
If you are a Java Developer working in a software company, and if you are interested in switching to a higher company either for the purpose of growth, or for the purpose of hike, then the first challenge you will be facing is an Interview.
No matter how many years of experience you have, or how expert you are in Java, clearing a Java interview requires calculated planning and preparation.
In general, you may have to revise all concepts of Core Java, and then assess yourself with the help of sets of Interview questions collected from various sources.
Revising all concepts of core java with perfection, is not as easy as you think.
More specifically speaking, if you have been working on particular areas of java for a long time, then it definitely takes time to conceptually revise all the topics, especially the topics on which you have not been working on.
What if an interview is scheduled in next 2 days, or in next 2 weeks?
The situation turns into a nightmare if you do not have appropriate sources which help you get through, in just 2 days.
The only source which helps you in these situations, is none other than a set or a Collection of Core Java Interview questions, which includes interview questions collected from various Java developers based on their interview experiences.
This Course, "Core Java Interview Questions" aims to provide you the same.
You get a Collection of Core java interview Questions, which includes interview questions collected from various Java developers based on their interview experiences, with indetail explanations, and the questions also cover all concepts of CoraJava.
Note that number of Questions you get is open ended.
Whenever an interview questions comes to our notice, we just add it in the set with indetail explanation.
Hence, by purchasing this course, you are obtaining something which helps you through out your Java Development Journey.
And finally, this course comes with a 30-days Money back guarantee.
Hence, there is really nothing you loose.
I am super excited to see you enrolled in this Course.
Thank You!