Could you list the possibilities for Java code to modify itself? The scenario in which this is going to be used is a learning program. In response to user input the program learns a new algorithm:
- it looks up the existing code base for a similar algorithm
- if no similar algorithm is in the code base, the program just adds a new algorithm
- if a similar algorithm exists, the program (perhaps with some help from the user) modifies the existing algorithm to be able to serve both the old purpose and the new purpose
A similar question exists Self modifying code in Java , but at that time the latest Java available was 6, and that question was closed as too broad.
A Java program can dynamically compile and load automatically-generated classes (see JavaCompiler), but I don't think that it is what a machine-learning program would do. Most certainly, the programmer creates an algorithm depending on several parameters to estimate, and running the program simply consists in finding optimal values for those parameters.