Book Image

The Complete Coding Interview Guide in Java

By : Anghel Leonard
Book Image

The Complete Coding Interview Guide in Java

By: Anghel Leonard

Overview of this book

Java is one of the most sought-after programming languages in the job market, but cracking the coding interview in this challenging economy might not be easy. This comprehensive guide will help you to tackle various challenges faced in a coding job interview and avoid common interview mistakes, and will ultimately guide you toward landing your job as a Java developer. This book contains two crucial elements of coding interviews - a brief section that will take you through non-technical interview questions, while the more comprehensive part covers over 200 coding interview problems along with their hands-on solutions. This book will help you to develop skills in data structures and algorithms, which technical interviewers look for in a candidate, by solving various problems based on these topics covering a wide range of concepts such as arrays, strings, maps, linked lists, sorting, and searching. You'll find out how to approach a coding interview problem in a structured way that produces faster results. Toward the final chapters, you'll learn to solve tricky questions about concurrency, functional programming, and system scalability. By the end of this book, you'll have learned how to solve Java coding problems commonly used in interviews, and will have developed the confidence to secure your Java-centric dream job.
Table of Contents (25 chapters)
1
Section 1: The Non-Technical Part of an Interview
7
Section 2: Concepts
12
Section 3: Algorithms and Data Structures
19
Section 4: Bonus – Concurrency and Functional Programming

Know yourself

Before searching for a job, it is important to know yourself. This means that you should know what kind of developer you are and what kind of job you want.

This is crucial to getting the right experience, evolving your package of skills, and finding the right employer. Most probably, you can cover a wide range of Java programming tasks, but do you find all of them equally engaging? Doing something that you don’t like for a short period of time is OK, but it will not work for the long term.

Ideally, in the long term, you must focus on what you like to do the most! This way, you maximize your chances of becoming a top Java developer. But, doing what you like the most should be considered in the context of what the IT market offers (in both the short term, and most importantly, the long term). Some Java technologies are widely covered by job offers, while others may require a lot of time to find a job or must make some really unpleasant trade-offs (for example, relocation). It is strongly advisable to periodically consult and participate (every vote counts) in the most relevant Java surveys conducted by websites such as blogs.oracle.com, snyk.io, jaxenter.com, codeburst.io, jetbrains.com, and dzone.com. Having a wide range of companies to choose from statistically maximizes the chances of finding the right company for you. This is half of the problem, while the other half is to prepare yourself to make sure that the company with the job you want will want you.

Now, let’s examine 10 questions that will help you to identify what kind of developer you plan to become. Look inside yourself and try to overlap your personality and skills in considering the following questions and explanations:

  1. Are you interested in developing user interfaces or the heavy business logic that is executed behind the scenes? Developing great user interfaces is an extremely important aspect of a graphical interface. After all, the graphical interface is what the end user sees and interacts with. It requires creativity, innovation, vision, and psychology (for example, developing multi-device interfaces is quite challenging). It requires knowledge of Java AWT, Swing, JavaFX, Vaadin, and so on. On the other hand, the business logic that is executed behind the scenes and answers to end user actions is the engine behind the interface, but, for the end user, most of the time it is a black box. The business logic requires strong coding skills and solid knowledge of algorithms, data structures, frameworks (such as Spring Boot, Jakarta EE, and Hibernate), databases, and so on. Most Java developers opt for coding the business logic behind the scenes (for desktop and web applications).
  2. What kind of applications do you find most engaging (desktop, mobile, web, or others)? Each type of application has specific challenges and dedicated suites of tools. Today, companies target as many consumers as possible, therefore, modern applications should be available for multi-platform devices. Most of all, you should be able to code in the knowledge that the application will be exposed on different devices and will interact with other systems.
  3. Are you especially interested in testing, debugging, and/or code review? Having strong skills in writing valuable tests, finding bugs, and reviewing the code are the most important skills for guaranteeing a high-quality final product. Of these three areas, we should focus on testing, as almost any Java developer job description requires the candidate to have strong skills in writing unit tests and integration tests (the most commonly preferred tools are JUnit, TestNG, Mockito, and Cucumber-JVM). Nevertheless, trying to find a dedicated Java tester job or Java code reviewer is quite challenging and is usually encountered in big companies (especially in companies that provide remote jobs, such as Upstack or Crossover). Most companies prefer pair code review and each Java developer should write meaningful tests that provide high coverage for the code that they wrote. So you have to be able do both: write astonishing code, and write the tests for that code.
  4. Are you interested in applications that interact with databases or do you try to avoid such applications? Most Java applications use a database (a relational database or a NoSQL database). A wide range of Java developer jobs will imperatively require you to have strong knowledge of coding against a database via Object Relational Mapping frameworks (such as Hibernate), JPA implementations (such as Hibernate JPA or Eclipse Link), or SQL-centric libraries (such as jOOQ). Most Java applications interact with a relational database such as MySQL, PostgreSQL, Oracle, or SQL Server. But NoSQL databases such as MongoDB, Redis, or Cassandra are also encountered in a significant number of applications. Trying to avoid developing applications that interact with a database may seriously limit the range of jobs on offer. If this is your case, then you should reconsider this aspect starting today.
  5. Do you have a predilection for code optimization and performance? Caring about the performance of your code is a highly appreciated skill. Such actions will catalog you as a perfectionist with great attention to detail. Having solutions that optimize the code and increase its performances will place you pretty quickly in the position of getting involved in designing and architecting the solutions of functional requirements. But at the interview (the code challenge stage), don’t focus on code optimizations and performance! Simply focus on delivering a working solution and, as much as possible, clean code.
  6. What is more appealing to you: a coding-focused job or being a software architect? At the beginning of your career as a Java developer, you will be focused on coding and taking implementation design decisions at code level. In time, some developers discover their abilities and interest in architecting large applications. This means that it’s time to evolve from a Java developer to a Java architect, or even a Java chief architect. While coding is still part of your job, as an architect you will wear different hats on the same day. You have to split your time between meetings, architecting, and coding. If you feel that you have the aptitude for designing and architecting different pieces of a project, then it is advisable to consider some training in software architecture as well. Moreover, during your coding-focused job, challenge yourself to see what solutions you can find and compare them with those implemented by the current architect of the application.
  7. Are you aiming for a small or a big company? Choosing between a small or a big company is a matter of trade-offs. Ideally, a big company (a brand) will give stability, a career path, and a good salary plan. But you may feel stifled by the bureaucracy, lack of communication and rivalry between departments, and a cold and rigid environment. In a small company, you have the chance to feel more intensely that you are part of the success and will get a nice, warm feeling of being part of a small community (even a family). However, small companies may fail fast and you might be fired in a year or two, most likely without any compensation package.
  8. Do you target a software company (working on a wide range of projects) or a certain industry (for example, the oil industry, medicine, the automobile industry, and so on)? A software company manages projects from a variety of fields (for example, a software company might develop a website for a Hollywood star, a financial application, and an airline traffic control application at the same time). From a developer’s perspective, this means that you need versatile thinking and to be capable of quickly adapting to understand the requirements of different business domains without diving into those domains. On the other hand, big industries (for example, the oil industry) prefer to create their own IT departments that develop and maintain applications specific to that company field. In such cases, you would most likely receive some training in the given company’s field as well. You will have the advantage of becoming an expert at developing applications specific to a certain domain.
  9. Do you prefer a remote job? In the past few years, a significant number of companies have decided to hire remote developers. Moreover, new companies such as Upwork, Remote|OK, X-Team, and Crossover are 100% remote companies recruiting only for remote positions. The advantage of working from any corner of the world with a flexible program is quite appealing. These companies offer jobs for junior, middle, and senior developers, and some of them (for example, Crossover) offer remote management positions as well. But, you have to be aware of some of the other aspects of this arrangement as well: it is possible that you will be monitored via webcam (for example, with snapshots every 10 minutes); you need to work in a completely remote team with members from different time zones (it may be challenging to participate in meetings at night, for example); you will have to be familiar with tools including JIRA, GitHub, Zoom, Slack, Meetup, and in-house marketplace platforms; you may face a lot of friction (tons of emails) and a lack of communication; you need to pay your taxes, and last but not least, you may need to achieve unreal metrics to the detriment of quality to maintain your position.
  10. Does management interest you? Commonly, reaching a managerial position is a goal that requires leadership skills. In other words, you should be able to take important decisions at both the technical and human levels. From this perspective, you need to avoid companies that offer a solid technical career path but don’t provide opportunities to get promoted to the ranks of management.

    Important note

    Knowing yourself is one of the hardest parts required in order to make the best decisions in life. Sometimes, asking the opinion of other people is the best way to eliminate your subjective view of yourself. Most of the time, asking your teachers, parents, and friends will help you to better understand what your skills are and where you fit the best. Making important decisions alone is risky.

Once you know yourself, it is time to get to know the market.