[go: up one dir, main page]

0% found this document useful (0 votes)
3 views7 pages

COMPROG12 Periodical

This document is a 1st periodical examination for the Computer Programming 12 course at Polytechnic College of Davao del Sur. It consists of 60 multiple-choice questions covering various topics in Java programming, including access modifiers, exception handling, JDBC, and string manipulation. Students are instructed to complete the exam within 60 minutes and to write their answers clearly on the provided questionnaire.

Uploaded by

Jay Selibio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

COMPROG12 Periodical

This document is a 1st periodical examination for the Computer Programming 12 course at Polytechnic College of Davao del Sur. It consists of 60 multiple-choice questions covering various topics in Java programming, including access modifiers, exception handling, JDBC, and string manipulation. Students are instructed to complete the exam within 60 minutes and to write their answers clearly on the provided questionnaire.

Uploaded by

Jay Selibio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

POLYTECHNIC COLLEGE OF DAVAO DEL SUR , INC.

McArthur Highway , Barangay Kiagot , Digos City


Tel. No (63) 082-553-3441
www.pcds.edu.ph

COMPUTER PROGRAMMING 12
SENIOR HIGH SCHOOL DEPARTMENT
1ST PERIODICAL EXAMINATION

NAME:______________________________ STRAND/SECTION:______________________
TEACHER: JAY MARCH C. SELIBIO LPT DATE:_________________________________

GENERAL INSTRUCTION: This is a 60 items examination test. You are given 60


minutes to finish the examination. Read, understand and follow directions in
each test item, otherwise, answers will be invalidated. Write your answer on the
test questionnaire provided. Write all answers clearly and neatly.
Multiple Choice (For item 1-60)
DIRECTION: Read and comprehend the ff. statements. Encircle the correct letter of
your choice.
1. What are access modifiers used for in 4. Which of the following methods can be
Java? overridden from the Object class?
a. To define the scope of variables and
methods a. toString()
b. To create new classes b. clone()
c. To perform arithmetic operations c. hashCode()
d. To manage memory allocation d. All of the above

2. Which of the following is the correct use 5. What is the function of package and
of the instance of operator? import statements in Java?
a. To check if an object is an instance of a a. To define the main method
specific class or interface b. To manage dependencies and organize
b. To cast an object to a different type classesl
c. To create a new instance of a class c. To declare variables
d. To compare two objects for equality d. To handle exceptions

3. What is the purpose of virtual method 6. Which access modifier allows a class
invocation in Java? member to be accessible only within its own
package?
a. To call a method directly without any
reference a. public
b. To enable dynamic method dispatch b. private
c. To overload methods in a class c. protected
d. To declare a method as final d. Default (no modifier)
managing namespaces to avoid naming
conflicts.
7. What is the primary purpose of access c. They are necessary for exception
modifiers in Java? handling.
a. To enhance the performance of the d. They determine the access level of
program classes and methods.
b. To control the visibility of classes,
methods, and variables 12. When designing a Java class, what is
c. To manage memory allocation the best practice for using access
d. To define the data types of variables modifiers?

8. Which of the following statements a. Use public for all members to ensure
correctly describes the instance accessibility.
of operator in Java? b. Use private for all members to
a. It is used to create a new instance of a encapsulate data and restrict access.
class. c. Use protected for all members to allow
b. It checks whether an object is an instance inheritance.
of a specific class or subclass. d. Use the appropriate access modifier
c. It is a method for casting primitive types based on the intended visibility and use
d. It is used to compare two objects for case of each member.
equality
13. What is the primary purpose of an
9. In Java, what is the significance of virtual abstract class in Java?
method invocation?
a. To create instances of the class
a. It allows a method to be called without b. To provide a base for subclasses to
being defined in the class. extend
b. It enables dynamic method dispatch, c. To implement all methods
allowing the correct method to be executed d. To store static variables
based on the object type.
c. It is used to create static methods. 14. Which keyword is used to declare a
d. It prevents method overriding constant variable in Java?
a. static
10. Which of the following best describes b. final
the purpose of overriding methods from the c. const
Object class? d. immutable
a. To change the visibility of methods
b. To improve the functionality of classes by 15. What is the correct way to declare a
providing specific implementations for nested class in Java?
methods like toString() and equals() a. class Outer { class Inner {} }
c. To create a new object b. class Inner { class Outer {} }
d. To enhance performance by reducing c. class Outer[] { class Inner {} }
memory usage d. class Outer { Inner class {} }

11. What is the role of package and import 16. Which of the following is a valid
statements in Java? declaration of an enumerated type in Java?
a. They are used to define the main method
a. enum Colors { RED, GREEN, BLUE }
of a program.
b. enum Colors: RED, GREEN, BLUE;
b. They help in organizing classes and
c. Colors enum { RED, GREEN, BLUE } d. Enums are mutable and can be changed
d. Colors { RED, GREEN, BLUE } enum at runtime.

17. What is the purpose of the implements 22. What is the main advantage of using
keyword in Java? generics in Java collections?
a. To create a new class a. It allows the collection to store any type of
b. To inherit from a superclass object without type safety.
c. To define an interface b. It provides compile-time type checking
d. To implement an interface in a class and eliminates the need for casting.
c. It reduces memory consumption by using
18. What is the primary purpose of using primitive types.
abstract classes in Java? d. It makes the code execute faster by
a. To create objects directly from the optimizing algorithms.
abstract class
b. To provide a common interface for 23. What is the purpose of the
subclasses String.format() method in Java?
c. To implement all methods defined in the a. To concatenate two strings
class b. To convert a string to uppercase
d. To prevent the use of inheritance c. To format a string using specified format
specifiers
19. Which statement correctly describes the d. To split a string into an array
use of the static keyword in Java?
a. It allows a variable to be shared among 24. Which of the following statements is
all instances of a class. used to declare that a method may throw an
b. It restricts the variable to be used only exception in Java?
within a method. a. throw
c. It indicates that a variable cannot be b. exception
modified after initialization. c. throws
d. It allows a method to be overridden in a d. try
subclass.
25. What is the primary purpose of the try-
20. What is a benefit of using nested with-resources statement in Java?
classes in Java? a. To create a new thread
b. To automatically close resources after
a. They can access private members of the use
outer class. c. To handle arithmetic exceptions
b. They can be instantiated without an d. To format strings
instance of the outer class.
c. They can replace the need for interfaces. 26. Which keyword is used to create a
d. They are always static in nature. custom exception in Java?
a. catch
21. Which of the following statements is true b. throw
regarding enumerated types in Java? c. extends
a. Enums can only contain primitive data d. assert
types.
b. Enums are a special type of class that 27. What is the function of assertions in
represents a group of constants. Java?
c. Enums cannot have methods or fields. a. To handle runtime exceptions
b. To verify assumptions in the code
c. To format strings c. It is exclusively used for MySQL
d. To declare exceptions databases.
d. It eliminates the need for SQL in Java
28. Which of the following methods can be applications.
used to format a string in Java?
a. String.format() 34. What is the primary role of the
b. StringBuilder.append() RowSetFactory in the JDBC API?
c. String.concat() a. To execute SQL queries directly on the
d. String.trim() database.
b. To create and manage instances of
29. What is the purpose of the throws RowSet objects.
keyword in a method declaration in Java? c. To establish a connection to the
a. To catch exceptions database.
b. To declare that a method may throw an d. To handle exceptions during database
exception operations.
c. To create a new exception
d. To handle multiple exceptions 35. When creating a PreparedStatement,
which of the following is a required step?
30. In Java, what does the try-with- a. Directly executing the SQL query with
resources statement ensure? executeQuery().
a. Resources are opened and closed b. Calling the prepareStatement()
manually method on a Connection object.
b. Resources are automatically closed when c. Closing the Connection object before
the try block exits preparation.
c. Resources can be reused in multiple try d. Using a CallableStatement instead of
blocks PreparedStatement.
d. Resources cannot throw exceptions
36. Which interface would you use to
31. What is an assertion in Java used for? execute stored procedures in a database
a. To create exceptions using JDBC?
b. To test assumptions in the code a. Statement
c. To format strings b. PreparedStatement
d. To handle runtime exceptions c. CallableStatement
32. When creating a custom exception in d. Rowset
Java, which class should your exception 37. In the context of JDBC, what does the
typically extend? RowSet interface allow developers to do?
a. RuntimeException a. Execute SQL commands without a
b. Error database connection.
c. Throwable b. Store a set of rows retrieved from a
d. Exception database and manipulate them.
c. Directly connect to a database without
33. Which of the following statements is true
using a driver.
regarding the JDBC driver?
d. Create new tables in a database.
a. It is used to create Java applications
without a database connection. 38. Which of the following best describes
b. It facilitates the connection between Java the role of the JDBC driver in a Java
applications and various databases. application?
a. It acts as a bridge between the Java 42. Which of the following Java classes can
application and the database. be used to monitor the CPU usage of a
b. It is responsible for executing Java Java application?
bytecode. a. java.lang.Runtime
c. It handles user interface components in b. java.lang.System
the application. c.
d. It compiles Java source code into java.lang.management.ManagementF
bytecode. actory
d. java.nio.file.Files
39. When analyzing the JDBC RowSet
interfaces, what is the primary advantage of 43. When monitoring network I/O using the
using RowSet objects over traditional Java framework, which method would you
ResultSet objects? typically override to capture data transfer
a. RowSet objects are more memory- statistics?
efficient than ResultSet objects. a. read()
b. RowSet objects can work with b. write()
disconnected data and are more flexible in c. connect()
data manipulation. d. accept()
c. RowSet objects are automatically
synchronized with the database. 44. To monitor disk I/O operations in Java,
d. RowSet objects are limited to read-only which of the following classes would you
operations. use to obtain file system statistics?
a. java.nio.file.Path
40. In the context of JDBC, how do b. java.nio.file.Files
PreparedStatement and CallableStatement c.
differ in terms of their use cases? java.lang.management.OperatingSyst
a. PreparedStatement is used for executing emMXBean
static SQL queries, while CallableStatement d. java.util.logging.Logger
is used for executing stored procedures.
b. Both are used for executing dynamic SQL 45. In Java, which of the following is a way
queries only. to monitor virtual memory usage effectively?
c. PreparedStatement can only retrieve a. java.lang.management.MemoryMXBean
data, while CallableStatement can b. java.util.concurrent.atomic.AtomicInteger
manipulate data. c. java.lang.Thread
d. CallableStatement is faster than d. java.net.Socket
PreparedStatement in all scenarios.
46. To tune garbage collection in a Java
41. What is the significance of the application, which JVM option would you
RowSetFactory in the JDBC API? modify to change the maximum heap size?
a. It creates an instance of a database a. -Xmx
connection. b. -Xms
b. It provides a method to create different c. -XX:MaxPermSize
types of RowSet objects. d. -XX:+UseG1GC
c. It manages transactions within the
database. 47. Which of the following Java classes can
d. It acts as a cache for database be utilized to monitor CPU usage in a Java
connections. application?
a. java.lang.Runtime 53. Which of the following statements
b. java.lang.System correctly describes a reference type in
c. Java?
java.lang.management.ManagementF a. A reference type holds a direct value of
actory the variable.
d. java.nio.file.Files b. A reference type points to the memory
location of an object.
48. When analyzing network I/O c. A reference type can only be used with
performance in a Java application, which primitive data types.
method would be most relevant to d. A reference type automatically copies the
investigate the data being sent and object it references.
received?
a. Socket.getOutputStream() 54. What is the primary purpose of using
b. ServerSocket.accept() collection classes in Java?
c. InputStream.read() a. To store simple data types like integers
d. NetworkInterface.getNetworkInterfaces() and characters.
b. To manage groups of objects in a flexible
49. What is the primary purpose of garbage manner.
collection tuning in Java applications? c. To enhance the performance of primitive
a. To enhance the speed of the CPU types.
b. To free up memory and improve d. To perform mathematical operations on
application performance data.
c. To monitor disk I/O operations
d. To manage network connections 55. Which of the following statements best
evaluates the effectiveness of using
50. Which tool can be used to monitor the finalizers in Java for resource
Java Virtual Machine (JVM) and its management?
performance characteristics? a. Finalizers are the most efficient way to
manage resources because they are called
a. JConsole
immediately after an object is no longer
b. VisualVM
reachable.
c. JProfiler
d. All of the above
b. Finalizers can lead to resource leaks and
51. Which of the following is a reference unpredictable behavior, making them a poor
type in Java? choice for managing resources.
a. int
b. boolean
c. String c. Finalizers should always be used to
d. char ensure that objects are cleaned up properly
before garbage collection occurs.
52. What is the purpose of a finalizer in
Java?
a. To finalize the execution of a program d. Finalizers are only useful for cleaning up
b. To perform cleanup before an object is memory but do not affect I/O operations.
garbage collected
c. To declare a variable as constant 56. When considering string efficiency in
d. To finalize the compilation of code Java applications, which of the following
practices would be most effective in
optimizing performance? b. Utilize the StringBuilder class for mutable
a. Using the String class for all string strings.
manipulation tasks without considering c. Create a new String object every time a
alternatives. modification is needed.
d. Store String literals in separate classes.

b. Using StringBuilder or StringBuffer for 59. In designing a multi-threaded Java


concatenation in loops to avoid creating application, which of the following strategies
multiple immutable String objects. would best enhance performance and avoid
potential deadlocks?
a. Use synchronized methods for all thread
c. Regularly converting String objects to interactions.
char[] and back to reduce memory b. Utilize the StringBuilder class for mutable
consumption. strings.
c. Allow threads to run without any
synchronization.
d. Storing all strings in a Vector to manage
d. Use the Thread.sleep() method
their memory usage more effectively.
frequently to pause threads.
57. In evaluating the use of collection
60. How would you design a Java
classes in Java, which statement best
application that efficiently handles I/O
describes their impact on performance in a
operations while ensuring high
multi-threaded environment?
performance?
a. Use blocking I/O operations for file
a. Collection classes are inherently thread- handling.
safe and do not require any b. Implement buffered I/O streams to
synchronization. minimize disk access.
c. Read and write data directly to/from the
disk without buffers.
b. The use of synchronized collection d. Use single-threaded operations for all I/O
classes can degrade performance due to tasks.
contention among threads.

c. All collection classes perform equally in


terms of performance, regardless of the
context.

d. Using raw arrays is always more efficient


than any collection class, regardless of
thread safety.

58. Which of the following approaches


would you take to optimize the use of String
objects in a Java application to improve
memory efficiency?
a. Use String concatenation operations.

You might also like