Advanced Java APIs MCQs

  1. Which of the following is true about Java Networking API?
    a) Provides classes like Socket, ServerSocket
    b) Supports TCP and UDP communication
    c) Uses java.net package
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  2. What will be printed?
    1 import java.net.*;
    2 public class Test {
    3 public static void main(String[] args) throws Exception {
    4 InetAddress addr = InetAddress.getByName("eduinq.com");
    5 System.out.println(addr.getHostName());
    6 }
    7 }
    a) eduinq.com
    b) IP address
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — eduinq.com

  3. Which of the following is true about Socket class?
    a) Used for client connections
    b) Provides input/output streams
    c) Throws IOException on failure
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  4. What will be printed?
    1 import java.net.*;
    2 public class Test {
    3 public static void main(String[] args) throws Exception {
    4 URL url = new URL("http://eduinq.com");
    5 System.out.println(url.getProtocol());
    6 }
    7 }
    a) http
    b) https
    c) eduinq.com
    d) Compilation error
    View Answer

    Correct answer: A — http

  5. Which of the following is true about JDBC?
    a) Provides API for database connectivity
    b) Uses DriverManager to get connections
    c) Supports PreparedStatement for queries
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  6. What will be printed?
    1 import java.sql.*;
    2 public class Test {
    3 public static void main(String[] args) throws Exception {
    4 Class.forName("com.mysql.cj.jdbc.Driver");
    5 System.out.println("Eduinq JDBC Loaded");
    6 }
    7 }
    a) Eduinq JDBC Loaded
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — Eduinq JDBC Loaded

  7. Which of the following is true about PreparedStatement?
    a) Prevents SQL injection
    b) Allows parameterized queries
    c) More efficient than Statement
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  8. What will be printed?
    1 import java.sql.*;
    2 public class Test {
    3 public static void main(String[] args) throws Exception {
    4 Connection con = DriverManager.getConnection("jdbc:h2:mem:eduinq");
    5 PreparedStatement ps = con.prepareStatement("SELECT 1");
    6 ResultSet rs = ps.executeQuery();
    7 rs.next();
    8 System.out.println(rs.getInt(1));
    9 }
    10 }
    a) 1
    b) 0
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — 1

  9. Which of the following is true about REST APIs in Java?
    a) Implemented using frameworks like Spring Boot, JAX RS
    b) Use HTTP methods GET, POST, PUT, DELETE
    c) Return JSON/XML responses
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  10. What will be printed?
    1 import javax.ws.rs.*;
    2 @Path("/eduinq")
    3 public class EduinqService {
    4 @GET
    5 @Produces("text/plain")
    6 public String getMsg() {
    7 return "Eduinq REST";
    8 }
    9 }
    a) Eduinq REST
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq REST

  11. Which of the following is true about JSON handling in Java?
    a) Libraries include Jackson, Gson, org.json
    b) JSON is lightweight data format
    c) Supports serialization and deserialization
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  12. What will be printed?
    1 import com.google.gson.*;
    2 public class Test {
    3 public static void main(String[] args) {
    4 Gson gson = new Gson();
    5 String json = gson.toJson("Eduinq");
    6 System.out.println(json);
    7 }
    8 }
    a) "Eduinq"
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — "Eduinq"

  13. Which of the following is true about XML handling in Java?
    a) Libraries include DOM, SAX, JAXB
    b) XML is hierarchical data format
    c) Supports parsing and binding
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  14. What will be printed?
    1 import javax.xml.parsers.*;
    2 import org.w3c.dom.*;
    3 public class Test {
    4 public static void main(String[] args) throws Exception {
    5 String xml = "<eduinq>Portal</eduinq>";
    6 DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    7 Document doc = db.parse(new java.io.ByteArrayInputStream(xml.getBytes()));
    8 System.out.println(doc.getDocumentElement().getTagName());
    9 }
    10 }
    a) eduinq
    b) Portal
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — eduinq

  15. Which of the following is true about Reflection API?
    a) Allows runtime inspection of classes
    b) Can access private fields/methods
    c) Used in frameworks and tools
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  16. What will be printed?
    1 class Eduinq {
    2 private String name = "Eduinq Reflection";
    3 }
    4 public class Test {
    5 public static void main(String[] args) throws Exception {
    6 Eduinq e = new Eduinq();
    7 java.lang.reflect.Field f = Eduinq.class.getDeclaredField("name");
    8 f.setAccessible(true);
    9 System.out.println(f.get(e));
    10 }
    11 }
    a) Eduinq Reflection
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Reflection

  17. Which of the following is true about Class.forName()?
    a) Loads class dynamically
    b) Initializes static blocks
    c) Used in JDBC driver loading
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  18. What will be printed?
    1 class Eduinq {
    2 static { System.out.println("Eduinq Loaded"); }
    3 }
    4 public class Test {
    5 public static void main(String[] args) throws Exception {
    6 Class.forName("Eduinq");
    7 }
    8 }
    a) Eduinq Loaded
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — Eduinq Loaded

  19. Which of the following is true about Method class in Reflection?
    a) Represents method of class
    b) Provides invoke() method
    c) Can access private methods with setAccessible(true)
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  20. What will be printed?
    1 class Eduinq {
    2 public void show() { System.out.println("Eduinq Method"); }
    3 }
    4 public class Test {
    5 public static void main(String[] args) throws Exception {
    6 Eduinq e = new Eduinq();
    7 java.lang.reflect.Method m = Eduinq.class.getMethod("show");
    8 m.invoke(e);
    9 }
    10 }
    a) Eduinq Method
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Method

  21. Which of the following is true about DatagramSocket?
    a) Used for UDP communication
    b) Provides send() and receive() methods
    c) Does not guarantee delivery
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  22. What will be printed?
    1 import java.net.*;
    2 public class Test {
    3 public static void main(String[] args) throws Exception {
    4 DatagramSocket ds = new DatagramSocket();
    5 System.out.println("Eduinq Datagram Ready");
    6 ds.close();
    7 }
    8 }
    a) Eduinq Datagram Ready
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — Eduinq Datagram Ready

  23. Which of the following is true about URLConnection?
    a) Represents communication link to resource
    b) Provides methods to read/write data
    c) Can set request properties
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  24. What will be printed?
    1 import java.net.*;
    2 public class Test {
    3 public static void main(String[] args) throws Exception {
    4 URL url = new URL("http://eduinq.com");
    5 URLConnection conn = url.openConnection();
    6 System.out.println(conn.getURL());
    7 }
    8 }
    a) http://eduinq.com
    b) eduinq.com
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — http://eduinq.com

  25. Which of the following is true about JDBC transactions?
    a) Managed using Connection object
    b) Supports commit and rollback
    c) Auto commit is true by default
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  26. What will be printed?
    1 import java.sql.*;
    2 public class Test {
    3 public static void main(String[] args) throws Exception {
    4 Connection con = DriverManager.getConnection("jdbc:h2:mem:eduinq");
    5 con.setAutoCommit(false);
    6 System.out.println(con.getAutoCommit());
    7 }
    8 }
    a) false
    b) true
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — false

  27. Which of the following is true about REST annotations in JAX RS?
    a) @Path defines resource URI
    b) @GET, @POST define HTTP methods
    c) @Produces defines response type
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  28. What will be printed?
    1 import javax.ws.rs.*;
    2 @Path("/eduinq")
    3 public class EduinqResource {
    4 @POST
    5 @Produces("text/plain")
    6 public String postMsg() {
    7 return "Eduinq POST";
    8 }
    9 }
    a) Eduinq POST
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq POST

  29. Which of the following is true about JSON parsing with Jackson?
    a) ObjectMapper is main class
    b) Supports readValue() and writeValue()
    c) Handles complex objects
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  30. What will be printed?
    1 import com.fasterxml.jackson.databind.*;
    2 public class Test {
    3 public static void main(String[] args) throws Exception {
    4 ObjectMapper mapper = new ObjectMapper();
    5 String json = "{\"name\":\"Eduinq\"}";
    6 java.util.Map map = mapper.readValue(json, java.util.Map.class);
    7 System.out.println(map.get("name"));
    8 }
    9 }
    a) Eduinq
    b) Portal
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq

  31. Which of the following is true about JAXB?
    a) Java Architecture for XML Binding
    b) Converts Java objects to XML and vice versa
    c) Uses annotations like @XmlRootElement
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  32. What will be printed?
    1 import javax.xml.bind.annotation.*;
    2 @XmlRootElement
    3 class Eduinq {
    4 public String name = "Eduinq JAXB";
    5 }
    a) Eduinq JAXB (when marshalled)
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq JAXB (when marshalled)

  33. Which of the following is true about Reflection constructors?
    a) Represented by Constructor class
    b) Can create new instances
    c) Can access private constructors with setAccessible(true)
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  34. What will be printed?
    1 class Eduinq {
    2 public Eduinq() { System.out.println("Eduinq Constructor"); }
    3 }
    4 public class Test {
    5 public static void main(String[] args) throws Exception {
    6 java.lang.reflect.Constructor<Eduinq> c = Eduinq.class.getConstructor();
    7 Eduinq e = c.newInstance();
    8 }
    9 }
    a) Eduinq Constructor
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Constructor

  35. Which of the following is true about Reflection annotations?
    a) Can be accessed at runtime
    b) Represented by Annotation interface
    c) Useful for frameworks
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  36. What will be printed?
    1 import java.lang.annotation.*;
    2 @Retention(RetentionPolicy.RUNTIME)
    3 @interface EduinqAnno {}
    4 @EduinqAnno
    5 class Eduinq {}
    6 public class Test {
    7 public static void main(String[] args) {
    8 boolean present = Eduinq.class.isAnnotationPresent(EduinqAnno.class);
    9 System.out.println(present);
    10 }
    11 }
    a) true
    b) false
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — true

  37. Which of the following is true about dynamic proxies?
    a) Created at runtime
    b) Implement interfaces
    c) Useful for AOP and logging
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  38. What will be printed?
    1 import java.lang.reflect.*;
    2 interface Eduinq {
    3 void show();
    4 }
    5 class Handler implements InvocationHandler {
    6 public Object invoke(Object proxy, Method m, Object[] args) {
    7 System.out.println("Eduinq Proxy");
    8 return null;
    9 }
    10 }
    11 public class Test {
    12 public static void main(String[] args) {
    13 Eduinq e = (Eduinq) Proxy.newProxyInstance(
    14 Eduinq.class.getClassLoader(),
    15 new Class[]{Eduinq.class},
    16 new Handler());
    17 e.show();
    18 }
    19 }
    a) Eduinq Proxy
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Proxy

  39. Which of the following is true about URLClassLoader?
    a) Loads classes from URLs
    b) Useful for dynamic loading
    c) Can be closed to release resources
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  40. What will be printed?
    1 import java.net.*;
    2 import java.net.URLClassLoader;
    3 public class Test {
    4 public static void main(String[] args) throws Exception {
    5 URL[] urls = {};
    6 URLClassLoader loader = new URLClassLoader(urls);
    7 System.out.println("Eduinq Loader Ready");
    8 }
    9 }
    a) Eduinq Loader Ready
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — Eduinq Loader Ready

  41. Which of the following is true about Proxy class in Reflection?
    a) Creates dynamic proxies
    b) Requires InvocationHandler
    c) Implements interfaces at runtime
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  42. What will be printed?
    1 import java.lang.reflect.*;
    2 interface Eduinq {
    3 void run();
    4 }
    5 class EduinqHandler implements InvocationHandler {
    6 public Object invoke(Object proxy, Method m, Object[] args) {
    7 System.out.println("Eduinq Dynamic Run");
    8 return null;
    9 }
    10 }
    11 public class Test {
    12 public static void main(String[] args) {
    13 Eduinq e = (Eduinq) Proxy.newProxyInstance(
    14 Eduinq.class.getClassLoader(),
    15 new Class[]{Eduinq.class},
    16 new EduinqHandler());
    17 e.run();
    18 }
    19 }
    a) Eduinq Dynamic Run
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Dynamic Run

  43. Which of the following is true about ClassLoader hierarchy?
    a) Bootstrap, Extension, Application loaders
    b) Delegation model
    c) Can be customized
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  44. What will be printed?
    1 class Eduinq {
    2 static { System.out.println("Eduinq Static Block"); }
    3 }
    4 public class Test {
    5 public static void main(String[] args) throws Exception {
    6 Class<?> c = Class.forName("Eduinq");
    7 }
    8 }
    a) Eduinq Static Block
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Static Block

  45. Which of the following is true about Introspector in JavaBeans?
    a) Provides information about bean properties
    b) Uses reflection internally
    c) Useful for frameworks and tools
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  46. What will be printed?
    1 import java.beans.*;
    2 class Eduinq {
    3 private String name;
    4 public String getName() { return name; }
    5 public void setName(String name) { this.name = name; }
    6 }
    7 public class Test {
    8 public static void main(String[] args) throws Exception {
    9 BeanInfo info = Introspector.getBeanInfo(Eduinq.class);
    10 for(PropertyDescriptor pd : info.getPropertyDescriptors()) {
    11 if(pd.getName().equals("name")) {
    12 System.out.println("Eduinq Bean Property Found");
    13 }
    14 }
    15 }
    16 }
    a) Eduinq Bean Property Found
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Bean Property Found

  47. Which of the following is true about ServiceLoader?
    a) Loads service providers dynamically
    b) Uses META INF/services configuration
    c) Provides iterator of implementations
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  48. What will be printed?
    1 import java.util.*;
    2 public interface EduinqService {
    3 void run();
    4 }
    5 public class Test {
    6 public static void main(String[] args) {
    7 ServiceLoader<EduinqService> loader = ServiceLoader.load(EduinqService.class);
    8 for(EduinqService s : loader) {
    9 s.run();
    10 }
    11 System.out.println("Eduinq ServiceLoader Done");
    12 }
    13 }
    a) Eduinq ServiceLoader Done (after running implementations)
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq ServiceLoader Done (after running implementations)

  49. Which of the following is true about Annotation Processing?
    a) Runs at compile time
    b) Uses javax.annotation.processing API
    c) Generates code or metadata
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  50. What will be printed?
    1 import java.lang.annotation.*;
    2 @Retention(RetentionPolicy.RUNTIME)
    3 @interface EduinqAnno {
    4 String value();
    5 }
    6 @EduinqAnno("Portal")
    7 class Eduinq {}
    8 public class Test {
    9 public static void main(String[] args) {
    10 EduinqAnno a = Eduinq.class.getAnnotation(EduinqAnno.class);
    11 System.out.println(a.value());
    12 }
    13 }
    a) Portal
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Portal

Quick Links to Explore