
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
Explore generics in Java through a focused set of coding exercises with automatic feedback on each solution, while videos explain solutions and help deepen understanding.
Java generics exercise shows how to implement a method taking a string array and returning a linked list of strings. Iterate the array, add each string, and return the list.
Define a longest string finder that implements the consumer generic interface, uses the for each method to process strings via accept, and exposes the longest result.
Implement and compare rectangles by area using the comparator interface and Arrays.sort. Complete the rectangle class to implement comparable and use a comparator for sorting by area.
Implement a generic list generator by passing a generator object and a size to populate a list with new objects, using a lambda or anonymous class for generation.
Access solutions for every quoting exercise, with optional video clips that explain the solutions, and request new or updated clips to support your ongoing learning of Java.
Explore how Java implements generics at the compiler level, so a generic class like box doesn't create new classes for different types, unlike C#. Reflection shows a single box class.
Explore why Java generics do not support covariance, showing that a linked list of derived elements cannot be assigned to a base-typed variable to preserve type safety.
Explore how static memory differs from instance memory in a generic class and why a static variable cannot use the unknown type; removing static makes it an instance variable.
Explore the limitations of generics in Java arrays, learn why an unknown element type causes compile errors, and see practical workarounds with setters and array creation.
This course was designed to help you strengthen your Java programming skills by focusing specifically on one of the most powerful and widely used language features: generics. Through a comprehensive set of hands-on exercises, you’ll gain practical experience in using and defining generic classes and interfaces, working with bounded wildcards, and understanding the limitations and capabilities of generics in Java.
Sharpen Your Java Skills with a Focused and Practical Approach to Generics
Learn how to define and implement your own generic classes
Understand how to use Java’s built-in generic types effectively
Explore the use of bounded wildcards and their role in type flexibility
Recognize the constraints and limitations of generics in real-world applications
This course includes more than ten coding exercises, each focused on a specific concept related to Java generics. Additional exercises will be added over time in response to student feedback and requests. Every exercise provides partially written code for you to complete and submit, helping you actively engage with the material.
This course is ideal for students who are already familiar with Java’s object-oriented features and basic generics concepts but want to deepen their understanding through practice. It bridges the gap between theoretical knowledge and practical application.
If you find a specific exercise challenging or would like more exercises on particular topics, we welcome your input! We are happy to assist, refine existing explanations, or even create new video clips that explain specific topics.