-1

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:

  1. it looks up the existing code base for a similar algorithm
  2. if no similar algorithm is in the code base, the program just adds a new algorithm
  3. 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.

Community
  • 1
  • 1
Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158
  • 1
    None of these scenarios imply that a program needs to modify *itself*. – Oliver Charlesworth Oct 12 '14 at 11:02
  • If the program doesn't modify itself, it would have to interpret the newly learned algorithms, which is at least slow. – Serge Rogatch Oct 12 '14 at 11:05
  • As several of the answers to the other question suggested, you have the option of generating and loading byte-code at runtime. No interpretation required. – Oliver Charlesworth Oct 12 '14 at 11:07
  • Maybe you are interested in [Genetic Programming](http://en.wikipedia.org/wiki/Genetic_programming). It's a subfield of evolutionary algorithms and deals with the creation of algorithms, but has nothing to do with self modifiying code... – tsabsch Oct 12 '14 at 11:12
  • I am somewhat interested in Genetic Programming, thanks, but that is a separate topic. In this question I try to focus on just the facilities for self-modification in Java. Evolution of computer programs is another usage scenario for self-modification. – Serge Rogatch Oct 12 '14 at 11:17

1 Answers1

0

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.

Dici
  • 25,226
  • 7
  • 41
  • 82
  • Current machine learning algorithms don't yet do self-modification - true. But in the scenario of a program which would learn algorithms, the program would need to execute those algorithms. – Serge Rogatch Oct 12 '14 at 11:18