To code, to program, or to mod. Yes, I make a distinction between simply coding (writing technically valid code in some language) and programming (developing software to solve an actual problem).
I learned the basics of Java from a teach yourself in 21 days book, about 15 years ago. Then, after being poor and without a computer for many years I re-learned Java from the official tutorials that Oracle has (https://docs.oracle.com/javase/tutorial/), though those might go a bit fast for someone who has never written code before. Before that I'd learned Atari Basic, Pascal, and beginning C++ (in that order). I was self-taught in all but Pascal (which I had a class on in high school), starting with Basic when I was in elementary school.
Really learning to program was then a mater of practice -- the more you do it that better you get. Once you know the basics of a language, the thing to do is just start trying to do things with it. No matter what books you read or videos you watch you will never really know how to program unless you put time into programming -- like any skill it requires practice.
As for modding, I watched some old videos by SweGoesMincraft (or something like that) which were for 1.6.4, to get the basics -- how to get Forge to recognize it as a mod, how to have Forge initialize it, etc. For there it was a mater looking through the code and figuring things out. This is also a skill; at first it can be hard -- Minecraft is most often not organized in the way I'd find most obvious. But a lot of it was trying things and see if they worked, looking at error reports to track down anything that actually crashed, struggling to figure what was going wrong if I didn't get the results I wanted. I remember the first time I got something to generate in game -- a quartz pillar though the middle of each chunk -- it seemed so cool that I'd made the game do *something*. I then went on to have it build scattered empty rooms, then rooms with content, then whole procedural dungeons (my real goal), and at each step I felt good that I'd made it work. That is how you learn to mod.