0Pricing
Java Academy · Lesson

Testing & Extensions

Test with edge cases and add tiny improvements. Keep examples simple and easy to read.

Testing & Extensions is a free Java Academy lesson on CoddyKit — lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why test

Why test? Small tests catch surprises early. We start with easy inputs and add edge cases step by step.

Happy path

First try a short sentence with clear words. Expect totals to match and top words to make sense.

Edge cases

Edge cases: empty string, only spaces, punctuation only, numbers mixed with words, and repeated spaces. Each should not crash and should produce sensible counts.

Normalization check

Use mixed case and commas to verify normalization. After lowercasing and cleaning, Hello and HELLO should count as the same word.

Small extensions

Tiny extensions: ignore very short words like a or an, choose top N as a variable, and print ties in any order. Keep changes minimal and readable.

Code: tiny tests

Run: each sample prints totals and unique counts. This helps verify empty, spaces, punctuation, and mixed case handling.

public class Main {
  public static void main(String[] args) {
    // Very small test set for beginners. Each case prints a short result.
    String[] samples = new String[] {
      "Hello world hello",
      "",                            // empty
      "   ",                         // spaces
      "Hello, HELLO, hello!",        // mixed case and punctuation
      "Numbers 1 2 3 and words",     // numbers and words
      "Only... punctuation!!!"       // punctuation only
    };

    for (int t = 0; t < samples.length; t = t + 1) {
      String text = samples[t];
      System.out.println("-- Case " + (t + 1) + " --");
      // 1) Lowercase
      String lower = text.toLowerCase();
      // 2) Replace non letters with spaces
      String cleaned = lower.replaceAll("[^a-z]+", " ");
      // 3) Split on spaces and filter empties
      String[] tokens = cleaned.trim().split("\\s+");

      java.util.Map<String, Integer> freq = new java.util.HashMap<>();
      int total = 0;
      for (int i = 0; i < tokens.length; i = i + 1) {
        String w = tokens[i];
        if (w.length() == 0) continue;
        // Optional tiny extension: skip one letter words like "a"
        if (w.length() == 1) continue;
        total = total + 1;
        Integer c = freq.get(w);
        if (c == null) freq.put(w, 1);
        else freq.put(w, c + 1);
      }

      // Print a very small summary (no top N here to keep it simple)
      System.out.println("Total words: " + total);
      System.out.println("Unique words: " + freq.size());
    }
  }
}

Normalization test

Quick check: Which input is best for checking normalization (case and punctuation)?

Recap

Recap: We tested happy paths and edge cases, then added tiny extensions like skipping one letter words. Keep examples short and readable.

Frequently asked questions

Is the “Testing & Extensions” lesson free?

Yes — the full text of “Testing & Extensions” is free to read here on the web, and the Java Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.

What will I learn in “Testing & Extensions”?

Test with edge cases and add tiny improvements. Keep examples simple and easy to read. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Java Academy?

No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Testing & Extensions” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Java Academy lesson?

Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Requirements & Design
  2. Implementation
  3. Testing & Extensions
← Back to Java Academy