5 Library Classes

String, Math, Random

Oracle Academy Section

Section 4: Java Methods and Library Classes

Lesson 3: The String Class

Lesson 4: The Random Class

Lesson 5: The Math Class

Section 4 Quiz 2 (Lessons 3-5)

Java Foundations Certification Exam Topics

Working with the String Class

Format Strings using escape sequences including %d, %n, and %s

Working with the Random and Math Classes

  • Use the Random class

  • Use the Math class

Key Resources

  1. Tutorials Point

    1. Java Examples - String formatting

    2. Java.util.Random Class

    3. Math class (for absolute value, rounding, rounding down (floor), rounding up (ceiling), and more)

  2. Udemy

    1. StringBuilder and String Formatting (19:43)

  3. Bucky's Room

    1. Math Class Methods (4:50)

    2. Random Number Generator (5:14)

Supplemental Resources

Most Important Concepts / Code

String formatting

// %d decimal number

// %n line break

// %s a string

System.out.format("the %s jumped %n over the %s, %d times %n", "cow", "moon", 2);

Random

// create random object, only do this once

Random randomGen = new Random();

// get next int value, you can do this as many times as you want

// nextInt will return an int between 0 (inclusive) and the specified value (exclusive)

System.out.println("Next int value: " + randomGen.nextInt(10000));

Hour 1

  • Quiz and Concepts Review

  • String class

  • StringBuilder

  • Random class

  • Math class

    • abs

    • floor

    • ceil

    • pow

Hour 2