1. Home
  2. Explore
  3. Computer Science
  4. Java Programming Fundamentals

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Java Programming Fundamentals

  • 131Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Java Setup
The software development environment for building Java applications that includes a compiler and other tools is the
.

131 questions

  1. 1
    The software development environment for building Java applications that includes a compiler and other tools is the
    _____
    .
    Hint

    It is commonly abbreviated JDK.

    Answer

    Java development kit

    Explanation

    The Java development kit provides tools for developing Java applications, including the Java compiler and a Java Runtime environment.

  2. 2
    The compiler included with the JDK translates Java source code into
    _____
    before the program runs.
    Hint

    This intermediate representation can run on different operating systems with a suitable runtime.

    Answer

    Java bytecode

    Explanation

    During compilation, the Java compiler converts source code into Java bytecode.

  3. 3
    The software component that translates Java bytecode into native code for the operating system is the
    _____
    .
    Hint

    Its abbreviation is JVM.

    Answer

    Java Virtual Machine

    Explanation

    The Java Virtual Machine loads bytecode and converts it into native code that the underlying operating system can execute.

  4. 4
    The Java Runtime environment contains the
    _____
    that executes Java bytecode.
    Hint

    It is the runtime component that translates bytecode for the operating system.

    Answer

    Java Virtual Machine

    Explanation

    The Java Runtime environment includes the Java Virtual Machine, which executes Java bytecode.

  5. 5
    Java applications are described as
    _____
    because bytecode can run on different operating systems that have a Java Runtime environment.
    Hint

    The phrase means that the program is not tied to one operating system.

    Answer

    platform independent

    Explanation

    The JVM translates platform-independent Java bytecode into native code for the operating system in use.

  6. 6
    The command used to invoke the Java compiler from a terminal is
    _____
    .
    Hint

    It is written as a short command followed by the source file name.

    Answer

    Java C

    Explanation

    The tutorial demonstrates compiling a source file from the terminal by invoking the compiler with the command Java C and the Java file as an argument.

  7. 7
    After compilation, the Java source file main.java is represented by a bytecode file named
    _____
    .
    Hint

    Compiled Java bytecode files use the class extension.

    Answer

    main.class

    Explanation

    Compiling main.java creates main.class, which contains the bytecode representation of the source file.

  8. 8
    The core Java platform used in the course, containing libraries Java developers need to learn, is
    _____
    .
    Hint

    It is abbreviated Java SE.

    Answer

    Java standard edition

    Explanation

    Java standard edition is the core Java platform and includes libraries used across Java development.

  9. 9
    The Java edition described as supporting very large-scale and distributed systems is
    _____
    .
    Hint

    It is built on top of Java standard edition.

    Answer

    Java Enterprise Edition

    Explanation

    Java Enterprise Edition adds libraries for large-scale, fault-tolerant, distributed, multi-tiered software.

  10. 10
    The Java edition described as a subset of Java standard edition for mobile devices is
    _____
    .
    Hint

    It includes libraries specific to mobile devices.

    Answer

    Java micro Edition

    Explanation

    Java micro Edition is a subset of Java standard edition designed for mobile devices.

  11. 11
    The Java edition used in smart cards is
    _____
    .
    Hint

    Its name refers to the small card-based devices it supports.

    Answer

    Java card

    Explanation

    Java card is the edition of Java used for smart cards.

  12. 12
    A command-line application runs from the command line and, unlike a GUI application, does not have a
    _____
    .
    Hint

    This is commonly abbreviated GUI.

    Answer

    graphical user interface

    Explanation

    A command-line application is run from the command line and does not provide a graphical user interface.

  13. 13
    A block of code that performs a task is called a
    _____
    .
    Hint

    It is a reusable unit of code, such as one that sends an email or validates input.

    Answer

    function

    Explanation

    A function is a block of code designed to perform a task.

  14. 14
    In Java, the value type specified before a method name is its
    _____
    .
    Hint

    It indicates what kind of value the method gives back, if any.

    Answer

    return type

    Explanation

    A method declaration begins with a return type that specifies the type of value returned by the method.

  15. 15
    The reserved keyword used as a method return type when the method returns nothing is
    _____
    .
    Hint

    It means the method does not provide a return value.

    Answer

    void

    Explanation

    A method with the return type void does not return a value.

  16. 16
    The descriptive identifier that tells readers what a method is for is its
    _____
    .
    Hint

    For example, a method that sends an email could be called sendEmail.

    Answer

    name

    Explanation

    A method should have a descriptive name that clearly identifies its purpose.

  17. 17
    Values passed into a method are received through its
    _____
    .
    Hint

    They are the named placeholders listed inside the method's parentheses.

    Answer

    parameters

    Explanation

    Parameters provide a way to pass values to a method when it is called.

  18. 18
    The curly braces following a method declaration enclose the method's
    _____
    .
    Hint

    This is the body that carries out the method's task.

    Answer

    actual Java code

    Explanation

    The method body, enclosed in curly braces, contains the Java statements that perform its work.

  19. 19
    In the Java style shown, the opening brace for a method is placed on the
    _____
    where the method is defined.
    Hint

    It is not moved to a new line as is conventional in some other languages.

    Answer

    same line

    Explanation

    The tutorial's Java formatting convention places the left brace on the same line as the method declaration.

  20. 20
    The method that acts as the entry point and is called when a Java program runs is the
    _____
    method.
    Hint

    Every Java program needs at least one of these methods.

    Answer

    main

    Explanation

    When a Java program is executed, its main method is called and the code inside it runs.

  21. 21
    A container used to organize one or more related functions is a
    _____
    .
    Hint

    In Java, functions defined inside this container are called methods.

    Answer

    class

    Explanation

    A class groups related methods and helps organize a program's code.

  22. 22
    A function that belongs to a class is called a
    _____
    .
    Hint

    In Java, class members of this kind are not usually referred to simply as standalone functions.

    Answer

    method

    Explanation

    A method is a function that is part of a class.

  23. 23
    The special keyword that controls whether other classes and methods can access a class or method is an
    _____
    .
    Hint

    Public and private are examples.

    Answer

    access modifier

    Explanation

    An access modifier determines whether other classes and methods can access a class or method.

  24. 24
    The access modifier most commonly used for classes and methods in the tutorial is
    _____
    .
    Hint

    It allows access from other parts of the program.

    Answer

    public

    Explanation

    The tutorial notes that public is the access modifier used most of the time for class and method declarations.

  25. 25
    The Java naming convention in which the first letter of every word in a class name is uppercase is
    _____
    .
    Hint

    A class name such as Main follows this convention.

    Answer

    Pascal naming convention

    Explanation

    Pascal naming convention capitalizes the first letter of every word in a class name.

  26. 26
    The Java naming convention in which the first word starts lowercase and later words begin with uppercase letters is
    _____
    .
    Hint

    A method name such as sendEmail follows this convention.

    Answer

    camel naming convention

    Explanation

    Camel naming convention keeps the first word lowercase and capitalizes the first letter of each later word.

  27. 27
    A Java source file uses the file extension
    _____
    .
    Hint

    The compiled bytecode file uses a different extension.

    Answer

    .java

    Explanation

    Java source files have the .java extension; compiled bytecode is stored in class files.

  28. 28
    In Java, a statement is terminated with a
    _____
    .
    Hint

    This punctuation mark appears at the end of many Java statements.

    Answer

    semicolon

    Explanation

    Java statements are terminated with semicolons.

  29. 29
    A package groups related
    _____
    so that code can be organized as an application grows.
    Hint

    It organizes the containers that hold methods.

    Answer

    classes

    Explanation

    Packages group related classes, helping organize applications that may contain many classes.

  30. 30
    A package creates a
    _____
    for classes, allowing classes with the same name to exist in different packages.
    Hint

    It helps prevent naming conflicts.

    Answer

    namespace

    Explanation

    Packages create namespaces, so classes with the same name can be distinguished by their packages.

  31. 31
    The base package for a Java project is conventionally based on the company's domain name written in
    _____
    .
    Hint

    The domain components are arranged from the broadest part toward the more specific part.

    Answer

    Reverse

    Explanation

    By convention, a project's base package uses the company's domain name in reverse order; an actual registered domain is not required.

  32. 32
    A method marked static in the program's entry point is required for the
    _____
    .
    Hint

    The tutorial says to remember this requirement even before learning static methods in detail.

    Answer

    main method

    Explanation

    The main method in a Java program should be static so it can serve as the program's entry point.

  33. 33
    The group of basic value types such as integers, characters, and booleans is called the
    _____
    types.
    Hint

    These types store simple values directly.

    Answer

    primitive

    Explanation

    Primitive types are used to store simple values such as numbers, boolean values, and individual characters.

  34. 34
    Types used to store complex objects, such as dates or messages, are called
    _____
    types.
    Hint

    Their variables refer to objects in memory rather than holding the objects' actual values.

    Answer

    reference

    Explanation

    Reference types are used for complex objects and store references to those objects.

  35. 35
    The primitive type that occupies one byte and can store whole-number values from negative 128 through 127 is
    _____
    .
    Hint

    It is suitable for small whole-number values, such as a person's age in the example.

    Answer

    byte

    Explanation

    A byte uses one byte of memory and supports values from negative 128 to 127.

  36. 36
    The primitive type that occupies two bytes and stores whole numbers up to about 32,000 is
    _____
    .
    Hint

    It has a larger range than byte but a smaller range than int.

    Answer

    short

    Explanation

    A short uses two bytes of memory and can store values up to about 32,000.

  37. 37
    The four-byte primitive type used for whole numbers up to about two billion is
    _____
    .
    Hint

    In Java code its keyword is int.

    Answer

    integer

    Explanation

    An integer uses four bytes of memory and stores whole numbers up to about two billion.

  38. 38
    The eight-byte whole-number type used for values larger than the int range is
    _____
    .
    Hint

    A large integer literal assigned to it may need an L suffix.

    Answer

    long

    Explanation

    A long uses eight bytes and can store larger whole numbers than an integer.

  39. 39
    The primitive type that uses four bytes for decimal numbers and requires an F suffix for a decimal literal is
    _____
    .
    Hint

    It uses less memory than double.

    Answer

    float

    Explanation

    A float uses four bytes, and a decimal literal must be marked with F when assigned as a float.

  40. 40
    The eight-byte primitive type commonly used to store decimal numbers is
    _____
    .
    Hint

    It is the default type Java assigns to decimal literals.

    Answer

    double

    Explanation

    A double uses eight bytes and is the default type for numbers written with a decimal point.

  41. 41
    The primitive type for a single character, written with single quotes, is
    _____
    .
    Hint

    It can represent one character, unlike a string.

    Answer

    char

    Explanation

    A char stores a single character and is written using single quotes.

  42. 42
    The primitive type that stores either true or false is
    _____
    .
    Hint

    It represents a two-valued logical choice.

    Answer

    boolean

    Explanation

    A boolean stores one of the two values true or false.

  43. 43
    The underscore separator used to make large numeric literals more readable does not change the number's value; it only improves
    _____
    .
    Hint

    It makes groups of digits easier to scan.

    Answer

    readability

    Explanation

    Java permits underscores between digits in large numbers to make the literal easier to read.

  44. 44
    Words such as public, static, void, class, and package are reserved Java
    _____
    .
    Hint

    They cannot be reused as variable, class, or method names.

    Answer

    keywords

    Explanation

    Reserved keywords have special meaning in Java and cannot be used as identifiers for variables, classes, or methods.

  45. 45
    A variable is initialized when it is given its
    _____
    value.
    Hint

    This happens when the variable is first assigned a value.

    Answer

    initial

    Explanation

    Initialization means assigning a variable its initial value, which should happen before the variable is read.

  46. 46
    The final keyword makes a variable's value unchangeable after it is initialized, so the variable acts as a
    _____
    .
    Hint

    The tutorial names the constant PI using capital letters.

    Answer

    constant

    Explanation

    A final variable cannot be assigned a new value after initialization, so it is used as a constant.

  47. 47
    By convention, Java constants are named using
    _____
    .
    Hint

    This naming style visually distinguishes constants from ordinary variables.

    Answer

    all capital letters

    Explanation

    The convention shown is to write constant names in all capital letters.

  48. 48
    When a primitive variable is assigned to another primitive variable, the stored
    _____
    is copied, so the variables are independent.
    Hint

    Changing one variable afterward does not alter the other.

    Answer

    value

    Explanation

    Primitive variables are copied by value, so assigning one to another gives each variable an independent value.

  49. 49
    When a reference variable is assigned to another reference variable, the
    _____
    to the object is copied.
    Hint

    Both variables can then point to the same object.

    Answer

    reference

    Explanation

    Reference variables hold and copy a reference to an object, rather than copying the object itself.

  50. 50
    An object created from a class is an
    _____
    of that class.
    Hint

    The class serves as a blueprint for creating it.

    Answer

    instance

    Explanation

    A class defines a template or blueprint, and an object created from it is an instance of that class.

  51. 51
    The new operator is used to allocate memory when creating an object of a
    _____
    .
    Hint

    Primitive variables do not require this explicit allocation in the examples.

    Answer

    reference type

    Explanation

    Creating an object of a reference type uses new to allocate memory for that object.

  52. 52
    A string is a sequence of
    _____
    .
    Hint

    For example, a word is made of several of these units.

    Answer

    characters

    Explanation

    A string represents textual data as a sequence of characters.

  53. 53
    Although a string literal can be assigned without using new, String is still a
    _____
    .
    Hint

    The shorter syntax is a convenient way to create an object, not evidence that String is primitive.

    Answer

    reference type

    Explanation

    Java provides shorthand initialization for strings, but strings remain reference types.

  54. 54
    Strings in Java are
    _____
    , so operations that appear to modify one return a new string instead.
    Hint

    Their original contents cannot be changed in place.

    Answer

    immutable

    Explanation

    A string cannot be mutated; methods such as replace and toLowerCase return new string objects.

  55. 55
    The plus operator can be used to
    _____
    two strings into one.
    Hint

    This means joining the strings together.

    Answer

    concatenate

    Explanation

    The plus operator concatenates strings by joining their text.

  56. 56
    The String method that returns the number of characters in a string is
    _____
    .
    Hint

    It is useful for checking whether user input exceeds a character limit.

    Answer

    length

    Explanation

    The length method returns the number of characters in a string.

  57. 57
    The String method that returns the position of the first occurrence of a character or substring is
    _____
    .
    Hint

    It returns zero when the match begins at the first character.

    Answer

    index of

    Explanation

    The index of method finds the first occurrence of the requested character or text; if it is absent, the result is negative one.

  58. 58
    When index of cannot find the requested text, it returns
    _____
    .
    Hint

    This result can be used to detect that a string does not contain the search text.

    Answer

    negative 1

    Explanation

    The index of method returns negative 1 when the requested character or substring is not present.

  59. 59
    The String method that returns a new string with specified text replaced is
    _____
    .
    Hint

    It takes a target and replacement value.

    Answer

    replace

    Explanation

    The replace method returns a new string in which occurrences of the target are replaced; it does not change the original string.

  60. 60
    The String method that removes whitespace from the beginning and end of a string is
    _____
    .
    Hint

    It is useful for cleaning up text entered in a form.

    Answer

    trim

    Explanation

    The trim method removes extra whitespace at the start and end of a string.

  61. 61
    In a Java string, the escape sequence used to include a double quote character is a backslash followed by
    _____
    .
    Hint

    Escaping prevents the quote from being interpreted as the end of the string.

    Answer

    double quote

    Explanation

    A backslash before a double quote allows that quote to appear inside a string literal.

  62. 62
    To represent a literal backslash in a Java string, use the escape sequence consisting of two
    _____
    .
    Hint

    The first backslash escapes the second one.

    Answer

    backslashes

    Explanation

    Two backslashes in the source string produce one backslash in the resulting text.

  63. 63
    The escape sequence used to insert a new line in a Java string is backslash followed by
    _____
    .
    Hint

    It is written as the newline escape sequence.

    Answer

    n

    Explanation

    The escape sequence backslash n inserts a line break into a string.

  64. 64
    The escape sequence used to insert a tab in a Java string is backslash followed by
    _____
    .
    Hint

    It is written as the tab escape sequence.

    Answer

    t

    Explanation

    The escape sequence backslash t inserts a tab into a string.

  65. 65
    An array is used to store a
    _____
    of items, such as numbers or messages.
    Hint

    The items are stored together and accessed by index.

    Answer

    list

    Explanation

    Arrays store a list of items of a particular type.

  66. 66
    The first element of a Java array is accessed using index
    _____
    .
    Hint

    Array indexing begins before one, not at one.

    Answer

    zero

    Explanation

    Java arrays use zero-based indexing, so the first element is at index zero.

  67. 67
    Once created, a Java array has a
    _____
    length; items cannot be added or removed from it.
    Hint

    Use a collection when the number of elements needs to change.

    Answer

    fixed

    Explanation

    Arrays have a fixed size after creation. Collections can be used when items need to be added or removed.

  68. 68
    For an integer array, elements that are not explicitly initialized default to
    _____
    .
    Hint

    This is the default value for an uninitialized integer element.

    Answer

    0

    Explanation

    Unassigned elements in an integer array are initialized to zero by default.

  69. 69
    The Arrays method that produces a readable string representation of a one-dimensional array is
    _____
    .
    Hint

    It converts the array into a string for printing.

    Answer

    toString

    Explanation

    Arrays.toString returns a string representation of a one-dimensional array.

  70. 70
    The Arrays method used to print a multidimensional array's nested contents is
    _____
    .
    Hint

    It handles the nested arrays rather than displaying only an object reference.

    Answer

    deepToString

    Explanation

    Arrays.deepToString provides a readable representation of a multidimensional array.

  71. 71
    The Arrays method used to arrange an array's items in sorted order is
    _____
    .
    Hint

    It orders the values rather than merely formatting them.

    Answer

    sort

    Explanation

    Arrays.sort sorts the contents of an array.

  72. 72
    The arithmetic operator that returns the remainder of a division is the
    _____
    .
    Hint

    It is useful for checking whether one number is divisible by another.

    Answer

    modulus operator

    Explanation

    The modulus operator returns the remainder after division; a zero remainder means the number is evenly divisible.

  73. 73
    When both operands of division are whole numbers in Java, the result is a
    _____
    .
    Hint

    A fractional part is discarded rather than automatically producing a decimal result.

    Answer

    whole number

    Explanation

    Division of two whole-number values produces a whole-number result; convert an operand to a floating-point type to get a decimal result.

  74. 74
    An expression is a piece of code that produces a
    _____
    .
    Hint

    For example, a comparison expression produces true or false.

    Answer

    value

    Explanation

    An expression evaluates to a value, which may be numeric, textual, or boolean.

  75. 75
    In an arithmetic expression, the values that operators act on are called
    _____
    .
    Hint

    In the expression 10 plus 3, these are 10 and 3.

    Answer

    operands

    Explanation

    Operands are the values used by arithmetic operators.

  76. 76
    The increment operator increases a variable's value by
    _____
    .
    Hint

    It is the short form for adding one.

    Answer

    1

    Explanation

    Applying the increment operator increases the value of its variable by one.

  77. 77
    With postfix increment in an assignment, the old value is copied first and the variable is incremented
    _____
    .
    Hint

    The increment happens after the assignment receives the value.

    Answer

    afterward

    Explanation

    Postfix increment supplies the current value to the expression before increasing the variable.

  78. 78
    With prefix increment in an assignment, the variable is incremented before its new value is copied to the assignment target, so the increment occurs
    _____
    .
    Hint

    The updated value is the one used by the expression.

    Answer

    first

    Explanation

    Prefix increment changes the variable before its value is used in the surrounding expression.

  79. 79
    The compound assignment operator += expresses the same update as adding a value and assigning the result back to the variable; it is an
    _____
    assignment operator.
    Hint

    It is a shorter form of an arithmetic update.

    Answer

    augmented

    Explanation

    An augmented, or compound, assignment such as x += 2 is equivalent to x = x + 2.

  80. 80
    In arithmetic precedence, multiplication and division are evaluated before addition and
    _____
    .
    Hint

    These two operations have the lower priority in the example.

    Answer

    subtraction

    Explanation

    Multiplication and division have higher precedence than addition and subtraction.

  81. 81
    Parentheses can be used to change the order in which arithmetic operations are
    _____
    .
    Hint

    An expression inside parentheses is handled before lower-priority operations outside them.

    Answer

    evaluated

    Explanation

    Parentheses have the highest priority and can force an expression to be evaluated first.

  82. 82
    Automatic conversion to a wider compatible type, when it does not risk losing data, is called
    _____
    casting.
    Hint

    The programmer does not have to write the conversion explicitly.

    Answer

    implicit

    Explanation

    Implicit casting happens automatically when a value can be converted to a wider type without data loss.

  83. 83
    A conversion written explicitly by the programmer, such as placing int in parentheses before a value, is called
    _____
    casting.
    Hint

    This form makes the requested type conversion visible in the code.

    Answer

    explicit

    Explanation

    Explicit casting directs Java to convert a value to a specified compatible type and may lose data.

  84. 84
    Converting a decimal value to an integer can discard the fractional part, so this conversion can involve data
    _____
    .
    Hint

    The digits after the decimal point may not be retained.

    Answer

    loss

    Explanation

    Explicitly converting a floating-point value to an integer removes its fractional part and therefore can lose data.

  85. 85
    The wrapper class method used to convert a string containing a whole number to an int is Integer dot
    _____
    .
    Hint

    The method name indicates the target primitive type.

    Answer

    parseInt

    Explanation

    Integer.parseInt converts a numeric string to an int; related wrapper classes provide parsing methods for other numeric types.

  86. 86
    The Double wrapper class method used to convert a decimal numeric string to a double is
    _____
    .
    Hint

    Use this instead of parsing a decimal value as an integer.

    Answer

    parseDouble

    Explanation

    Double.parseDouble parses a string as a double, including a value with a fractional part.

  87. 87
    The Math method that rounds a floating-point value to a whole-number result is
    _____
    .
    Hint

    Its result type depends on whether the input is a float or a double.

    Answer

    round

    Explanation

    Math.round rounds a floating-point number; it returns an int for a float argument and a long for a double argument.

  88. 88
    The Math method that returns the smallest integer greater than or equal to a number is
    _____
    .
    Hint

    For example, the result for 1.1 is 2.

    Answer

    ceil

    Explanation

    Math.ceil returns the ceiling value, the smallest integer greater than or equal to the input, represented as a double.

  89. 89
    The Math method that returns the largest integer less than or equal to a number is
    _____
    .
    Hint

    For example, the result for 1.1 is 1.

    Answer

    floor

    Explanation

    Math.floor returns the largest integer less than or equal to the input, represented as a double.

  90. 90
    The Math method that returns the greater of two values is
    _____
    .
    Hint

    It compares two supplied values and selects the larger one.

    Answer

    max

    Explanation

    Math.max returns the greater of its two arguments and has overloads for different numeric types.

  91. 91
    The Math method that returns a pseudorandom double between zero and one is
    _____
    .
    Hint

    Multiplying its result by 100 scales the range to zero through 100.

    Answer

    random

    Explanation

    Math.random returns a random floating-point value between zero and one; scaling and converting can produce other ranges.

  92. 92
    To read input from the terminal using Scanner, pass the system field
    _____
    .
    Hint

    The corresponding output field used for printing is System.out.

    Answer

    System.in

    Explanation

    A Scanner constructed with System.in reads input from the terminal.

  93. 93
    The Scanner method that reads one whitespace-separated token is
    _____
    .
    Hint

    Repeated calls read successive tokens, not necessarily a whole line.

    Answer

    next

    Explanation

    Scanner.next reads one token at a time, so a name containing spaces requires more than one call or a different method.

  94. 94
    The Scanner method that reads the entire line, including spaces, is
    _____
    .
    Hint

    Use it when input may contain a full name or other text with spaces.

    Answer

    nextLine

    Explanation

    Scanner.nextLine reads the full line entered by the user, including spaces and tabs.

  95. 95
    To prompt without automatically moving the cursor to the next line, use the Scanner tutorial's output method named
    _____
    .
    Hint

    Unlike its line-ending counterpart, it does not append a new line.

    Answer

    print

    Explanation

    The print method displays a prompt without adding a newline, allowing the user's input to appear beside it.

  96. 96
    The Java class used to format numbers as currency or percentages is
    _____
    .
    Hint

    It is defined in the text package and supplies formatting methods.

    Answer

    NumberFormat

    Explanation

    NumberFormat provides methods for displaying numeric values in formats such as currency and percent.

  97. 97
    Because NumberFormat is abstract, an instance for currency formatting is obtained with its
    _____
    .
    Hint

    This factory method creates and returns a suitable NumberFormat object.

    Answer

    getCurrencyInstance

    Explanation

    An abstract class cannot be instantiated with new; getCurrencyInstance supplies a NumberFormat instance configured for currency.

  98. 98
    The NumberFormat factory method that supplies an object for percent formatting is
    _____
    .
    Hint

    It returns a formatter that displays a value such as 0.1 as 10 percent.

    Answer

    getPercentInstance

    Explanation

    getPercentInstance creates a NumberFormat object configured to format numeric values as percentages.

  99. 99
    A factory method followed immediately by another method call on its returned object is an example of method
    _____
    .
    Hint

    The calls are connected rather than stored in separate intermediate variables.

    Answer

    chaining

    Explanation

    Method chaining calls a method on the object returned by a previous method call.

  100. 100
    Replacing unexplained numeric literals with named final variables helps avoid
    _____
    numbers.
    Hint

    Named constants make the purpose of values like 12 or 100 clear to readers.

    Answer

    magic

    Explanation

    Using descriptive constants instead of magic numbers improves code clarity and makes the intent of values explicit.

  101. 101
    Operators such as == and != used to compare primitive values are called
    _____
    operators.
    Hint

    They determine whether values are equal, unequal, greater, or smaller.

    Answer

    comparison

    Explanation

    Comparison operators compare primitive values and produce boolean results.

  102. 102
    An expression that evaluates to either true or false is a
    _____
    expression.
    Hint

    The result can be used as the condition of an if statement or loop.

    Answer

    boolean

    Explanation

    A boolean expression produces a boolean value, true or false.

  103. 103
    The logical operator && returns true only when
    _____
    conditions are true.
    Hint

    If either side is false, the complete expression is false.

    Answer

    both

    Explanation

    The logical AND operator evaluates to true only if both boolean conditions are true.

  104. 104
    The logical operator represented by two vertical bars returns true if at least
    _____
    condition is true.
    Hint

    It combines alternatives rather than requiring both conditions.

    Answer

    one

    Explanation

    The logical OR operator evaluates to true when at least one of its conditions is true.

  105. 105
    The logical operator ! reverses a boolean value and is called logical
    _____
    .
    Hint

    Applying it to false produces true.

    Answer

    not

    Explanation

    Logical NOT negates a boolean value, changing true to false or false to true.

  106. 106
    The clause that supplies a condition for an alternative path when the preceding if condition is false is
    _____
    .
    Hint

    It allows a program to test another condition before the final fallback.

    Answer

    else if

    Explanation

    An else if clause tests another condition when earlier conditions in an if statement are false.

  107. 107
    The final fallback clause in an if structure, used when none of its earlier conditions match, is
    _____
    .
    Hint

    It does not require a condition of its own.

    Answer

    else

    Explanation

    The else clause runs when none of the preceding if or else if conditions is true.

  108. 108
    The operator that selects one of two values according to a condition uses a question mark and a
    _____
    .
    Hint

    Its structure is condition, question mark, first value, then this punctuation and the alternative value.

    Answer

    colon

    Explanation

    The ternary operator has a condition and two possible values separated by a question mark and a colon.

  109. 109
    A switch statement uses a
    _____
    clause to run when none of its listed cases matches.
    Hint

    It acts as the switch statement's fallback case.

    Answer

    default

    Explanation

    The default clause is executed when no case value matches the switch expression.

  110. 110
    In a switch statement, the statement that exits the switch after a matching case is
    _____
    .
    Hint

    Without it, execution can continue into later cases.

    Answer

    break

    Explanation

    A break statement exits the switch block and prevents execution from falling through to subsequent cases.

  111. 111
    When several conditions overlap, placing the most
    _____
    condition first prevents a broader condition from taking precedence.
    Hint

    For example, test divisibility by both 3 and 5 before divisibility by just 5.

    Answer

    specific

    Explanation

    In the FizzBuzz example, the condition for divisibility by both numbers must come before the less specific individual divisibility checks.

  112. 112
    A for loop is especially useful when the number of repetitions is known
    _____
    .
    Hint

    Its initialization, condition, and update are collected in the loop header.

    Answer

    ahead of time

    Explanation

    A for loop is a good choice when the number of iterations is known in advance.

  113. 113
    The three parts of a for loop header are the counter initialization, loop condition, and counter
    _____
    .
    Hint

    This often increments or decrements the loop variable after an iteration.

    Answer

    update

    Explanation

    A for loop header initializes its counter, checks a condition, and updates the counter between iterations.

  114. 114
    A while loop is especially useful when the number of repetitions is not known
    _____
    .
    Hint

    For example, the user may decide when to stop by entering a particular word.

    Answer

    ahead of time

    Explanation

    A while loop is suitable when repetition continues until a condition changes and the number of iterations is not known beforehand.

  115. 115
    A do-while loop checks its condition after running its body, so its body executes at least
    _____
    .
    Hint

    This distinguishes it from a while loop whose condition is false at the start.

    Answer

    once

    Explanation

    Because a do-while loop tests its condition after the body, it always executes the body at least once.

  116. 116
    The statement that immediately terminates a loop is
    _____
    .
    Hint

    It exits the loop rather than skipping only the current iteration.

    Answer

    break

    Explanation

    The break statement stops execution of the current loop.

  117. 117
    The statement that skips the rest of the current loop iteration and moves to the next one is
    _____
    .
    Hint

    It does not terminate the loop entirely.

    Answer

    continue

    Explanation

    The continue statement moves control to the beginning of the next loop iteration.

  118. 118
    A loop whose condition is always true can run indefinitely unless it contains a
    _____
    .
    Hint

    The loop needs a way to stop when its exit condition is reached.

    Answer

    break statement

    Explanation

    A while true loop continues indefinitely unless a break statement provides a way to exit it.

  119. 119
    A for-each loop is designed to iterate over arrays or
    _____
    .
    Hint

    These are groups of items that can be traversed one at a time.

    Answer

    collections

    Explanation

    For-each loops provide a concise way to iterate over arrays and collections.

  120. 120
    Unlike a traditional for loop, a for-each loop does not directly provide the index of each
    _____
    .
    Hint

    It supplies the current element through its loop variable.

    Answer

    item

    Explanation

    A for-each loop gives access to each element but not its index; use a traditional for loop when the index is needed.

  121. 121
    A for-each loop traverses elements only in the
    _____
    direction.
    Hint

    A traditional for loop can be adjusted to move from the end toward the beginning.

    Answer

    forward

    Explanation

    The for-each loop moves forward through its array or collection and does not directly support reverse iteration.

  122. 122
    A mortgage calculator converts the annual interest rate, expressed as a percent, to a decimal rate by dividing by
    _____
    .
    Hint

    A percentage must be converted before it is used as a decimal interest rate.

    Answer

    100

    Explanation

    The annual rate is divided by 100 to convert its percentage representation to a decimal rate.

  123. 123
    To obtain the monthly interest rate from the annual decimal rate, divide by the number of
    _____
    in a year.
    Hint

    The calculator uses 12 of these in one year.

    Answer

    months

    Explanation

    The annual interest rate is divided by 12 to convert it to a monthly interest rate.

  124. 124
    The number of monthly mortgage payments is the number of loan years multiplied by 12, the number of
    _____
    in a year.
    Hint

    Each year contributes 12 monthly payments.

    Answer

    months

    Explanation

    The payment count is calculated by multiplying the loan period in years by 12 months per year.

  125. 125
    In the mortgage formula, the Math method used to raise a value to a specified power is
    _____
    .
    Hint

    It accepts a base and an exponent.

    Answer

    pow

    Explanation

    The Math.pow method raises its first argument to the power specified by its second argument.

  126. 126
    Mortgage input validation can keep asking the same question by placing the prompt and check inside an infinite
    _____
    .
    Hint

    A break statement exits it when the entered value is valid.

    Answer

    loop

    Explanation

    An infinite loop can repeatedly prompt the user until a valid value is entered, then break when validation succeeds.

  127. 127
    A variable declared inside a code block is scoped to that
    _____
    , so it cannot be accessed outside it.
    Hint

    Move the declaration outward if later code needs to use the variable.

    Answer

    block

    Explanation

    A variable's scope is limited to the block in which it is declared; code outside that block cannot access it.

  128. 128
    Descriptive variable names improve code readability by making each variable's
    _____
    clear.
    Hint

    Names such as monthlyInterest convey more than names such as m1.

    Answer

    purpose

    Explanation

    Meaningful names help readers understand what variables represent and what the code does.

  129. 129
    A programming guideline abbreviated DRY means
    _____
    .
    Hint

    It encourages avoiding duplicated code or expressions.

    Answer

    don't repeat yourself

    Explanation

    DRY stands for don't repeat yourself, a principle that discourages unnecessary duplication in code.

  130. 130
    In choosing between solutions, programming often involves
    _____
    because every solution has strengths and weaknesses.
    Hint

    A solution may reduce duplication but make code more nested, for example.

    Answer

    trade-offs

    Explanation

    Programming and problem solving involve trade-offs; one implementation may improve one quality while making another worse.

  131. 131
    Code that is clean and expressive is generally easier to
    _____
    and maintain.
    Hint

    It is written for human readers as well as for the computer.

    Answer

    understand

    Explanation

    Clean, expressive code helps people understand a program and makes it easier to maintain.

1 of 131
Question 1 of 131

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent