Computer Science Java Quiz

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 Salaheldein
S
Salaheldein
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,614
| Attempts: 1,614 | Questions: 23
Please wait...
Question 1 / 23
0 %
0/100
Score 0/100
1. Pseudocode is:

Explanation

Pseudocode is a formal programming language that is written after the program design phase. It is used by programmers to help map out what a program is supposed to do. It is not actual code that can be executed, but rather a way to outline the logic and structure of a program before writing the actual code. Pseudocode allows programmers to plan and organize their code without worrying about the specific syntax of a programming language.

Submit
Please wait...
About This Quiz
Computer Science Java Quiz - Quiz

This Computer Science Java Quiz assesses knowledge of Java programming fundamentals, including array handling, loop structures, and class organization. It is ideal for learners looking to test their... see moreunderstanding of basic Java concepts and improve their coding skills. see less

2. Which of the following data types are ideal for numbers?

Explanation

Both float and double are ideal data types for representing numbers with decimal points. Float is a 32-bit data type that can store decimal numbers with a precision of up to 7 digits, while double is a 64-bit data type that can store decimal numbers with a precision of up to 15 digits. Boolean is a data type used for representing true/false values, and char is used for representing single characters. Therefore, the correct answer is both a and d, as float and double are suitable for storing numbers.

Submit
3. Each time that a loop "loops" is known as a(n):

Explanation

In programming, a loop is a structure that repeats a certain block of code multiple times. Each repetition of the loop is known as an iteration. Therefore, the correct answer is "iteration".

Submit
4. When should one choose a for() loop instead of a while() loop?

Explanation

A for() loop should be chosen instead of a while() loop when you know the number of times the loop should execute. The for() loop is designed to execute a specific number of times, which is determined by the initialization, condition, and increment/decrement statements within the loop structure. This makes it ideal for situations where the number of iterations is known in advance, such as iterating over arrays or performing a fixed number of calculations.

Submit
5. Which of the following is not a primitive data type?

Explanation

The data types int, double, and char are all primitive data types in programming. They are used to represent basic types of data such as whole numbers, decimal numbers, and individual characters, respectively. However, String is not a primitive data type. It is a class in Java and other programming languages that represents a sequence of characters. Unlike primitive data types, objects of the String class can have methods and properties associated with them.

Submit
6. Which of the following classes is included in the java.util package?

Explanation

The correct answer is Scanner. Scanner is a class included in the java.util package. It is used to read input from various sources like files, strings, and the console. It provides methods to parse primitive types and strings, making it useful for input validation and data extraction.

Submit
7. Which of the following best describes a contructor method?

Explanation

A constructor method is a special type of method in object-oriented programming that is used to initialize objects of a class. It has the same name as the class and does not have a return type. It is typically declared as public and is used to set initial values for the instance variables of the class. Therefore, the answer "A public method that shares the same name as the class, but cannot return a value" accurately describes a constructor method.

Submit
8. Which of the following would be used to import all the classes in the java.awt class?

Explanation

The correct answer is "import java.awt.*;". This statement is used to import all the classes in the java.awt package. The asterisk (*) is a wildcard character that represents all classes in the package. By using this import statement, all the classes in the java.awt package can be accessed without specifying their individual names.

Submit
9. An overloaded method is:

Explanation

An overloaded method is a method with the same name as another method, but with different parameters. This allows multiple methods with the same name to be defined in a class, each with a different set of parameters. The compiler distinguishes between these methods based on the number, type, and order of the parameters. This allows for more flexibility and versatility in method implementation, as different versions of the method can be called depending on the arguments provided.

Submit
10. Refer to the following variable declaration for this question: double[] decimals = {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0}; What does this variable declaration represent?

Explanation

The given variable declaration represents a list. It is an array of double values that stores decimal numbers ranging from 0.1 to 1.0. The use of square brackets and the presence of multiple values indicate that it is a list or an array.

Submit
11. What is the use of the java.awt package?

Explanation

The java.awt package is used for creating user interfaces and for painting graphics and images. This package provides classes and methods for creating windows, buttons, menus, and other graphical components. It also provides functionality for drawing shapes, images, and text on the screen. Therefore, the correct answer is creating user interfaces and for painting graphics and images.

Submit
12. Which of the following most specifically defines a package?

Explanation

A package in Java is a way to organize and group related classes together. It allows for better organization and modularization of code. By grouping classes with a similar purpose, it becomes easier to manage and maintain the codebase. This also helps in avoiding naming conflicts and provides better code reusability. Therefore, the correct answer is "a group of java classes with a similar purpose".

Submit
13. Which of the following would be an example of only declaring a number variable?

Explanation

The correct answer is "double number;" because it only declares a variable named "number" of type double without assigning any value to it. The other options either assign a value to the variable or create a new instance of a float variable.

Submit
14. Which of the following is an example of a call to a method to draw a rectangle that is 100 by 200 pixels?

Explanation

The correct answer is "drawRectangle(100, 200);" because it is the only option that correctly calls the method "drawRectangle" with the parameters "100" and "200", specifying the dimensions of the rectangle as 100 by 200 pixels.

Submit
15. Refer to the following code for this question: public class HelloWorld {    public static void main (String [] args)    {       System.out.println("Hello World!!");    } } What would be the only appropriate file name for this program?

Explanation

The only appropriate file name for this program would be "HelloWorld.java" because in Java, the file name must match the name of the public class defined in the file. In this case, the public class is named "HelloWorld", so the file name should be "HelloWorld.java".

Submit
16. Refer to the following code for this question: public class HelloWorld {    public static void main (String [] args)    {       System.out.println("Hello World!!");    } } What type of class is the class above?

Explanation

The class above is a driver class because it contains the main() method, which serves as the entry point for the program. The main() method is responsible for starting the execution of the program and it is required in order to run the code. Therefore, this class can be considered as the driver or starting point of the program.

Submit
17. Refer to the following variable declaration for this question: int[] numbers = {1,2,3,4,5,6,7,8,9,10}; Which of the following is a valid conclusion based on this variable declaration?

Explanation

The valid conclusion based on the given variable declaration is that the value at index 5 of the array "numbers" is being changed to 6.

Submit
18. Which of the following is an example of a method header?

Explanation

The given example "public static int stringToInteger()" is an example of a method header because it includes the access modifier "public", the keyword "static" indicating that the method belongs to the class rather than an instance of the class, the return type "int" indicating the type of value the method will return, and the method name "stringToInteger()".

Submit
19. Given the Turtle object t1, how can you call a method to make it move forward 100 pixels, using a distance parameter?

Explanation

The correct answer is t1.backward(-100). This is because the backward() method is used to move the turtle in the opposite direction it is facing. In this case, the turtle is moved backwards by a distance of 100 pixels. The negative sign in the parameter is used to indicate the opposite direction.

Submit
20. Which of the following would be an example of only instantiating an object?

Explanation

The correct answer is "george = new Turtle();". This line of code is an example of only instantiating an object because it creates a new instance of the Turtle class and assigns it to the variable "george". The other options either declare a variable without instantiating an object or assign an existing object to a variable.

Submit
21. Following proper method naming conventions, which of the following would be a good method constructor?

Explanation



None of the above options are suitable for a method constructor. In Java, a method constructor should have the same name as the class, and it should not have a return type, not even void. 

So, a proper method constructor would have a signature like public MyClass().
Submit
22. Which of the following is an example of a constructor?

Explanation

A constructor is a special method in a class that is used to initialize objects of that class. It is typically declared with the same name as the class and has no return type. In this case, the answer "private class Calculator" is an example of a constructor because it is a class with the same name as the class it is defined in and it has the private access modifier, indicating that it is a constructor.

Submit
23. When running any java class, which of the following is the starting point?

Explanation

The question asks about the starting point when running any Java class, but the given options do not provide enough information to determine the correct answer. The starting point for running a Java class is the main() method, which serves as the entry point for the program. However, since this option is not provided, none of the given options can be considered as the correct answer.

Submit
View My Results

Quiz Review Timeline (Updated): Jan 17, 2024 +

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

  • Current Version
  • Jan 17, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Jan 24, 2012
    Quiz Created by
    Salaheldein
Cancel
  • All
    All (23)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Pseudocode is:
Which of the following data types are ideal for numbers?
Each time that a loop "loops" is known as a(n):
When should one choose a for() loop instead of a while() loop?
Which of the following is not a primitive data type?
Which of the following classes is included in the java.util package?
Which of the following best describes a contructor method?
Which of the following would be used to import all the classes in the...
An overloaded method is:
Refer to the following variable declaration for this question: ...
What is the use of the java.awt package?
Which of the following most specifically defines a package?
Which of the following would be an example of only declaring a number...
Which of the following is an example of a call to a method to draw a...
Refer to the following code for this question: ...
Refer to the following code for this question:...
Refer to the following variable declaration for this question: ...
Which of the following is an example of a method header?
Given the Turtle object t1, how can you call a method to make it move...
Which of the following would be an example of only instantiating an...
Following proper method naming conventions, which of the following...
Which of the following is an example of a constructor?
When running any java class, which of the following is the starting...
Alert!

Advertisement