top of page

Core Java Quiz

Updated: Nov 1, 2023

Core Java Quiz

Java remains one of the most popular and versatile programming languages in the world, and as such, Java interviews often include a wide range of topics to assess a candidate's proficiency. This guide is designed to help you prepare core Java Interview Questions thoroughly and confidently, covering both fundamental and advanced Java concepts.

1. When is "this" used in Java? i: Differentiating between instance variables and local variables ii. To enable method chaining iii: For both

2. key ideas of Functional Programming Paradigm: i. In FP, functions are treated as first-class citizens

ii. In FP, data is treated as immutable

iii. Pure functions are central to FP

iv. Functional code often follows a declarative style

v. All the above four options vi. Options 2, & 3

3. Uses of Optional class in Java? i. Used to handle potential null values and reduce the risk of NullPointerException by providing a container that can hold either a non-null value or be empty.

ii. Used for creating and managing custom exceptions in your code.

iii. Used to force variables to be declared as final, making them immutable.

4. Explain the concept of immutability in functional programming

i. Immutability in functional programming allows objects to be modified freely, making it easier to change their properties as needed.

ii. Immutability in functional programming refers to the practice of making all variables in a program constant, preventing any changes to their values.

iii. Immutability means that once an object is created, its state cannot be changed. Immutable objects are safe to use in concurrent environments

5. Explain the concept of referential transparency property of the function in functional programming.

i. Referential transparency allows a function to have unpredictable outputs based on its inputs, making it a key feature of functional programming.

ii. Referential transparency in functional programming means that a function's output is solely determined by its inputs, it has no side effects, and it can be replaced with its result without changing the program's behavior.

iii. Referential transparency is the property of a function that encourages side effects and dependencies on external resources for reliable execution.

6. To achieve lazy evaluation in Java functional programming, instead of executing the computation immediately, you can wrap it in a lambda and execute it only when the result is needed. is this statement correct?

i. No

ii. Yes

7. What is currying, and how can it be implemented in Java using lambdas i. Currying is a technique in Java that allows you to combine multiple functions into a single function, simplifying code and improving performance.

ii. Currying is a functional programming technique where a function that takes multiple arguments is transformed into a series of functions, each taking a single argument. In Java using lambdas, you can implement currying by creating a chain of lambda functions, each taking one argument and returning another lambda until all arguments are consumed, and the final result is computed.

iii. Currying in Java using lambdas involves creating complex data structures to store function arguments, making code more convoluted and less readable.

Core Java Quiz

8. What is the difference between eager and lazy evaluation in the context of stream processing?

i. Eager evaluation in stream processing processes elements sequentially, while lazy evaluation processes elements in parallel.

ii. Eager evaluation in stream processing is more memory-efficient than lazy evaluation.

iii. Eager evaluation in stream processing processes elements as soon as an operation is invoked, whereas lazy evaluation defers processing until it's actually needed, typically when a terminal operation is invoked.

Answers: 1. (iii) 2. (v)

3. (i)

4. (iii)

5. (ii)

6. (ii)

7. (ii)

8. (iii)

26 views0 comments


bottom of page