Java - jiquest

add

#

Java

 1. Java Basics and Syntax

  1. Q: What is the difference between JDK, JRE, and JVM?

    • Explain the roles of each in Java development and execution.
  2. Q: What is the difference between a Java source file and a Java class file?

    • Discuss the compilation process from .java to .class.
  3. Q: How does the Java main method signature differ from that in other programming languages?

    • Discuss the significance of public static void main(String[] args).
  4. Q: What are Java identifiers? What are the rules for naming them?

    • Discuss naming conventions and restrictions for identifiers.
  5. Q: Explain the significance of the final keyword in Java.

    • Discuss its usage with classes, methods, and variables.

2. Object-Oriented Programming (OOP) Concepts

  1. Q: What is encapsulation in Java? How do you implement it?

    • Discuss the use of access modifiers and getters/setters.
  2. Q: Explain the concept of inheritance and its advantages in Java.

    • Discuss method overriding and the use of super keyword.
  3. Q: What is polymorphism in Java? Provide examples of method overloading and method overriding.

    • Discuss compile-time and runtime polymorphism.
  4. Q: How does abstraction work in Java?

    • Discuss abstract classes and interfaces, and when to use each.
  5. Q: What is the significance of the this keyword in Java?

    • Discuss its use in constructors and methods.

3. Data Types, Variables, and Operators

  1. Q: What are the differences between primitive and reference data types in Java?

    • Discuss memory allocation, default values, and autoboxing.
  2. Q: How does type conversion and casting work in Java?

    • Discuss implicit and explicit casting, and type promotion rules.
  3. Q: What are Java literals, and how are they used?

    • Discuss different types of literals like integers, floats, characters, and strings.
  4. Q: Explain the difference between == and equals() in Java.

    • Discuss reference equality vs. object equality.
  5. Q: What is the significance of static keyword in Java?

    • Discuss static variables, methods, and static blocks.

4. Control Flow Statements

  1. Q: How does the if-else statement work in Java?

    • Discuss the syntax and nesting of if-else statements.
  2. Q: What is the difference between switch and if-else statements?

    • Discuss the use cases for each and the data types supported by switch.
  3. Q: How do for, while, and do-while loops differ in Java?

    • Discuss syntax, usage, and performance considerations.
  4. Q: What are the different types of break and continue statements in Java?

    • Discuss their usage within loops and switch statements.
  5. Q: Explain the concept of a for-each loop in Java.

    • Discuss its usage with arrays and collections.

5. Arrays and Strings

  1. Q: How do you declare and initialize arrays in Java?

    • Discuss single-dimensional and multi-dimensional arrays.
  2. Q: What is the difference between String, StringBuilder, and StringBuffer in Java?

    • Discuss immutability, performance, and thread-safety.
  3. Q: How does the substring() method work in Java?

    • Discuss the behavior and potential pitfalls related to memory usage.
  4. Q: Explain the concept of string pooling in Java.

    • Discuss how string literals are stored and managed.
  5. Q: How do you reverse a string in Java without using built-in methods?

    • Discuss different approaches like loops, recursion, or using StringBuilder.

6. Collections Framework

  1. Q: What are the main interfaces of the Java Collections Framework?

    • Discuss List, Set, Map, Queue, and their subinterfaces.
  2. Q: How does an ArrayList differ from a LinkedList in Java?

    • Discuss performance, underlying data structures, and use cases.
  3. Q: What is the difference between HashSet and TreeSet in Java?

    • Discuss ordering, performance, and usage scenarios.
  4. Q: Explain how HashMap works internally in Java.

    • Discuss hashing, buckets, collisions, and the role of equals() and hashCode().
  5. Q: What is the difference between Comparable and Comparator in Java?

    • Discuss how each interface is used for sorting and ordering objects.

7. Exception Handling

  1. Q: What are the different types of exceptions in Java?

    • Discuss checked, unchecked, and errors.
  2. Q: How do you implement custom exceptions in Java?

    • Discuss creating a class that extends Exception or RuntimeException.
  3. Q: What is the difference between throw and throws in Java?

    • Discuss their usage in throwing and declaring exceptions.
  4. Q: Explain the concept of try-with-resources in Java.

    • Discuss automatic resource management and AutoCloseable interface.
  5. Q: How would you handle multiple exceptions in a single catch block in Java?

    • Discuss multi-catch block introduced in Java 7.

8. Multithreading and Concurrency

  1. Q: What is the difference between Thread and Runnable in Java?

    • Discuss how to create and start threads using each approach.
  2. Q: Explain the significance of synchronized keyword in Java.

    • Discuss synchronization methods, blocks, and the concept of intrinsic locks.
  3. Q: What is a deadlock in Java, and how can it be avoided?

    • Discuss conditions leading to deadlock and strategies to prevent it.
  4. Q: How does the ExecutorService framework simplify thread management in Java?

    • Discuss the usage of thread pools and task submission methods.
  5. Q: What are volatile variables in Java? How do they differ from synchronized?

    • Discuss visibility guarantees and atomicity concerns.

9. I/O and File Handling

  1. Q: How do you read and write files in Java using FileInputStream and FileOutputStream?

    • Discuss byte streams and handling binary data.
  2. Q: What is the difference between BufferedReader and FileReader in Java?

    • Discuss character streams and performance benefits of buffering.
  3. Q: Explain how serialization works in Java.

    • Discuss the role of Serializable interface and ObjectOutputStream.
  4. Q: How do you implement a file search utility in Java to find files based on a specific pattern?

    • Discuss using File API or NIO with file filters.
  5. Q: What is the significance of the Path and Files classes introduced in Java NIO?

    • Discuss modern file handling and working with file paths.

10. Java 8+ Features

  1. Q: How do lambda expressions work in Java, and what problem do they solve?

    • Discuss functional interfaces and how lambdas improve code readability.
  2. Q: Explain the concept of Streams in Java 8 and how they differ from collections.

    • Discuss lazy evaluation, pipelining, and functional-style operations.
  3. Q: What are Optional objects in Java, and how do they help with null safety?

    • Discuss avoiding NullPointerException and using Optional effectively.
  4. Q: How do you use CompletableFuture for asynchronous programming in Java?

    • Discuss chaining tasks, handling exceptions, and combining futures.
  5. Q: Explain the role of default methods in interfaces. Why were they introduced in Java 8?

    • Discuss backward compatibility and interface evolution.

11. Reflection and Annotations

  1. Q: What is reflection in Java, and how is it used?

    • Discuss introspection, dynamic method invocation, and potential risks.
  2. Q: How would you create and use custom annotations in Java?

    • Discuss defining annotations and processing them with reflection or frameworks.
  3. Q: Explain the difference between checked and runtime annotations.

    • Discuss annotation processing and retention policies.
  4. Q: How does Java’s annotation-based configuration compare to XML-based configuration?

    • Discuss the evolution of configuration practices in Java applications.
  5. Q: What are some common use cases for annotations in Java frameworks like Spring?

    • Discuss dependency injection, transaction management, and declarative configurations.

12. Memory Management and Garbage Collection

  1. Q: How does Java manage memory? Explain the roles of the stack and heap.

    • Discuss memory allocation, scope of variables, and object lifecycle.
  2. Q: What is garbage collection in Java, and how does it work?

    • Discuss different GC algorithms and how they manage object memory.
  3. Q: What is the difference between finalize() and a finalizer method in Java?

    • Discuss the purpose of finalization and its deprecated status.
  4. Q: How do you avoid memory leaks in Java?

    • Discuss common causes of memory leaks and best practices to avoid them.
  5. Q: Explain how the WeakReference and SoftReference classes help manage memory.

    • Discuss use cases where objects should not prevent garbage collection.

13. Design Patterns

  1. Q: What is the Singleton pattern, and how do you implement it in Java?

    • Discuss thread safety, lazy initialization, and double-checked locking.
  2. Q: Explain the Factory Method pattern with an example.

    • Discuss how it promotes loose coupling and enhances code maintainability.
  3. Q: What is the Observer pattern, and how can it be implemented in Java?

    • Discuss event-driven programming and real-time updates.
  4. Q: How does the Strategy pattern work, and when would you use it?

    • Discuss how it promotes flexibility and the principle of “open/closed.”
  5. Q: Explain the concept of dependency injection and how it relates to the Inversion of Control pattern.

    • Discuss using DI frameworks like Spring for managing dependencies.

14. JVM Internals

  1. Q: How does the Java ClassLoader work?

    • Discuss the delegation model, custom class loaders, and dynamic loading.
  2. Q: What is the role of the Java bytecode verifier?

    • Discuss security, type safety, and the integrity of loaded classes.
  3. Q: Explain the difference between JIT compilation and interpretation in Java.

    • Discuss how JIT optimizes runtime performance.
  4. Q: What are JVM tuning parameters, and how do they affect application performance?

    • Discuss tuning the heap size, garbage collection settings, and monitoring tools.
  5. Q: How does the JVM handle exceptions, and what is the structure of an exception stack trace?

    • Discuss how exceptions are propagated and handled at runtime.

15. Testing and Debugging

  1. Q: How do you write unit tests in Java? Explain using JUnit.

    • Discuss test structure, assertions, and annotations like @Test.
  2. Q: What is Test-Driven Development (TDD) in Java, and how do you implement it?

    • Discuss the TDD cycle and benefits of writing tests first.
  3. Q: How do you debug a Java application using an IDE like IntelliJ or Eclipse?

    • Discuss setting breakpoints, stepping through code, and inspecting variables.
  4. Q: What is the role of mocking frameworks like Mockito in unit testing?

    • Discuss creating mock objects, stubbing methods, and verifying interactions.
  5. Q: How do you handle exceptions in test cases to ensure robust testing?

    • Discuss using @Test(expected) and assertThrows for exception testing.

16. Java Ecosystem and Build Tools

  1. Q: How does Maven manage dependencies in a Java project?

    • Discuss the concept of POM files, repositories, and dependency scopes.
  2. Q: What is the difference between Maven and Gradle as build tools?

    • Discuss their build scripts, flexibility, and performance differences.
  3. Q: How would you set up a multi-module project in Maven?

    • Discuss parent POMs, module inheritance, and managing shared dependencies.
  4. Q: Explain the role of Continuous Integration (CI) tools in Java development.

    • Discuss tools like Jenkins, their setup, and benefits in automated builds.
  5. Q: How do you manage external libraries and dependencies in a Java project?

    • Discuss using dependency management tools and handling version conflicts.

17. Java Network Programming

  1. Q: How do you create a simple client-server application in Java using sockets?

    • Discuss creating Socket and ServerSocket objects, and handling I/O streams.
  2. Q: What is the role of URL and URLConnection classes in Java?

    • Discuss sending HTTP requests and handling responses.
  3. Q: How would you implement a multi-threaded server in Java?

    • Discuss handling multiple client connections and threading models.
  4. Q: Explain the difference between TCP and UDP communication in Java.

    • Discuss reliability, ordering, and use cases for each protocol.
  5. Q: How do you handle network timeouts and retries in a Java application?

    • Discuss setting socket options like setSoTimeout() and implementing retry logic.

18. Java Security

  1. Q: How does Java’s security manager work?

    • Discuss restricting operations using security policies and permissions.
  2. Q: What is the role of the java.security package?

    • Discuss cryptography, key management, and secure random number generation.
  3. Q: How would you implement encryption and decryption in Java?

    • Discuss using libraries like JCA/JCE, and symmetric/asymmetric encryption.
  4. Q: What is the role of digital signatures in Java, and how do you create them?

    • Discuss ensuring data integrity and authenticity using Signature class.
  5. Q: How do you secure sensitive data like passwords in a Java application?

    • Discuss hashing with MessageDigest, salt usage, and secure storage.

19. Emerging Technologies

  1. Q: How do you use Java to interact with NoSQL databases like MongoDB?

    • Discuss using drivers or ORM frameworks and performing CRUD operations.
  2. Q: Explain how to build a RESTful web service in Java using JAX-RS.

    • Discuss creating REST endpoints, handling HTTP methods, and serialization.
  3. Q: How do you implement WebSockets in Java for real-time communication?

    • Discuss the WebSocket API and its usage in building interactive applications.
  4. Q: What is the significance of reactive programming in Java, and how is it implemented?

    • Discuss using frameworks like Project Reactor or RxJava.
  5. Q: How does Java support building cloud-native applications?

    • Discuss using Spring Cloud, containerization with Docker, and deployment on Kubernetes.

20. Miscellaneous

  1. Q: How does the enum type work in Java, and what are its advantages?

    • Discuss type safety, methods within enums, and common use cases.
  2. Q: What is the significance of immutability in Java? How do you create an immutable class?

    • Discuss benefits like thread safety and best practices for designing immutable classes.
  3. Q: Explain the concept of method references in Java 8 and how they improve code readability.

    • Discuss different types of method references and their syntax.
  4. Q: How does Java support the creation of cross-platform applications?

    • Discuss Java’s platform-independent bytecode and JVM.
  5. Q: What are some best practices for writing clean, maintainable Java code? - Discuss coding standards, meaningful naming conventions, and the importance of code reviews.