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.

Which of the following best describes the difference between Java Records and Lombok?

Java MCQ: Which of the following best describes the difference between Java Records and Lombok? a) Lombok generates boilerplate code using annotations, while records are a built-in language feature b) Lombok is used only for testing, while records are used in production code c) Lombok is part of the Java standard library, while records are […]

Which of the following best describes the difference between Java Records and Lombok? Read More »

How can Java Records be used with Spring Boot applications?

Java MCQ: How can Java Records be used with Spring Boot applications? a) As a replacement for all Spring Beans b) To define immutable data transfer objects (DTOs) c) To replace all Spring Controllers d) As a substitute for the application.properties file Answer: b) To define immutable data transfer objects (DTOs) Explanation: Java Records can

How can Java Records be used with Spring Boot applications? Read More »

Which of the following is true about the constructors in Java Records?

Java MCQ: Which of the following is true about the constructors in Java Records? a) Records cannot have custom constructors b) Records can only have parameterless constructors c) Records can have custom constructors that validate input or compute derived fields d) Records must have at least two constructors Answer: c) Records can have custom constructors

Which of the following is true about the constructors in Java Records? Read More »

What is the output of the following code snippet involving a Java Record?

Java MCQ: What is the output of the following code snippet involving a Java Record? public record Point(int x, int y) {} public class Main { public static void main(String[] args) { Point p1 = new Point(1, 2); Point p2 = new Point(1, 2); System.out.println(p1.equals(p2)); } } a) true b) false c) Compilation error d)

What is the output of the following code snippet involving a Java Record? Read More »

How do records differ from traditional classes in Java?

Java MCQ: How do records differ from traditional classes in Java? a) Records are mutable by default, while classes are immutable by default b) Records automatically generate methods like equals(), hashCode(), and toString() c) Records cannot implement interfaces d) Records support inheritance, while classes do not Answer: b) Records automatically generate methods like equals(), hashCode(),

How do records differ from traditional classes in Java? Read More »

Which method is used to obtain the superclass of a class using Java Reflection?

Java MCQ: Which method is used to obtain the superclass of a class using Java Reflection? a) getSuperclass() b) getParentClass() c) getBaseClass() d) getSuperClass() Answer: a) getSuperclass() Explanation: The getSuperclass() method in Java is used to obtain the superclass of a class using reflection. This method is part of the Class class and returns a

Which method is used to obtain the superclass of a class using Java Reflection? Read More »

Which utility method in Java Reflection is used to check if a class is an array type?

Java MCQ: Which utility method in Java Reflection is used to check if a class is an array type? a) isArray() b) isArrayType() c) checkArray() d) isArrayClass() Answer: a) isArray() Explanation: The isArray() method in Java is used to check if a class is an array type. This method is part of the Class class

Which utility method in Java Reflection is used to check if a class is an array type? Read More »

How can you access the enum constants of an enum type using Java Reflection?

Java MCQ: How can you access the enum constants of an enum type using Java Reflection? a) getEnumConstants() b) getEnumValues() c) getConstants() d) getEnums() Answer: a) getEnumConstants() Explanation: The getEnumConstants() method in Java is used to access the enum constants of an enum type using reflection. This method is part of the Class class and

How can you access the enum constants of an enum type using Java Reflection? Read More »

How can you retrieve the length of an array using Java Reflection?

Java MCQ: How can you retrieve the length of an array using Java Reflection? a) getArrayLength() b) length() c) getLength() d) arrayLength() Answer: c) getLength() Explanation: The getLength() method in the java.lang.reflect.Array class is used to retrieve the length of an array using Java Reflection. This method is particularly useful when working with arrays of

How can you retrieve the length of an array using Java Reflection? Read More »

Which method is used to create an instance of a class using its constructor with Java Reflection?

Java MCQ: Which method is used to create an instance of a class using its constructor with Java Reflection? a) newInstance() b) create() c) construct() d) build() Answer: a) newInstance() Explanation: The newInstance() method in Java is used to create a new instance of a class using its constructor via reflection. This method is part

Which method is used to create an instance of a class using its constructor with Java Reflection? Read More »

Which method is used to access a private field using Java Reflection?

Java MCQ: Which method is used to access a private field using Java Reflection? a) getField() b) getDeclaredField() c) getPrivateField() d) accessField() Answer: b) getDeclaredField() Explanation: The getDeclaredField() method in Java is used to access a private field of a class using reflection. This method is part of the Class class and returns a Field

Which method is used to access a private field using Java Reflection? Read More »

Which method is used to invoke a method on an object using Java Reflection?

Java MCQ: Which method is used to invoke a method on an object using Java Reflection? a) invokeMethod() b) call() c) execute() d) invoke() Answer: d) invoke() Explanation: The invoke() method in Java is used to invoke a method on an object using reflection. This method is part of the Method class, which is found

Which method is used to invoke a method on an object using Java Reflection? Read More »

Which class is used to obtain information about a class in Java Reflection?

Java MCQ: Which class is used to obtain information about a class in Java Reflection? a) ClassInfo b) ClassInspector c) Class d) ReflectionClass Answer: c) Class Explanation: The Class class in Java is the primary class used to obtain information about a class in Java Reflection. The Class class is part of the java.lang package

Which class is used to obtain information about a class in Java Reflection? Read More »

Which class is used to compress files into ZIP format in Java?

Java MCQ: Which class is used to compress files into ZIP format in Java? a) ZipOutputStream b) ZipFile c) ZipCompressor d) ZipWriter Answer: a) ZipOutputStream Explanation: The ZipOutputStream class in Java is used to compress files into the ZIP format. It is part of the java.util.zip package and provides methods to write compressed data to

Which class is used to compress files into ZIP format in Java? Read More »

Which class is used to read data from a file using DataInputStream in Java?

Java MCQ: Which class is used to read data from a file using DataInputStream in Java? a) DataReader b) DataInputStream c) FileInputStream d) BufferedInputStream Answer: b) DataInputStream Explanation: The DataInputStream class in Java is used to read primitive data types from an input stream in a machine-independent way. It is part of the java.io package

Which class is used to read data from a file using DataInputStream in Java? Read More »

Which method is used to read a file using BufferedInputStream in Java?

Java MCQ: Which method is used to read a file using BufferedInputStream in Java? a) read() b) readBytes() c) readLine() d) readData() Answer: a) read() Explanation: The read() method in Java is used to read data from a file using the BufferedInputStream class. BufferedInputStream is part of the java.io package and is used to read

Which method is used to read a file using BufferedInputStream in Java? Read More »

Scroll to Top