JavaRush /Java Blog /Random EN /Kay Horstmann and his 1500 words on how to become a bette...

Kay Horstmann and his 1500 words on how to become a better Java programmer

Published in the Random EN group
Chances are you've already heard the name Cay S. Horstmann. He is a fairly prominent person in the Java world and the author of many books on our beloved language. Among them are the classic course “Core Java” (published in Russian in the two-volume book “Java. Professional’s Library” ) and a series with a brief summary of the essence of “Java for Impatient” (published in Russian “Java SE 8. Introductory Course” and “Java SE 8. Basic course " ). He bears the proud title of “Java Champion”. And at this link you can find his old school website with interesting information.
Kay Horstmann and his 1500 words on how to become a better Java programmer - 1
We bring to your attention a translation of an article for the InformIT resource , in which Kay voices several tips for beginning and continuing programmers on how to become better in their profession. One day, Jennifer Bortel, editorial director of InformIT, asked me to drop a line on how to become a better Java programmer. She suggested that I, the author of Core Java for the Impatient, might know something about it. “There’s nothing easier, just buy a book,” I thought at first. But this answer didn’t work, because I have to fit it into 1500 words, and up to this point there are only 62 of them * ( of course, when translating the article, we did not try to maintain the number of words - approx. transl. ). I recently received an email from a developer friend who was asked at an interview why the following code was not thread safe:
class ThreadSafeClass extends Thread
{
     private static int count = 0;

     public synchronized static void increment()
     {
         count++;
     }

     public synchronized void decrement()
     {
         count--;
     }
}
My friend decided that the code in this example was thread safe, and I agreed with him, noting that there was one keyword missing staticin the second method, and once it was inserted, access was controlled by the class object's built-in lock. I also said that this is not a good interview question because if you need a thread counter, you're better off using AtomicInteger. But then in the middle of the night I woke up and wondered: what if this word staticwas left out for a reason? Perhaps some sneaky interviewer deliberately structured this example in such a way as to mislead candidates? So I wrote back to the developer who asked the question and said that I was probably wrong earlier: in a parallel universe called Interview Questions, the answer to this question is: “The second method contains an object lock.” After this answer, the guy asked if I run a YouTube channel where I teach how to handle these types of interview problems. Alas, I don't do this. I teach computer science and write books, but my main goal is not to make better “interview problem solvers,” but to make my students better programmers. Once upon a time, Peter Norvig ( American scientist in the field of artificial intelligence, Google research director - approx. trans. ) wrote a wonderful article on his blog. He argued that books that promise to teach you Java in 24 hours or 21 days are simply ridiculous. It's hard to disagree with him: it takes 10 years, or perhaps 10,000 hours, to become an expert in any field. And it is well known that experts process information differently from novices. In a classic experiment, experienced and novice chess players were shown a chessboard with a certain arrangement of pieces for a few seconds, and then it was hidden and asked to arrange the pieces as they were. Beginners did not cope with the task very well, but experts did not have any problems. But only under one important condition: the arrangement of the pieces must correspond to the real game . If the pieces were placed randomly, the experts were no better at rebuilding the board than the novices.
Kay Horstmann and his 1500 words on how to become a better Java programmer - 2
That is why I answered the question from the letter exactly the way I did. My background is in actual programming, not interviewing, so I instinctively added the missing keyword and made the “wrong” conclusion. I'd like to think that I would still be hired after I explained what happened and why I would never write code like the example without my addition. Perhaps, if such an answer did not satisfy them, I myself would not want to work with them.
Now, I don't think that studying for certification exams or interviews will turn you into a better programmer. I am also sure that buying a large number of books on programming and then reading them from cover to cover will not work either (although I, as the author of these very books, would not like to admit it!). In fact, a really good way to become a better programmer is to create as much software as possible . From time to time I teach an introductory computer science course at my university. This is by far the most difficult course I have ever taught. It is even more difficult than the graduate course. When I first started working as a young professor, I diligently gave lectures to students in which I dutifully covered programming issues, such as the difference between loops forand whileloops do. I then assigned students four three-week projects. And this subject has been taught this way since the beginning of time in all universities. After my first attempt, the instructor of the second-semester course complained that most of my former students did not really understand even simple loops after their first semester of programming. And such results have also taken place since the beginning of time. Remember the article “FizzBuzz or why programmers can’t program” ? When you learn a foreign language, most tasks are exercises and practice, not theory at all. It is extremely important to “push” knowledge into the subconscious. The turning point comes when you no longer have to actively think about each cycle, or (in the case of French), each irregular verb. If this moment has come, then you are ready to move to the next level. And there is nothing revolutionary in this idea.
Kay Horstmann and his 1500 words on how to become a better Java programmer - 3
The key to everything is instant feedback. Some psychologists believe we could do much more with computer-based learning with instant feedback. For example, in another classic experiment, aspiring trainee pilots underwent a training session in which they were required to look at the instrument panel over and over again and describe the movement of the airplane. At the same time, they received instant feedback indicating whether they did it correctly or not. After two hours of training, they outperformed the experienced pilots. Of course, this did not mean that they could immediately be sent on a real flight, but they were no longer nervous about the varied and numerous dials on the instrument panel. So, if you are just starting to learn Java, doing lots of practice exercises to practice is the best idea. There are a large number of websites and online courses that automatically check the correctness of your code. Choose one that offers real challenges rather than gobbledygook. After all, you want your subconscious to be good at the code you'll actually write in practice. This is why I'm not very keen on programming examples that use contrived situations, such as animal classes with methods that meow and bark. After some time, you will master the basics of programming. To move to the next level, you can write a couple of projects. Several years ago, the InformIT portal asked experienced programmers a question: “What is the best way for a programmer to learn a new language?” If we summarize their answers, we can conclude the following: “use this language in your current project.” So, think about what you have always wanted to implement - and go ahead. Twenty years ago, when Java was still very young,my friend and sometime co-author Gary Cornell called me and said, “Kay, we're going to write a book on Java.” " My answer was that neither he nor I really know anything about this Java, to which he retorted: “So what? We already have a book deal." Nothing to do. We had to hurry because someone else announced the imminent release of the book "Teach Yourself to Be a Java Dummy in 24 Hours" ... I think it was called something like that ( Kay makes fun of the "For Dummies" series of books - "for dummies" the word "Dummy" can be translated as "dummy" - translator's note ). To learn a new language, I started with projects - writing a program that created a user interface for retirement planning, and then a program that connected to a weather site and displayed a weather report. After it - a program that simulates the movement of cars on the highway. At that time, these programs were simply amazing!java.awtjava.netand threads ( threads). And I had to learn how to actually make this work, not just what the documentation says. At that time these were completely different things. That's why Core Java [1] was a hit: it wasn't for dummies.
Kay Horstmann and his 1500 words on how to become a better Java programmer - 4
At that time, learning Java was much more difficult. We didn’t have sites like Stack Overflow ( and we didn’t have JavaRush either - editor’s note ). At this point, I move on to formulate the following advice for improving your programming “skill”. So, when you work on your own project, you are bound to get stuck somewhere. In this case, go to a specialized forum and try to find answers. Believe me, this is a great idea . First, you will ask questions that have already been asked many times before. But soon you will gain knowledge and your questions will become more unique. This is an amazing way to learn! Of course, this is not about just copy-pasting a piece of code and asking: “What should I do with this now?” You need to get to the bottom of it, explain what attempts you have already made to solve the problem before you got stuck. By the way, in most cases, while I formulate a question in writing, I find the answer myself and all I have to do is say to myself: “What is the problem here, it’s a no brainer” even before I sent the question. But even if this doesn't happen... Believe me, thoughtful questions tend to attract thoughtful answers. Just remember to return the social favor by answering other people's thoughtful questions. Both asking questions and answering thoughtful questions make you a better programmer. “So, what about the books? - you ask. “Have they really become completely and irrevocably obsolete thanks to Google and Stack Overflow ?” Whenever I navigate a new technology, I believe that I am a courageous person and can overcome all difficulties alone. But an hour of senseless torment gives way to an hour of sanity - and I buy a book. Technical books are a stunning bargain these days. If I pay $40 for an e-book and only get one question answered quickly, I've already made my money back. I hate to disappoint my fellow writers, but I have never read a technical book from start to finish. I start where I think my problem and its solution are written, and I read until I understand how to solve it. For this reason, I am currently trying to write books that can be read this way. This approach gave rise to the series “For the Impatient.” And at this point I should stop - I exceeded the editorial limit of 1500 words. Let me just add that to become a better programmer, start by recognizing that there are many levels of knowledge.
  1. First, “pull” basic language structures into your subconscious, that is, bring their knowledge to automaticity by solving a large number of exercises.

  2. Get started working on real projects that interest you as quickly as possible.

  3. Then join a community where you can ask and answer questions.

  4. Once you do this, you will be able to speak with knowledge and experience in interviews. And it doesn't really matter whether you solve the contrived puzzle.
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION