1.
The ____ is the brain of the computer.
Correct Answer
B. Central processing unit
Explanation
The central processing unit (CPU) is often referred to as the brain of the computer because it is responsible for executing instructions and performing calculations. It controls and coordinates all the other components of the computer, including the input and output devices, memory, and storage. The CPU contains the arithmetic logic unit (ALU), which performs mathematical and logical operations, as well as the control unit, which manages the flow of data and instructions. The accumulator is a register within the CPU that stores intermediate results during calculations.
2.
All data must be brought into ____ before a program can manipulate it.
Correct Answer
B. Main memory
Explanation
Before a program can manipulate data, it must be brought into main memory. Main memory, also known as primary memory or RAM (Random Access Memory), is the primary storage location in a computer where data and instructions are stored temporarily while the program is running. This allows the processor to quickly access and manipulate the data. Secondary storage, such as hard drives or solid-state drives, is used for long-term storage and is not directly accessible by the processor. Output devices are used to display or present the manipulated data, but they do not store it. Therefore, the correct answer is main memory.
3.
When the power is switched off, everything in ____ is lost.
Correct Answer
A. Main memory
Explanation
When the power is switched off, everything in main memory is lost. Main memory, also known as RAM (Random Access Memory), is a volatile type of memory that stores data and instructions that are actively being used by the computer. It is a temporary storage location and requires continuous power supply to retain the data. Once the power is switched off, the data stored in main memory is erased, and the computer starts fresh when powered on again. Therefore, any unsaved work or data in main memory will be lost when the power is turned off.
4.
The devices that feed data and programs into computers are called ____.
Correct Answer
B. Input devices
Explanation
Input devices are the devices that are used to feed data and programs into computers. These devices allow users to interact with the computer and input information or commands. Examples of input devices include keyboards, mice, scanners, and microphones. Output devices, on the other hand, are used to display or present the processed information from the computer, such as monitors or printers. Therefore, the correct answer is "input devices".
5.
The term MB refers to ____.
Correct Answer
A. Megabyte
Explanation
MB stands for Megabyte, which is a unit of digital information storage equal to 1,048,576 bytes. It is commonly used to measure the size of files, documents, and data storage capacity. Therefore, the correct answer is Megabyte.
6.
A program called a(n) ____ translates the assembly language instructions into machine language and then executes it.
Correct Answer
B. Interpreter
Explanation
An interpreter is a program that translates the assembly language instructions into machine language and then executes it. Unlike a compiler, which translates the entire program before execution, an interpreter translates and executes the code line by line. This allows for immediate feedback and easier debugging. A loader is responsible for loading the program into memory, while an assembler translates assembly language into machine language. Therefore, the correct answer is interpreter.
7.
In a Java program, the file name must be the same as the ____.
Correct Answer
B. Class name
Explanation
In a Java program, the file name must be the same as the class name. This is because Java follows a naming convention where the file name and the class name should match. This allows the Java compiler to easily locate and load the class when the program is executed. If the file name and the class name do not match, the compiler will throw an error.
8.
When all ____ errors are removed, the compiler generates the machine code (bytecode in Java).
Correct Answer
B. Syntax
Explanation
When all syntax errors are removed, the compiler is able to generate the machine code or bytecode in Java. Syntax errors refer to mistakes in the structure or grammar of the code, such as missing semicolons or incorrect variable declarations. Once these errors are fixed, the code becomes syntactically correct and can be compiled into executable machine code.
9.
Which word is not a reserved word (Keyword)?
Correct Answer
A. Load
Explanation
The word "load" is not a reserved word or keyword in programming languages. Reserved words are predefined words that have special meanings and cannot be used as variable names or identifiers. However, "float", "public", and "static" are reserved words in many programming languages, including Java and C++.
10.
To develop a program to solve a problem, you start by ____.
Correct Answer
A. Analyzing the problem
Explanation
To develop a program to solve a problem, the first step is to analyze the problem. This involves understanding the requirements, constraints, and objectives of the problem. By analyzing the problem, you can identify the inputs, outputs, and the necessary steps to solve it. This initial analysis helps in designing an effective solution and choosing the appropriate programming language and algorithm to implement it.
11.
In Java, the mechanism that allows you to combine data and operations on the data into a single unit is called a(n) ____.
Correct Answer
C. Method
Explanation
In Java, a method is a mechanism that allows you to combine data and operations on the data into a single unit. Methods are used to perform specific actions on objects and can be called to execute a block of code. They provide a way to organize and encapsulate functionality within a class, making code more modular and reusable. Therefore, the correct answer for this question is method.
12.
The ____ rules of a programming language tell you which statements are legal, or accepted by the programming language.
Correct Answer
C. Syntax
Explanation
The syntax rules of a programming language define the structure and format of valid statements in the language. These rules determine whether a statement is written correctly according to the language's grammar and punctuation. Syntax errors occur when a statement violates these rules and are usually detected by the compiler or interpreter. Therefore, the correct answer is "syntax."
13.
Which of the following is NOT a special symbol in Java?
Correct Answer
B. #
Explanation
In Java, the special symbols include +, !=, and ?. However, # is not considered a special symbol in Java. It is commonly used in other programming languages like C or C++ to indicate preprocessor directives, but in Java, it does not have any special meaning or usage.
14.
Which of the following identifiers is not valid?
Correct Answer
D. 5sum
Explanation
The identifier "5sum" is not valid because identifiers in programming languages cannot start with a number. They must start with a letter or an underscore.
15.
Oranges = oranges * (expression);
is equivalent to
oranges *= expression;
Correct Answer
A. True
Explanation
The given statement is true because the shorthand operator "*=" is used to multiply the value of the variable "oranges" by the value of "expression" and assign the result back to "oranges". This is equivalent to the first statement "oranges = oranges * (expression)". Therefore, both statements have the same effect of updating the value of "oranges" by multiplying it with "expression".
16.
Primitive Data types in Java do not include:
Correct Answer
D. Decimal
Explanation
The primitive data types in Java include integral (byte, short, int, long), floating point (float, double), and boolean. However, decimal is not a primitive data type in Java. Decimal values are typically represented using the non-primitive data type BigDecimal, which provides more precise decimal calculations.
17.
Integral Data Types in Java do not include:
Correct Answer
D. Double
Explanation
Integral data types in Java are used to store whole numbers without any fractional parts. They include char, long, and int. However, double is not an integral data type in Java. It is a floating-point data type that can store numbers with decimal places. Therefore, the correct answer is double.
18.
A null or empty string has at least one character that is a space.
Correct Answer
B. False
Explanation
This statement is false because a null or empty string does not have any characters, including spaces. A null string refers to a variable that has not been assigned a value, while an empty string refers to a string with no characters. In both cases, there are no spaces or any other characters present.
19.
Named constants
Correct Answer(s)
A. They cannot be changed during program execution
B. They are declared using the reserved word final
C. They are initialized when they are declared
D. They should be created in all capital letters
Explanation
Named constants are values that cannot be changed during program execution. They are declared using the reserved word final, meaning their value cannot be modified once assigned. Named constants are also initialized when they are declared, meaning they are given an initial value when they are defined. Additionally, it is a convention to create named constants in all capital letters to easily distinguish them from variables.
20.
Int num1;
The statement above declares and initializes the value of num1.
Correct Answer
B. False
Explanation
Initializing the value means you make the variable equal to something.
i.e.
int num1 = 15;
21.
Which of the following methods would you use to read in a number such as 2.3 for a variable?
Correct Answer
C. NextDouble();
Explanation
To read in a number such as 2.3 for a variable, the most appropriate method to use would be nextDouble(). This method is specifically designed to read in double values from the input. next() would only read in the next token as a string, nextInt() would only read in the next token as an integer, and nextLine() would read in the entire line as a string. Therefore, nextDouble() is the correct method to use in this scenario.
22.
The value of the expression 26 – 14 % 3 + 1 is ____.
Correct Answer
D. 25
Explanation
The expression is evaluated using the order of operations. First, the modulo operator (%) is applied, giving a result of 2. Then, the subtraction and addition operators are applied, giving a final result of 25.
23.
Which of the following is a legal identifier?
Correct Answer
B. Program_1
Explanation
A legal identifier is a name that can be used to identify a variable, function, or any other programming entity. It must follow certain rules, such as starting with a letter or underscore, and can only contain letters, numbers, or underscores. In this case, "program_1" is a legal identifier because it starts with a letter, followed by letters and an underscore, which follows the rules for identifiers in programming languages.
24.
Which of the following is a valid int value?
Correct Answer
B. 46259
Explanation
A valid int value is a whole number without any decimal points. Therefore, the only option that fits this criteria is 46259. The other options either have decimal points or commas, which make them invalid int values.
25.
Consider the following sequence of statements.
String str;
int num1, num2;
num1 = 13;
num2 = 24;
str = "The sum = " + num1 + num2;
What is the final value stored in str?
Correct Answer
D. The sum = 1324
Explanation
The final value stored in str is "The sum = 1324" because the concatenation operator (+) is used to combine the string "The sum = " with the values of num1 and num2. Since num1 and num2 are both integers, they are converted to strings before being concatenated. Therefore, the final result is the string "The sum = " followed by the string representations of num1 and num2, which are "13" and "24" respectively.
26.
What is the output of the following statement?
System.out.println("Welcome \n Home");
Correct Answer
C. Welcome
Home
Explanation
The output of the given statement is "Welcome Home". This is because the statement is using the println() method to print the string "Welcome Home" to the console. The println() method adds a new line after printing the string, so the output will be displayed on separate lines.
27.
Which of the following is the correct syntax for commenting in Java?
Correct Answer
C. /* Enter Comments Here*/
Explanation
The correct syntax for commenting in Java is /* Enter Comments Here */. This syntax allows you to comment out multiple lines of code or add a comment on a single line. The other options (#, ', **) are not valid syntax for commenting in Java.
28.
Suppose x = 2 and y = 3. If the statement
x *= y;
is executed once, what is the value of x?
Correct Answer
D. 6
Explanation
The statement "x *= y" is a compound assignment operator that multiplies the value of x by the value of y and then assigns the result back to x. In this case, since x is initially 2 and y is 3, the value of x after executing the statement will be 6.
29.
Suppose that you have the following figure.
According to this figure, str contains ____.
Correct Answer
C. The address 2500
Explanation
Based on the given figure, it can be inferred that "str" contains the address 2500. This is because the figure represents a memory diagram, and the arrow pointing to "str" indicates that it is storing the memory address 2500.
30.
What is the value of the following statement?
Math.pow(2,4)
Correct Answer
C. 16.0
Explanation
The Math.pow() function in JavaScript is used to raise a number to a certain power. In this case, Math.pow(2,4) means 2 raised to the power of 4. So, the value of this statement is 16.0, as 2^4 equals 16.
31.
An expression such as str.length(); is an example of a(n) ____.
Correct Answer
D. Method call
Explanation
The expression "str.length();" is an example of a method call. In this case, the method "length()" is being called on the string object "str" to retrieve the length of the string.
32.
Which of the following outputs 56734.987 to three decimal places?
Correct Answer
B. System.out.printf(".3f%", 56734.9875);
Explanation
The correct answer is System.out.printf(".3f%", 56734.9875);. This is because the ".3f" format specifier in the printf statement specifies that the output should be formatted as a floating-point number with three decimal places.
33.
Which of the following statements would produce the figure above?
Correct Answer
A. Name = JOptionPane.showInputDialog("Enter your name and press OK");
Explanation
The correct answer is "name = JOptionPane.showInputDialog("Enter your name and press OK");". This statement would produce a dialog box with a text field where the user can enter their name and press OK.
34.
What would be output by the following statement:
Assume that
int num1 = 12;
int num2 = 26;
str = "The sum = " + (num1 + num2);
Correct Answer
A. "The sum = 38";
Explanation
The output of the given statement would be "The sum = 38". This is because the statement assigns the string "The sum = " concatenated with the sum of num1 and num2 (which is 38) to the variable str.
35.
Which escape sequence is used for a tab space?
Correct Answer
C. \t
Explanation
The escape sequence \t is used for a tab space.
36.
Which package needs to be imported to read and write to outside files?
Correct Answer
A. Java.io
Explanation
The correct answer is java.io. The java.io package in Java provides classes for input and output operations, including reading and writing to external files. This package contains classes such as FileReader, FileWriter, BufferedReader, BufferedWriter, and many others that are essential for file handling in Java. Therefore, to read and write to outside files, the java.io package needs to be imported.
37.
This type of variable stores the address of the object containing the data
Correct Answer
B. Reference
Explanation
A reference variable in programming is used to store the address of an object that contains data. Unlike primitive variables that store the actual value, a reference variable holds a reference or pointer to the memory location where the object is stored. This allows us to access and manipulate the data within the object through the reference variable. Therefore, the given correct answer is "reference".
38.
An object is an instance of a class and the operator new is used to instantiate an object
.
Correct Answer
A. True
Explanation
In object-oriented programming, an object is created by instantiating a class using the "new" operator. This means that the "new" operator is used to allocate memory for the object and initialize its attributes and methods based on the class definition. Therefore, the given statement is true.
39.
To use a predefined method you must know
Correct Answer(s)
A. Name of the class containing method (i.e. Math)
B. Name of the package containing class (i.e. java.lang)
C. Name of the method & the parameters
Explanation
To use a predefined method, you must know the name of the class containing the method (e.g. Math), the name of the package containing the class (e.g. java.lang), and the name of the method along with its parameters. These pieces of information are necessary to correctly call and utilize the predefined method in your code.
40.
Dot (.) Operator: used to access the method in the class
Correct Answer
A. True
Explanation
The dot (.) operator is used to access the method in a class. This means that by using the dot operator, we can call or invoke a method that is defined within a class. Therefore, the statement "Dot (.) Operator: used to access the method in the class" is true.
41.
String variables are reference variables
Correct Answer
A. True
Explanation
In Java, string variables are reference variables because they store the memory address of the actual string object rather than the value itself. This means that when we assign a string to a variable, the variable holds a reference to the memory location where the string is stored. This allows us to manipulate and access the string using the variable.
42.
A String object is an instance of class String
Correct Answer
A. True
Explanation
The statement is true because in Java, a String object is indeed an instance of the class String. In object-oriented programming, a class is a blueprint for creating objects, and an instance is a specific object created from that blueprint. Therefore, when we create a String object in Java, we are creating an instance of the String class.
43.
To convert a string consisting of an integer to a value of the type int, we use the following expression:
Correct Answer
A. Integer.parseInt(strExpression)
Explanation
The correct answer is Integer.parseInt(strExpression) because this expression is used to convert a string consisting of an integer to an int value. The parseInt() method parses the string argument as a signed decimal integer and returns the corresponding int value.
44.
Integer, Float, and Double are classes designed to convert a numeric string into a number
These classes are called _________________ classes
Correct Answer
A. Wrapper
Explanation
The Integer, Float, and Double classes are known as wrapper classes. These classes provide methods and functionality to convert a numeric string into the respective number type (integer, float, or double). Wrapper classes are used to wrap primitive data types and provide additional methods and functionality that are not available in the primitive types.
45.
What is the value of the following?
double x = 15.674;
double y = 235.73;
String.format("%.2f ",x)
Correct Answer
A. 15.67
Explanation
The correct answer is 15.67. The code uses the String.format() method to format the value of variable x as a string with 2 decimal places. Since x is 15.674, it will be rounded down to 15.67.