Java Ch 1-3 Test

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Tcarteronw
T
Tcarteronw
Community Contributor
Quizzes Created: 38 | Total Attempts: 32,005
| Attempts: 229 | Questions: 47
Please wait...
Question 1 / 47
0 %
0/100
Score 0/100
1. Match the following values
Submit
Please wait...
About This Quiz
Java Ch 1-3 Test - Quiz

Ch1-3 Test Java assesses foundational computer hardware knowledge, focusing on components like the central processing unit, main memory, and input devices. It evaluates understanding of data management and... see morebasic computer operations, essential for learners in computer science. see less

2. The ____ is the brain of the computer.

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.

Submit
3.   An object is an instance of a class and the operator new is used to instantiate an object .

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.

Submit
4. Oranges = oranges * (expression); is equivalent to oranges *= expression;

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".

Submit
5.   A String object is an instance of class String

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.

Submit
6. To convert a string consisting of an integer to a value of the type int, we use the following expression:

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.

Submit
7. Which of the following is a valid int value?

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.

Submit
8. Which of the following is the correct syntax for commenting in Java?

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.

Submit
9. The term MB refers to ____.     

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.

Submit
10. In a Java program, the file name must be the same as the ____.

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.

Submit
11. Which escape sequence is used for a tab space?

Explanation

The escape sequence \t is used for a tab space.

Submit
12. Which of the following identifiers is not valid?

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.

Submit
13. Named constants

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.

Submit
14. Which of the following methods would you use to read in a number such as 2.3 for a variable?

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.

Submit
15.
  The value of the expression 26 – 14 % 3 + 1 is ____.

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.

Submit
16.   What would be output by the following statement: Assume that int num1 = 12; int num2 = 26; str = "The sum = " + (num1 + num2);  

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.

Submit
17.   Dot (.) Operator: used to access the method in the class

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.

Submit
18. What is the value of the following? double x = 15.674; double y = 235.73;  String.format("%.2f ",x)

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.

Submit
19. The devices that feed data and programs into computers are called ____.

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".

Submit
20.   String variables are reference variables

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.

Submit
21. A null or empty string has at least one character that is a space.

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.

Submit
22. Which of the following is a legal identifier?

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.

Submit
23. Suppose x = 2 and y = 3.  If the statement x *= y; is executed once, what is the value of x?

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.

Submit
24. 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?

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.

Submit
25. What is the output of the following statement? System.out.println("Welcome \n 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.

Submit
26. Which of the following outputs 56734.987 to three decimal places?

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.

Submit
27. The ____ rules of a programming language tell you which statements are legal, or accepted by the programming language.

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."

Submit
28. This type of variable stores the address of the object containing the data

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".

Submit
29. Int num1; The statement above declares and initializes the value of num1.

Explanation

Initializing the value means you make the variable equal to something.
i.e.
int num1 = 15;

Submit
30. What is the value of the following statement?   Math.pow(2,4)

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.

Submit
31. To develop a program to solve a problem, you start by ____.

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.

Submit
32. To use a predefined method you must know

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.

Submit
33. When all ____ errors are removed, the compiler generates the machine code (bytecode in Java).

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.

Submit
34. An expression such as str.length(); is an example of a(n) ____.

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.

Submit
35. Which word is not a reserved word (Keyword)?  

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++.

Submit
36. Which package needs to be imported to read and write to outside files?

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.

Submit
37. When the power is switched off, everything in ____ is lost.

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.

Submit
38. Suppose that you have the following figure. mc038-1.jpg According to this figure,  str contains ____.

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.

Submit
39. Primitive Data types in Java do not include:

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.

Submit
40. Which of the following is NOT a special symbol in Java?

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.

Submit
41. Which of the following statements would produce the figure above?

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.

Submit
42. Match the following terms:
Submit
43. Integral Data Types in Java do not include:

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.

Submit
44.   Integer, Float, and Double are classes designed to convert a numeric string into a number These classes are called _________________ classes

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.

Submit
45. All data must be brought into ____ before a program can manipulate it.

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.

Submit
46. In Java, the mechanism that allows you to combine data and operations on the data into a single unit is called a(n) ____.

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.

Submit
47. A program called a(n) ____ translates the assembly language instructions into machine language and then executes it.

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.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 20, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 28, 2011
    Quiz Created by
    Tcarteronw
Cancel
  • All
    All (47)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Match the following values
The ____ is the brain of the computer.
 ...
Oranges = oranges * (expression);...
  A String object is an instance of class String
To convert a string consisting of an integer to a value of the type...
Which of the following is a valid int value?
Which of the following is the correct syntax for commenting in Java?
The term MB refers to ____.     
In a Java program, the file name must be the same as the ____.
Which escape sequence is used for a tab space?
Which of the following identifiers is not valid?
Named constants
Which of the following methods would you use to read in a...
  ...
 ...
  Dot (.) Operator: used to access the method in the class
What is the value of the following?...
The devices that feed data and programs into computers are called...
  String variables are reference variables
A null or empty string has at least one character that is a...
Which of the following is a legal identifier?
Suppose x = 2 and y = 3.  If the statement ...
Consider the following sequence of statements....
What is the output of the following statement?...
Which of the following outputs 56734.987 to three decimal places?
The ____ rules of a programming language tell you which statements are...
This type of variable stores the address of the object containing the...
Int num1;...
What is the value of the following statement?   Math.pow(2,4)
To develop a program to solve a problem, you start by ____.
To use a predefined method you must know
When all ____ errors are removed, the compiler generates the machine...
An expression such as str.length(); is an example of a(n) ____.
Which word is not a reserved word (Keyword)?  
Which package needs to be imported to read and write to outside files?
When the power is switched off, everything in ____ is lost.
Suppose that you have the following figure. ...
Primitive Data types in Java do not include:
Which of the following is NOT a special symbol in Java?
Which of the following statements would produce the figure above?
Match the following terms:
Integral Data Types in Java do not include:
 ...
All data must be brought into ____ before a program can manipulate it.
In Java, the mechanism that allows you to combine data and operations...
A program called a(n) ____ translates the assembly language...
Alert!

Advertisement