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 is not a method in the ‘String’ class?

Java MCQ: Which of the following is not a method in the ‘String’ class? a) length() b) substring() c) equalsIgnoreCase() d) size() Answer: d) size() Explanation: The Java String class provides a variety of methods for manipulating and inspecting strings. Common methods include length() for getting the length of the string, substring() for extracting a […]

Which of the following is not a method in the ‘String’ class? Read More »

Which of the following is not a valid method for converting a string to an integer in Java?

Java MCQ: Which of the following is not a valid method for converting a string to an integer in Java? a) Integer.parseInt() b) Integer.valueOf() c) String.toInt() d) None of the above Answer: c) String.toInt() Explanation: In Java, there are several ways to convert a string to an integer. The Integer.parseInt() method is commonly used to

Which of the following is not a valid method for converting a string to an integer in Java? Read More »

Which of the following is not a feature of Java?

Java MCQ: Which of the following is not a feature of Java? a) Dynamic b) Platform-independent c) Machine-dependent d) Multithreaded Answer: c) Machine-dependent Explanation: Java is designed to be platform-independent, meaning that Java programs can run on any device or operating system that has the Java Virtual Machine (JVM) installed. This “write once, run anywhere”

Which of the following is not a feature of Java? Read More »

Which of the following is used to compare the contents of two objects in Java?

Java MCQ: Which of the following is used to compare the contents of two objects in Java? a) == operator b) equals() method c) compareTo() method d) hashCode() method Answer: b) equals() method Explanation: In Java, the equals() method is used to compare the contents of two objects. Unlike the == operator, which compares the

Which of the following is used to compare the contents of two objects in Java? Read More »

Which of the following is true about the ‘abstract’ keyword in Java?

Java MCQ: Which of the following is true about the ‘abstract’ keyword in Java? a) Abstract classes cannot be instantiated b) Abstract methods do not have a body c) A class must be declared abstract if it contains abstract methods d) All of the above Answer: d) All of the above Explanation: The abstract keyword

Which of the following is true about the ‘abstract’ keyword in Java? Read More »

Which of the following interfaces is used to handle events in Java?

Java MCQ: Which of the following interfaces is used to handle events in Java? a) Runnable b) Serializable c) EventListener d) Cloneable Answer: c) EventListener Explanation: The EventListener interface in Java is used to handle events. It is a marker interface that all event listener interfaces must extend. Event listeners are objects that are notified

Which of the following interfaces is used to handle events in Java? Read More »

Which of the following is not a type of inheritance in Java?

Java MCQ: Which of the following is not a type of inheritance in Java? a) Single inheritance b) Multiple inheritance through classes c) Multilevel inheritance d) Hierarchical inheritance Answer: b) Multiple inheritance through classes Explanation: In Java, multiple inheritance through classes is not supported. This means a class cannot inherit from more than one class.

Which of the following is not a type of inheritance in Java? Read More »

Which of the following is true about Java’s ‘String’ class?

Java MCQ: Which of the following is true about Java’s ‘String’ class? a) Strings are immutable b) Strings can be changed after they are created c) Strings are a primitive data type d) Strings are thread-unsafe by default Answer: a) Strings are immutable Explanation: In Java, the String class represents a sequence of characters. One

Which of the following is true about Java’s ‘String’ class? Read More »

Which of the following statements is true about the ‘static’ keyword in Java?

Java MCQ: Which of the following statements is true about the ‘static’ keyword in Java? a) Static methods can access instance variables directly b) Static methods belong to the class, not instances c) Static methods can override instance methods d) Static methods can be abstract Answer: b) Static methods belong to the class, not instances

Which of the following statements is true about the ‘static’ keyword in Java? Read More »

Which access modifier is used to allow access to members of a class within the same package but not from outside?

Java MCQ: Which access modifier is used to allow access to members of a class within the same package but not from outside? a) private b) protected c) public d) default Answer: d) default Explanation: In Java, when no access modifier is specified for a class member, the default access level is package-private, also known

Which access modifier is used to allow access to members of a class within the same package but not from outside? Read More »

Which of the following is not a feature of Java?

Java MCQ: Which of the following is not a feature of Java? a) Platform-independent b) Object-oriented c) Pointers d) Secure Answer: c) Pointers Explanation: Java is a platform-independent, object-oriented, and secure programming language, but it does not support pointers. Pointers are used in languages like C and C++ to directly access memory addresses, but Java

Which of the following is not a feature of Java? Read More »

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

Java MCQ: Which of the following statements is true about constructors in Java? a) Constructors can be abstract b) Constructors can be final c) Constructors cannot be synchronized d) Constructors do not return any value Answer: d) Constructors do not return any value Explanation: Constructors in Java are special methods used to initialize objects. They

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

Scroll to Top