Java Programming

Java is a high-level, object-oriented programming language developed by Sun Microsystems in the mid-1990s. It adheres to the “Write Once, Run Anywhere” (WORA) principle, ensuring platform independence via the Java Virtual Machine (JVM).

Java is a widely used programming language for coding web applications. It has been a popular choice among developers for over two decades, with millions of Java applications in use today. Java is a multi-platform, object-oriented, and network-centric language that can be used as a platform in itself. It is a fast, secure, reliable programming language for coding everything from mobile apps and enterprise software to big data applications and server-side technologies.

How does the sendAsync() method in Java 11 HttpClient differ from the send() method?

Java MCQ: How does the sendAsync() method in Java 11 HttpClient differ from the send() method? a) It sends requests over a different protocol b) It sends requests asynchronously, returning a CompletableFuture c) It sends requests faster d) It sends requests in batches Answer: b) It sends requests asynchronously, returning a CompletableFuture Explanation: The sendAsync()

How does the sendAsync() method in Java 11 HttpClient differ from the send() method? Read More »

What is the return type of the send() method in the Java 11 HttpClient class?

Java MCQ: What is the return type of the send() method in the Java 11 HttpClient class? a) HttpResponse b) String c) Future d) void Answer: a) HttpResponse Explanation: The send() method in the Java 11 HttpClient class returns an instance of HttpResponse. This method is used to send an HTTP request synchronously, meaning that

What is the return type of the send() method in the Java 11 HttpClient class? Read More »

Which method is used to create a new instance of HttpClient in Java 11?

Java MCQ: Which method is used to create a new instance of HttpClient in Java 11? a) HttpClient.create() b) HttpClient.newBuilder() c) HttpClient.newHttpClient() d) HttpClient.getInstance() Answer: c) HttpClient.newHttpClient() Explanation: The HttpClient.newHttpClient() method is used to create a new instance of HttpClient in Java 11. This method returns a default HttpClient that can be used to send

Which method is used to create a new instance of HttpClient in Java 11? Read More »

What does the Local-Variable Syntax for Lambda Parameters in Java 11 allow you to do?

Java MCQ: What does the Local-Variable Syntax for Lambda Parameters in Java 11 allow you to do? a) Define local variables in lambda expressions b) Use the var keyword to declare the types of lambda parameters c) Use instance variables inside lambda expressions d) Automatically infer the types of lambda parameters Answer: b) Use the

What does the Local-Variable Syntax for Lambda Parameters in Java 11 allow you to do? Read More »

What does the Optional.orElseThrow() method introduced in Java 10 do?

Java MCQ: What does the Optional.orElseThrow() method introduced in Java 10 do? a) Returns the contained value if present, otherwise throws NoSuchElementException b) Returns the contained value if present, otherwise returns null c) Returns the contained value if present, otherwise returns a default value d) Returns the contained value if present, otherwise throws IllegalStateException Answer:

What does the Optional.orElseThrow() method introduced in Java 10 do? Read More »

How does the Collectors.toUnmodifiableMap() method handle duplicate keys in Java 10?

Java MCQ: How does the Collectors.toUnmodifiableMap() method handle duplicate keys in Java 10? a) It merges the values associated with duplicate keys b) It throws an IllegalStateException c) It ignores duplicate keys d) It keeps only the first occurrence of the key Answer: b) It throws an IllegalStateException Explanation: The Collectors.toUnmodifiableMap() method, introduced in Java

How does the Collectors.toUnmodifiableMap() method handle duplicate keys in Java 10? Read More »

Which Java 10 feature allows you to collect elements into an unmodifiable list using Collectors?

Java MCQ: Which Java 10 feature allows you to collect elements into an unmodifiable list using Collectors? a) Collectors.toUnmodifiableSet() b) Collectors.toUnmodifiableMap() c) Collectors.toUnmodifiableList() d) Collectors.toImmutableList() Answer: c) Collectors.toUnmodifiableList() Explanation: The Collectors.toUnmodifiableList() method, introduced in Java 10, allows you to collect elements into an unmodifiable list. This method is part of the java.util.stream.Collectors class and is

Which Java 10 feature allows you to collect elements into an unmodifiable list using Collectors? Read More »

What is the behavior of the Map.copyOf() method introduced in Java 10 when invoked with a map containing null keys or values?

Java MCQ: What is the behavior of the Map.copyOf() method introduced in Java 10 when invoked with a map containing null keys or values? a) It removes the null keys or values from the map b) It replaces null keys or values with empty strings c) It throws a NullPointerException d) It converts null keys

What is the behavior of the Map.copyOf() method introduced in Java 10 when invoked with a map containing null keys or values? Read More »

How does the Set.copyOf() method introduced in Java 10 behave when given a null argument?

Java MCQ: How does the Set.copyOf() method introduced in Java 10 behave when given a null argument? a) It returns an empty set b) It throws a NullPointerException c) It creates a set with a null element d) It ignores the null argument Answer: b) It throws a NullPointerException Explanation: The Set.copyOf() method, introduced in

How does the Set.copyOf() method introduced in Java 10 behave when given a null argument? Read More »

What is the behavior of the Map.of() method when invoked with duplicate keys?

Java MCQ: What is the behavior of the Map.of() method when invoked with duplicate keys? a) It merges the values of the duplicate keys b) It replaces the previous key with the new one c) It throws an IllegalArgumentException d) It removes the duplicate key Answer: c) It throws an IllegalArgumentException Explanation: The Map.of() method

What is the behavior of the Map.of() method when invoked with duplicate keys? Read More »

Which method in Java 9 is used to create an immutable Map with a variable number of key-value pairs?

Java MCQ: Which method in Java 9 is used to create an immutable Map with a variable number of key-value pairs? a) Map.put() b) Map.ofEntries() c) Map.copyOf() d) Map.of() Answer: d) Map.of() Explanation: The Map.of() method introduced in Java 9 is used to create an immutable Map with a variable number of key-value pairs. This

Which method in Java 9 is used to create an immutable Map with a variable number of key-value pairs? Read More »

What happens if you use the Java 9 List.of() method with null elements?

Java MCQ: What happens if you use the Java 9 List.of() method with null elements? a) It creates a List with null elements b) It creates a List and removes the null elements c) It throws a NullPointerException d) It converts null elements to empty strings Answer: c) It throws a NullPointerException Explanation: Using the

What happens if you use the Java 9 List.of() method with null elements? Read More »

Which statement is true about private methods in interfaces introduced in Java 9?

Java MCQ: Which statement is true about private methods in interfaces introduced in Java 9? a) They can be called from outside the interface b) They can only be called within default or static methods of the same interface c) They must be overridden by implementing classes d) They are automatically public Answer: b) They

Which statement is true about private methods in interfaces introduced in Java 9? Read More »

What is a key advantage of using Java modules introduced in Java 9?

Java MCQ: What is a key advantage of using Java modules introduced in Java 9? a) They allow for direct memory access b) They enable better encapsulation and modularization of code c) They improve exception handling d) They increase the speed of the garbage collector Answer: b) They enable better encapsulation and modularization of code

What is a key advantage of using Java modules introduced in Java 9? Read More »

Scroll to Top