I would like to immediately warn novice programmers from cramming. Unlike the languages we speak, programming languages have very few exceptions to the rules, and the number of keywords and constructs rarely exceeds a hundred. Moreover, when writing programs, if you are certainly not going to work in a notebook, you can always use the modern code editors and IDEs that analyze the code, make hints, mark your mistakes, thereby speeding up development.
But there are things in programming that really need to be learned for two reasons. Firstly, in order to successfully pass the interview, demonstrating your skills, and secondly, just so as not to waste your time searching for the same information. Such things include, for example, the basic design algorithms and patterns (patterns), as well as the syntax and basic functions of the programming language in which you are going to write most of the time.
What is the best way to learn these things? Just memorize without getting into the gist? Unlikely. You can either find training on the Internet for memory and do exercises “remember a series of words and repeat”, “remember numbers and repeat”, or learn poetry. Yes, it will undoubtedly benefit you and your brain, but will it make you a great programmer? Most likely no. But what really can help is constant practice. If you write code every day, at least for a couple of hours, in your favorite programming language (or the one you want to work with in the future) and not just mindlessly copy the code from sites such as StackOverflow, namely, write, understanding that makes every character of your code, then very soon you will catch yourself thinking that you are writing from memory, and you do not have to peek at each construction in the textbook / documentation.
In addition, I can advise you to “save yourself a piggy bank” with interesting constructions and code fragments in order not to re-write the same algorithm in the future, but to take a peek at yourself. Such pieces are usually called snippets of code, from the English snippet – excerpt, fragment. There are also free services for storing such pieces of code, such as the GitHub Gist.
To summarize, I want to recommend not to memorize everything in a row, but first of all to understand what you are writing and why your code works this way and not otherwise. It is enough to learn the most basic and most frequently used things, and most likely, they themselves will quickly be remembered. The rest is important to be able to quickly find in the textbook or in the documentation.