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

  • 118Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Java Platform
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is the Java Development Kit (JDK), and what does it contain?

Tap to flipClick to flipspace

The JDK is a software development environment for building Java applications. It includes a compiler, reusable code libraries, a Java Runtime Environment, and other tools.

Or swipe the card

118 cards

  1. What is the Java Development Kit (JDK), and what does it contain?

    The JDK is a software development environment for building Java applications. It includes a compiler, reusable code libraries, a Java Runtime Environment, and other tools.

  2. What are the JRE and JVM, and how are they related?

    The Java Runtime Environment (JRE) provides what is needed to run Java programs. It includes the Java Virtual Machine (JVM), which executes Java bytecode.

  3. What are the two main stages when a Java program runs?

    Compilation converts Java source code into bytecode; execution runs that bytecode on the JVM.

  4. Which command-line tool compiles a Java source file, and what is an example command?

    The Java compiler, javac, compiles source files. For example: javac Main.java.

  5. What is a .class file?

    It contains the bytecode produced by compiling a Java source file.

  6. What does the JVM do with Java bytecode?

    It translates bytecode into native code for the operating system on which the program is running.

  7. Why are Java applications described as platform-independent?

    The same bytecode can run on different operating systems, provided each has a compatible JRE and JVM.

  8. What popular Java IDEs are mentioned, and which is used in the course?

    NetBeans, Eclipse, and IntelliJ are mentioned; the course uses IntelliJ IDEA.

  9. Which IntelliJ IDEA edition is recommended for the course, and why?

    The free Community Edition is recommended because it is sufficient for the course.

  10. Who developed Java, when, and at which company?

    James Gosling developed Java in 1995 at Sun Microsystems, which Oracle acquired in 2010.

  11. What names did Java have before it was called Java?

    It was first called Oak, then Green, and finally Java.

  12. What inspired the name Java?

    Java coffee inspired the name; the course also connects the coffee inspiration to Java’s logo.

  13. What are Java SE and Java EE used for?

    Java SE is the core Java platform. Java EE builds on SE with additional libraries for large-scale, distributed, multi-tier systems.

  14. What are Java ME and Java Card designed for?

    Java ME is a subset of Java SE designed for mobile devices; Java Card is used in smart cards.

  15. What Java adoption and version figures does the content cite?

    As reported in 2019, Java SE 12 had been released in March 2019; the content cites close to 9 million developers, about 3 billion mobile phones, 120 million TV sets, every Blu-ray player, and an average U.S. Java developer salary just over $100,000.

  16. What is a function in programming?

    A function is a block of code that performs a task, such as sending an email or validating user input.

  17. What is a method, and how does it differ from a function?

    A method is a function that belongs to a class. Some languages allow functions outside classes, but Java methods belong to classes.

  18. What is a Java class used for?

    A class is a container for related methods and helps organize code.

  19. What is the main method’s role in a Java program?

    It is the program’s entry point: when the program runs, execution begins in main.

  20. What minimum structure does a basic Java program need?

    At least one class containing a main method.

  21. What does the static modifier mean for the main method in this course’s basic program structure?

    The main method should be declared static; the course notes that the details of static will be covered later.

  22. What does a method’s return type specify, and what does void mean?

    The return type specifies the kind of value a method returns. void means the method returns no value.

  23. What are method parameters used for?

    Parameters provide a method with values it needs to perform its task.

  24. What is an access modifier?

    A special keyword that determines whether other classes or methods can access a class or method. public is commonly used.

  25. Where does Java conventionally place the opening brace for a class or method?

    On the same line as the class or method declaration.

  26. What naming conventions does Java use for classes and methods?

    Class names use PascalCase, with each word beginning with an uppercase letter. Method names use camelCase, with the first word lowercase and later words capitalized.

  27. What is a Java package, and why use one?

    A package groups related classes and provides a namespace, helping organize projects as they grow.

  28. What is the conventional base-package naming pattern described for a Java project?

    Use the company’s domain name in reverse order, such as com.example. It creates a namespace and does not require owning a registered domain.

  29. What does a package statement do, and how is it terminated?

    It specifies the package a class belongs to and, like other Java statements, ends with a semicolon.

  30. What file extension do Java source files use, and what does an import statement do?

    Java source files use .java. An import makes a class from another package available for use.

  31. Why can Java code use classes in java.lang without an explicit import?

    The java.lang package is imported automatically.

  32. What is a variable, and why must it be initialized before it is read?

    A variable is a named memory location used to store data temporarily. It must be given an initial value before its value is read.

  33. In a declaration such as int age = 30, what do the type, identifier, assignment operator, and initial value represent?

    int is the type, age is the identifier, = assigns a value, and 30 is the initial value.

  34. Can a variable’s value change after initialization?

    Yes. A variable can be assigned a different value later in the program.

  35. What is an identifier, and what makes a variable name useful?

    An identifier is a name used to identify a variable. Meaningful, descriptive names make code easier to understand.

  36. Why is declaring several variables on one line generally discouraged?

    Although Java permits it, separate declarations are usually easier to read and maintain.

  37. What is the difference between primitive and reference types?

    Primitive types store simple values; reference types store references to complex objects.

  38. How much memory do byte, short, int, and long use, and what rough ranges does the content give?

    They use 1, 2, 4, and 8 bytes respectively. The content gives byte as ranging from −128 to 127, short up to about 32,000, and int up to about 2 billion; long stores still larger whole numbers.

  39. When should float or double be used, and how do their sizes compare?

    Use them for numbers with decimal points. A float uses 4 bytes; a double uses 8 bytes and can represent larger values.

  40. What do char and boolean store?

    char stores one character and uses 2 bytes; boolean stores either true or false.

  41. Why must a large integer literal assigned to a long sometimes end with L?

    Java treats an unsuffixed whole-number literal as an int by default. The L suffix marks it as a long; uppercase L is clearer than lowercase l.

  42. Why must a decimal literal assigned to a float sometimes end with F?

    Java treats decimal literals as double by default. The F suffix marks the literal as a float.

  43. How should Java character and string literals be delimited?

    A single character uses single quotes; a string containing multiple characters uses double quotes.

  44. What are reserved keywords, and can they be used as variable names?

    Reserved keywords have special meanings in Java, so they cannot be used as names for variables, classes, or methods.

  45. How is a reference-type object commonly created, and what is an object’s relationship to its class?

    Use new followed by the class name and constructor arguments. The class is a template; an object is an instance created from it.

  46. How does assigning a reference variable differ from assigning a primitive variable?

    Primitive assignment copies the value, so the variables are independent. Reference assignment copies the reference, so both variables can refer to the same object and observe changes to it.

  47. How can a variable be made constant, and what naming convention is used for constants?

    Declare it with final; after initialization, its value cannot be changed. Constants are conventionally named with uppercase letters, such as PI.

  48. What is a Java string, and why is assigning a string literal a convenient way to create one?

    A string is a reference type representing a sequence of characters. Java allows a string variable to be initialized directly with a string literal instead of explicitly using new String(...).

  49. How can strings be concatenated in Java?

    Use the + operator to join strings, or to join a string with another value such as a number.

  50. What do the startsWith and endsWith string methods check?

    They return whether a string begins or ends with the specified character sequence.

  51. What does the length method return for a string?

    The number of characters in the string.

  52. What does indexOf return, and what does a result of -1 mean?

    It returns the index of the first occurrence of the specified character or sequence. It returns -1 if that content is not found.

  53. What does the string replace method do, and does it modify the original string?

    It returns a new string with the target content replaced. It does not modify the original string because strings are immutable.

  54. What do toLowerCase and trim do, and do they change the original string?

    toLowerCase returns a lowercase version; trim returns a version with surrounding whitespace removed. Neither changes the original string.

  55. How can a double quote be included inside a Java string literal?

    Escape it with a backslash: \".

  56. How can a literal backslash be included in a Java string?

    Escape the backslash with another backslash: \\ in Java source represents one backslash in the resulting string.

  57. What do the Java string escape sequences \n and \t represent?

    \n inserts a new line; \t inserts a tab.

  58. What are arrays used for, and what is an important size limitation?

    Arrays store lists of items, such as numbers or messages. Their length is fixed when they are created.

  59. How are array elements accessed, and what index identifies the first element?

    Use an index in square brackets; the first element has index 0.

  60. What happens when a program accesses an array index that is outside the array’s bounds?

    Java raises an exception, and the program may terminate if the exception is not handled.

  61. What default values does the content identify for uninitialized integer and boolean array elements?

    Integer array elements default to 0; boolean array elements default to false.

  62. What does Arrays.toString do, and how does it relate to method overloading?

    It returns a readable string representation of an array. The method is overloaded, with implementations for different array element types.

  63. How can an array be sorted using Java’s Arrays class?

    Call Arrays.sort(array) to sort the array.

  64. How do multidimensional arrays differ from one-dimensional arrays, and how can a multidimensional array be displayed?

    A multidimensional array contains arrays, such as rows and columns in a matrix. Use Arrays.deepToString to get a readable representation; Arrays.toString is for a one-dimensional array.

  65. Which arithmetic operators are covered, and what does the modulus operator return?

    Addition, subtraction, multiplication, division, and modulus are covered. Modulus returns the remainder of a division.

  66. What is an operand in an arithmetic expression?

    A value on which an operator acts; for example, in an addition, the numbers being added are operands.

  67. What happens when one whole number is divided by another in Java?

    The result is a whole number; any fractional part is discarded. Convert an operand to a floating-point type to get a fractional result.

  68. What is an expression in Java?

    A piece of code that produces a value, such as an arithmetic calculation or a comparison.

  69. What is the order of precedence for the arithmetic operators covered?

    Parentheses are evaluated first, followed by multiplication and division, then addition and subtraction.

  70. How do prefix and postfix increment differ when used in an assignment?

    Postfix (x++) supplies the original value before incrementing; prefix (++x) increments first and supplies the new value.

  71. What do the increment and decrement operators do?

    Increment increases a value by one; decrement decreases it by one.

  72. What is a compound assignment operator, such as +=?

    It combines an operation with assignment: x += 2 is equivalent to x = x + 2. Similar forms exist for other arithmetic operations.

  73. What is implicit casting, and when is it generally safe?

    It is automatic conversion between compatible types when conversion does not lose data, such as widening a smaller numeric type to a larger one.

  74. What is explicit casting, and what is a potential consequence?

    It is a conversion requested by the programmer, such as (int) value. It may discard information, such as digits after a decimal point.

  75. Can a string be converted to a number using a numeric cast? What should be used instead?

    No. Use a wrapper-class parsing method, such as Integer.parseInt for an integer or Double.parseDouble for a double.

  76. What does Math.round do, and what return types does the content describe?

    It rounds a floating-point value to a whole number. The float version returns an int; the double version returns a long.

  77. What do Math.ceil and Math.floor return?

    ceil returns the smallest integer-valued result greater than or equal to the input; floor returns the largest integer-valued result less than or equal to it. Both return a double.

  78. What do Math.max and Math.min do?

    They return the greater or lesser of two values, respectively; their methods are overloaded for numeric types.

  79. What range does Math.random produce, and how can it be scaled?

    It produces a double from 000 up to but not including 111. Multiplying it by 100100100 scales the range to 000 up to but not including 100100100.

  80. Why can casting Math.random() to an integer before multiplying by 100100100 produce only zero?

    The random value is less than 111, so casting it to an integer first discards its fractional part and gives 000. Multiply first, then cast if an integer result is needed.

  81. What is the purpose of Java’s Scanner class when reading terminal input?

    It reads input from a source such as the terminal; use System.in to supply terminal input.

  82. What is the difference between Scanner.next() and Scanner.nextLine()?

    next() reads one token, ending at whitespace. nextLine() reads the entire line, including spaces within it.

  83. Why might trim() be useful on user input?

    It removes whitespace at the beginning and end of a string, which can prevent unwanted spaces from affecting input handling.

  84. Why is it inefficient to create a new Scanner inside every iteration of an input loop?

    It repeatedly creates unnecessary objects. Create one scanner before the loop and reuse it.

  85. How can a string entered by a user be converted to a numeric value?

    Use an appropriate parsing method, such as Integer.parseInt, Float.parseFloat, or Double.parseDouble.

  86. What can happen if a numeric parsing method receives invalid input?

    It can raise an exception, which is Java’s way of reporting an error at runtime.

  87. Why can’t NumberFormat be instantiated directly, and how can an instance be obtained?

    NumberFormat is abstract. Use a factory method such as getCurrencyInstance() or getPercentInstance() to obtain an instance.

  88. How does a currency formatter present a number?

    It returns a formatted string, typically using a currency symbol, grouping separators, and two digits after the decimal point.

  89. How does a percent formatter interpret a value such as 0.10.10.1?

    It formats the value as a percentage, so 0.10.10.1 is displayed as 10%10\%10%.

  90. What is method chaining?

    Calling a method on the result of another method, such as calling format on the object returned by a NumberFormat factory method.

  91. What is the general formula for a monthly mortgage payment described in the content?

    Let PPP be the principal, rrr the monthly interest rate, and nnn the total number of monthly payments. The payment is Pr(1+r)n(1+r)n−1\frac{P r(1+r)^n}{(1+r)^n-1}(1+r)n−1Pr(1+r)n​.

  92. How is an annual interest rate entered as a percent converted to a monthly rate?

    Divide the annual percentage by 100100100 to convert it to a decimal, then divide by 121212: r=annual rate100×12r=\frac{\text{annual rate}}{100\times12}r=100×12annual rate​.

  93. How is the number of monthly payments for a loan term in years calculated?

    Multiply the number of years by 121212.

  94. What does a comparison operator produce?

    A boolean value, true or false. Operators covered include equality, inequality, greater than, greater than or equal to, less than, and less than or equal to.

  95. What is a boolean expression?

    An expression that evaluates to true or false.

  96. What does the logical AND operator && require to evaluate to true?

    Both conditions must be true. Java can stop evaluating once it finds a false condition.

  97. What does the logical OR operator || require to evaluate to true?

    At least one condition must be true. Java can stop evaluating once it finds a true condition.

  98. What does the logical NOT operator ! do?

    It reverses a boolean value: true becomes false, and false becomes true.

  99. What are the clauses of an if statement used for?

    if handles the first condition, else if handles additional conditions, and else handles the case when none of the preceding conditions is true.

  100. When are braces needed around an if branch in Java?

    They are required when the branch contains multiple statements. The content notes that programmers may also use braces around single statements for consistency.

  101. How can a boolean variable be assigned directly from a condition instead of using an if statement?

    Assign the boolean expression itself, such as hasHighIncome = income > 100000;.

  102. What does the ternary operator do?

    It chooses between two values based on a condition: condition ? valueIfTrue : valueIfFalse.

  103. How does a switch statement select a branch?

    It compares an expression with case values and executes the matching case; default handles cases with no match.

  104. Why are break statements commonly used in switch cases?

    They exit the switch after a case runs. Without a break, execution can continue into later cases.

  105. Which types does the content say can be used in switch cases?

    It describes strings and integer-like values such as byte, short, and int, but excludes long.

  106. What are the three main parts of a for loop header?

    Initialization of a loop variable, a boolean continuation condition, and an update such as incrementing the variable.

  107. How does a while loop differ from a do-while loop?

    A while loop checks its condition before running the body and may run zero times. A do-while checks afterward and runs at least once.

  108. What is the difference between break and continue inside a loop?

    break exits the loop; continue skips to the next iteration.

  109. What are the key limitations of a for-each loop compared with a traditional for loop?

    A for-each loop moves forward through the items and does not directly provide their indexes. Use a traditional for loop when you need an index or reverse traversal.

  110. How does the FizzBuzz example use the modulus operator?

    A number is divisible by another number when the remainder is zero; for example, test divisibility by 555 with number % 5 == 0.

  111. Why should FizzBuzz test divisibility by both 333 and 555 before testing either one separately?

    The combined condition is more specific. If a number such as 151515 is tested against 555 first, the program may print only Fizz and never reach the combined case.

  112. What trade-off does the content describe between nested conditions and repeating a condition?

    Nested conditions can avoid repeating tests but may make code harder to read. A flatter structure may repeat a test but be clearer; there is not always one ideal solution.

  113. How can an infinite loop be used to validate user input?

    Ask the question inside the loop, test the input, and use break when it is valid. If it is invalid, display an error and loop to ask again.

  114. Why might variables used after a validation loop need to be declared outside it?

    A variable’s scope is limited to the block where it is declared. Declaring it outside the loop lets later code access it.

  115. What input ranges does the mortgage-calculator validation example use?

    It accepts a principal from 1,0001{,}0001,000 to 1,000,0001{,}000{,}0001,000,000, an annual interest rate greater than 000 and at most 303030, and a loan term from 111 to 303030 years.

  116. Why should a mortgage calculator use named constants rather than unexplained numeric literals?

    Named constants clarify what values mean, such as months per year or the percent divisor, and avoid magic numbers.

  117. What types does the mortgage-calculator example choose for principal, interest, and loan term?

    It uses an int for principal, a float for the small annual interest value, and a byte for a term capped at 303030 years.

  118. What general principle about clean code is emphasized in the content?

    Good code should be understandable to humans, not merely executable by a computer; readable names and clear structure support maintainability.

Card 1 of 118
Card 1 of 118

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent