How does typical editors for java work? How do they associate javac and java to the editor so that once you say compile and run, it directs the file to the compiler, and extracts the output to the editor?
It will entirely depend on the editor - but "advanced" IDEs will usually have at least a parser built in, to provide syntax highlighting, IntelliSense, pre-compilation error highlighting, refactoring etc. They may have a full built-in compiler like Eclipse does, to offer smart incremental compilation.
A more primitive level of integration is more likely to effectively "shell out" to javac, possibly by way of Ant.
Editors have in common, that they apply changes ('edits') to a file on a file system. So basically, the Java editor reads the Java text file, allows changes to the text and allows saving the edited content.
Compiling or executing a Java application is a separate action, where usually the javac (or java) executable is invoked to compile (or execute) the java files.