Podcast
Questions and Answers
What is the purpose of the .equals() method in Java?
What is the purpose of the .equals() method in Java?
What is the difference between ArrayList and arrays in Java?
What is the difference between ArrayList and arrays in Java?
What is the difference between method overloading and method overriding in Java?
What is the difference between method overloading and method overriding in Java?
Study Notes
Java Interview Questions and Answers
-
Java is a high-level programming language based on object-oriented principles, developed by James Gosling in 1982.
-
Java is platform-independent due to the compiler converting code to byte code that can run on multiple systems.
-
Java supports primitive data types and is not a pure object-oriented language.
-
Stack memory is assigned to individual programs, while heap memory is available for use by the program during runtime.
-
Java does not use pointers, which can cause potential errors and compromise security.
-
Instance variables are accessible by all methods in a class, while local variables are restricted to the block scope.
-
The .equals() method is used to compare values in objects, while the == operator compares memory location.
-
Infinite loops run infinitely without breaking conditions, and constructors can be overloaded to create multiple constructors with different parameters.
-
Method overloading is possible by introducing different methods in the same class with the same name but differing in the number or type of parameters.
-
Method overriding is possible when two methods with the same method signature are present in two different classes with an inheritance relationship.
-
Comparator is an interface in Java used to sort lists based on specific values.
-
Strings in Java are immutable, residing in the heap section of memory, and can pose security risks. Priority levels in Java include MIN_PRIORITY, MAX_PRIORITY, and NORM_PRIORITY.Java Tricky Interview Questions
-
Java threads with MAX_PRIORITY get the first chance to execute, but the default priority is NORM_PRIORITY assigned by JVM.
-
The super() keyword must be the first statement in a block, so using this() and super() in the same block will throw a compilation error.
-
Java works as "pass by value" and not "pass by reference", but when an object is passed, the address of the value is passed due to the nature of object handling in Java.
-
The "IS-A" relationship is another name for inheritance, where inheriting the base class from the derived class forms a relationship between the classes.
-
StringBuffer is preferred over String in cases of frequent updates/modifications to reduce the creation of multiple string objects in the string pool.
-
Overloading main() method will not execute all the overloaded methods, but only one based on its declaration in JVM.
-
Main() threads in Java multithreading are always non-daemon threads and cannot be changed to daemon threads.
-
When an exception occurs, it searches to locate the matching catch block, and if not found, the program gets terminated in the main method.
-
ArrayList stores non-primitive data types in various memory locations, while arrays store object or primitive type values in contiguous memory locations.
-
LinkedList is preferred over ArrayList for deleting elements from either end or front of the linked list as it requires less adjustment of references.
-
Synchronization is used to resolve issues when multiple threads require the same shared resource, and it ensures that the resource is shared by a single thread at a time.
-
The System.exit() method immediately terminates the program and does not execute the finally block.
-
Marker interfaces or tagging interfaces are used to provide runtime-related information regarding objects, and they have no methods and constants defined in them.Java Programming Concepts and Examples
-
Supplementary characters in a string are counted as 2 units in the length() function, leading to inaccuracies.
-
The use of single quotes in a program results in the concatenation of ASCII values of characters, while double quotes would have concatenated the letters.
-
Different approaches can be used to make objects eligible for garbage collection in Java, including nullifying references and creating an "island of isolation" between objects.
-
The recommended approach for dependency injection is to use constructors for mandatory dependencies and setters for optional ones.
-
Spring Bean supports five scopes for setting the lifespan of a bean.
-
Memory leaks can occur when unused objects are still referenced, preventing the garbage collector from removing them.
-
Causes of memory leaks include threads that hold locks and not releasing them, even after calling sleep().
-
Fibonacci numbers and string sorting algorithms are commonly used in Java programming.
-
The formula for finding the sum of n natural numbers can be used to find a missing number in an array.
-
Custom exception classes can be created to handle errors in Java programs.
-
Matrix rotation, prime number finding, and Tower of Hanoi algorithms are other common examples of Java programming concepts.
-
Java is a popular programming language known for its powerful tools, impressive standards, and threading support. The language is widely used in software development due to its stability and ease of use.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
This quiz contains a variety of Java interview questions and answers, covering topics such as Java programming concepts, tricky Java interview questions, and more. Whether you're preparing for a Java job interview or just looking to brush up on your knowledge, this quiz has something for everyone. Test your understanding of Java's object-oriented principles, memory management, and multithreading capabilities. You'll also learn about common Java programming algorithms and techniques, as well as best practices for writing efficient, high-quality Java code.