0% found this document useful (0 votes)
8 views10 pages

Comprog PreFi Reviewer

The document outlines the IT2402 Comprehensive Exam, consisting of multiple-choice questions covering topics such as Java input/output, control structures, strings, and arrays, along with essay questions. It includes 105 multiple-choice questions divided into sections on input/output, control structures, and strings & arrays, as well as 5 essay questions. The exam tests knowledge on Java programming concepts, syntax, and functionalities.

Uploaded by

Studio Code
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)
8 views10 pages

Comprog PreFi Reviewer

The document outlines the IT2402 Comprehensive Exam, consisting of multiple-choice questions covering topics such as Java input/output, control structures, strings, and arrays, along with essay questions. It includes 105 multiple-choice questions divided into sections on input/output, control structures, and strings & arrays, as well as 5 essay questions. The exam tests knowledge on Java programming concepts, syntax, and functionalities.

Uploaded by

Studio Code
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/ 10

IT2402 Comprehensive Exam

Multiple Choice (105 items):

Input/Output (15 items)

1. Which of the following is NOT a valid Java input method from the
Scanner class?
a) nextInt()
b) nextLine()
c) nextChar()
d) nextDouble()

2. What is the purpose of System.out.println()?


a) Reads input from the user
b) Prints output to the console and moves the cursor to the
next line
c) Prints output to the console without moving the cursor
d) Clears the console

3. Which class is necessary for keyboard input in Java?


a) System
b) Scanner
c) Input
d) Output

4. What package does the Scanner class belong to?


a) java.io
b) java.lang
c) java.util
d) java.input

5. What is the purpose of a prompt in a Java program?


a) To display the program's output
b) To instruct the user what input is expected
c) To store user input
d) To perform calculations

6. What is the output of System.out.print("Hello");


System.out.print("World!");?
a) Hello\nWorld!
b) HelloWorld!
c) Hello World!
d) Hello World_\n
7. What character is used to terminate a Java statement?
a) :
b) .
c) ,
d) ;

8. Which keyword is used to import all classes from a package?


a) import all
b) *
c) include
d) package

9. What is System.in used for?


a) Console output
b) Keyboard input
c) File input
d) Network input

10. What is the default output device in Java?


a) Printer
b) Monitor
c) File
d) Network

11. What does ln in println stand for?


a) long
b) line
c) link
d) literal

12. What does API stand for?


a) Application Programming Interface
b) Advanced Programming Interface
c) Application Processing Interface
d) Advanced Processing Interface

13. What is the purpose of the new keyword in Java?


a) To declare a variable
b) To create an object
c) To define a method
d) To import a class
14. Which method reads an entire line of text from the console?
a) next()
b) nextLine()
c) nextInt()
d) nextDouble()

15. What is the output of the following code:

System.out.print("One");

System.out.println("Two");

System.out.print("Three");

a) OneTwo\nThree

b) One\nTwoThree

c) OneTwoThree

d) One\nTwo\nThree

(Control Structures - 25 items)

1. Which of these is NOT a selection statement?


a) if
b) if-else
c) switch
d) while

2. What is the purpose of an else block?


a) To execute code if the if condition is true
b) To execute code if the if condition is false
c) To loop through a block of code
d) To exit a loop

3. Which keyword is used to exit a switch statement?


a) exit
b) return
c) break
d) continue
4. What data types can a switch statement evaluate?
a) byte, short, int, long, float, double, boolean, String
b) byte, short, char, int
c) All primitive data types
d) Only integer types

5. What keyword is used for the default case in a switch statement?


a) else
b) default
c) case other
d) otherwise

6. What type of statement is a while loop?


a) Selection statement
b) Repetition statement
c) Branching statement
d) Control statement

7. When does a do-while loop check its condition?


a) Before executing the loop body
b) After executing the loop body
c) In the middle of the loop body
d) Never

8. Which loop is best when the number of iterations is known in advance?


a) while
b) do-while
c) for
d) All of the above

9. What does the initialization expression in a for loop do?


a) Sets the initial value of the loop variable
b) Tests the loop condition
c) Increments/decrements the loop variable
d) Exits the loop

10. What happens if you put a semicolon immediately after the for
loop parentheses?
a) The loop body is executed once
b) The loop body is executed infinitely
c) The loop body is not executed at all
d) A compile-time error occurs.
11. What is a nested loop?
a) A loop that contains another loop inside its body
b) A loop that never terminates
c) A loop that contains multiple conditions
d) A loop that uses multiple loop variables

12. Which keyword is used to immediately exit a loop?


a) break
b) continue
c) return
d) exit

13. What does the continue keyword do?


a) Exits the loop entirely
b) Skips the current iteration and proceeds to the next
c) Restarts the loop from the beginning
d) Pauses the loop execution

14. What keyword returns control to the caller of a method?


a) break
b) continue
c) return
d) go back

15. Which of the following is a valid return statement for a method


declared as void?
a) return 0;
b) return;
c) return null;
d) return void;

16. What happens when a return statement is executed within a


method?
a) The method continues execution
b) The program terminates
c) Control is returned to the calling method
d) An error occurs

(True/False Questions - 10 Items): Convert to Multiple Choice

1. A switch statement can have duplicate case labels.


a) True
b) False
2. A while loop will always execute at least once.
a) True
b) False

3. The continue keyword is used to exit a loop entirely.


a) True
b) False

4. A for loop can have multiple initialization expressions.


a) True
b) False

5. The break statement can only be used inside loops.


a) True
b) False

(Strings & Arrays - 55 items)

1. What class is used to work with strings in Java?


a) String
b) Text
c) Character
d) Array

2. What is the index of the first character in a Java string?


a) 1
b) 0
c) -1
d) It depends on the string

3. What are string literals in Java?


a) Variables that store strings
b) Constant string values enclosed in double quotes
c) Methods that operate on strings
d) Special characters in strings

4. Which keyword is used to create a String object?


a) string
b) new
c) create
d) object

5. What is a constructor in Java?


a) A method that performs a specific operation on an object
b) A block of code that initializes a newly created object
c) A keyword used to declare a new variable
d) A special type of loop

6. What does the String() constructor create?


a) A string with a default value
b) An empty string
c) A null string
d) A copy of another string

7. What is the purpose of the charAt() method?


a) To get the length of a string
b) To get the character at a specified index
c) To concatenate two strings
d) To compare two strings

8. What does the trim() method do?


a) Removes leading and trailing spaces
b) Removes all spaces from a string
c) Converts a string to lowercase
d) Converts a string to uppercase

9. Which method replaces occurrences of a character in a string?


a) replace()
b) change()
c) substitute()
d) switch()

10. What does the equals() method return if two strings have the
same characters in the same order?
a) true
b) false
c) 0
d) 1

11. Which method converts a String to lowercase?


a) lowercase()
b) toLowerCase()
c) toLower()
d) makeLower()

12. Which method returns the length of a String?


a) size()
b) length()
c) count()
d) getSize()

13. Which method joins two strings together?


a) join()
b) concat()
c) append()
d) merge()

14. What does the indexOf() method return?


a) The length of a string.
b) The index of the first occurrence of a character or substring.
c) The index of the last occurrence of a character or substring.
d) The number of times a character appears in the string.

15. What does the compareTo() method do?


a) Concatenates two strings.
b) Compares two strings lexicographically.
c) Checks if two strings are equal.
d) Replaces characters in a string.

16. What is an array in Java?


a) A primitive data type.
b) A collection of elements of the same data type.
c) A class for performing mathematical operations.
d) A type of loop.

17. How are array elements accessed?


a) By their name.
b) By their index.
c) By their value.
d) By their data type.

18. What is the default value of elements in a newly created int


array?
a) null
b) 1
c) 0
d) -1

19. What is an initializer list for an array?


a) A list of methods that operate on the array
b) A list of initial values for the array elements
c) A list of indexes for the array
d) A list of different data types that can be stored in the array

20. Which of the following is a valid way to declare an array variable?


a) int[] myArray;
b) int myArray[];
c) int [] myArray;
d) All of the above

21. What does the new operator do when used with arrays?
a) Declares a new array variable
b) Allocates memory for the array
c) Initializes the array elements
d) Accesses an element in the array

22. What type of loop is commonly used to initialize array elements?


a) while loop
b) do-while loop
c) for loop
d) enhanced for loop

23. What is a multi-dimensional array?


a) An array that can store different data types.
b) An array of arrays.
c) An array with a dynamic size.
d) An array that can only store primitive data types.

Essay (5 items):

1. Explain the difference between System.out.print() and


System.out.println(). Provide examples.

2. Describe the three components of a for loop (initialization, test,


increment/decrement) and their roles in loop execution.

3. Explain the difference between the break and continue keywords within
a loop structure. Give practical examples.

4. Describe the concept of string immutability in Java. What implications


does this have for string manipulation?

5. Explain the difference between one-dimensional and two-dimensional


arrays in Java. Provide examples of how each type is declared and
used.

You might also like