Should I learn first design patterns or object oriented principles?

This is a question I faced while chatting with a Junior Java Developer recently. I think it is an interesting question, especially because it seems the two things could be put on the same level at first glance.

You find below my answer, hoping it is clear enough and that may help someone else clarifying this.

Think at the two words. What a pattern is in this context? A solution to an already seen problem. You shouldn’t look for or force patterns in your code but the fact you know them may save you some time/pain.

If you realise that for the problem you are facing you need an object that can be instantiated one and only one time, you may spend time for finding how to implement such mechanism or you may remind that this is a Singleton pattern. So you already have the solution. Patterns are all about not reinventing the wheel.

On the other side principles are the fundamental bricks of your coding paradigm. You may not know patterns and still write decent code. Pattern may change or became obsolete. For example in Spring all the beans are singleton by default. If you always work with such framework you may never see a Singleton implementation.

But you MUST know, understand and master principles.