I want to learn how I can create an injectable piece of java bytecode, and inject it into an already compiled java program so it will run when the said program is executed. It doesn't have to be dynamic and in runtime, just given a compiled java program inject additional code into it.
Now, I know there are many existing tools for this, like Javassist and ASM. But the act itself isn't my goal, I want to learn how its done, so I want to learn how to do this without these tools.
For example: How to strip excess code from the source bytecode, where to inject it into the target code, etc.
The best answer would be one or more simple pieces of source or pseudo-code. After learning and successfully doing this I'm going to start searching info on how to do this to Linux executable binaries, so adding in more information on that way would also be very helpful and appreciated.
Javassist is essentially decompiling and compiling the code, that is why there is a lot of code there. And you won't find the type code injection you are looking for in javassist. So "Go read javassist" is a rather stupid suggestion.
If you want to put your code into an specific place(for instance in the start or constructor) you can see how to find the spot by reading JVM docs.
However as Antimony mentioned, you are looking for bytecode knowledge, so here it is: http://arhipov.blogspot.com.au/2011/01/java-bytecode-fundamentals.html
If you want to inject a piece of bytecode,you can just find the start of your main() and paste the code there. It will be 200-300 LOC MAX.
With linux binaries it is much easier, read this: http://www.skyfree.org/linux/references/ELF_Format.pdf