Writing deterministic programs is often difficult for problems whose optimal solutions depend on unpredictable properties of the programs’ inputs. Difficulty is also encountered for problems where the programmer is uncertain about how to best implement certain aspects of a solution. For such problems a mixed strategy of deterministic programming and machine learning can often be very helpful: Initially, define those parts of the program that are well understood and leave the other parts loosely defined through default actions, but also define how those actions can be improved depending on results from actual program runs. Then run the program repeatedly and let the loosely defined parts adapt. In this paper we present a library for Java that facilitates this style of programming, called adaptation-based programming. We motivate the design of the library, define the semantics of adaptation-based programming, and demonstrate through two evaluations that the approach works well ...