Java Developer – job interview questions + answers
For many years there has been no shortage of opinions that we are witnessing the end of Java, they are almost memetic in nature. Meanwhile, Java is still doing fine, being the main programming language for a huge number of IT workers. So how do you prepare for an interview for a Java Developer position?
Java Developer in Poland
Before we get into the details, it is worth outlining who a Java Developer is in Poland today. We will use for this IT Community Report, according to which Java is known to as many as 34% of those surveyed. What is important, Java is the main programming language among backend developers (39%), who are also the largest group among all IT specialties. Java Developers are also most likely to know SQL (61%), JavaScript (43%), as well as HTML and CSS (34%).
Java developers are not badly paid in Poland compared to programmers working with other languages. For an employment contract, a Java developer can expect an average of PLN 8,275, which is more than the salary of programmers using Python, C# or JavaScript. For Java developers employed for a B2B contract, average salary is PLN 18,629, and these are net on the invoice. Contracts of mandate and contracts for specific work are valued at an average of PLN 5,875 per month.
Frameworks and libraries
Before the interview, you should know that Java is an object-oriented language with strong typing that uses a virtual machine to execute code. This is of great importance – it makes it possible to run code written in Java on multiple platforms and architectures, but it also presents some challenges.
Compiling source code into intermediate code sometimes makes programs written in Java slower than those compiled directly. Among other reasons, this is why the idea that was originally behind the birth of Java never came to life, as it was supposed to be the successor to C++ as the main general-purpose universal language.
For years, Spring has remained the most popular Java framework. It is free software distributed free of charge under the Apache 2.0 license. The tool offers a multitude of components that are templates. Among them, it is worth mentioning the IoC container that allows the use of the control inversion technique, the Model-View-Controller template or the template that allows the implementation of user authentication. You can read the details about Spring in the framework documentation.
Less popular than Spring is the Hibernate framework developed by Red Hat, which is used by 26% of Java developers. At its core is, nomen omen, the Hibernate Core, a library with which object-relational mappings can be performed using XML files in Java. The Angular framework also has some popularity among javascripters.
In preparation for the interview, it is undoubtedly also worth refreshing yourself with information on the most popular libraries. The most popular of these is probably JUnit, which is used for software testing. In addition, it is worth knowing about the Guava library, a set of tools developed by Google for internal use. After all, it should be remembered that until a few years ago Java was the main programming language on Android and was only relatively recently replaced by Kotlin. Also popular is the Log4j library for logging, which has admittedly covered itself in some infamy recently – as we have written more about here – nevertheless it is still used on a very large scale.
Key issues
As befits an object-oriented language, classes are crucial in Java. And also objects that are instances of classes and methods. The range of variables is integer, floating point and text variables. As in other object-oriented languages, important features of Java are inheritance, encapsulation, abstraction, polymorphism and interface. Compilation follows JiT, or jut-in-time (only the code that is needed in a given case is compiled, not the entire source code, which can be given by the candidate during the interview as an example of mechanisms that positively affect Java performance.)
In addition, there are eight main types in use:
boolean
– classic Boolean logic, taking values of true or false.char
– a data type that can contain one single character. It is more common to use string, which, however, is not the main type.double
– used to store floating-point numbers, a type with a maximum size of 8 bytes, which results in a value with a maximum of 14-15 digits after the decimal point.byte
– a byte storing integers in the range from -128 to 127.float
– just like double it is a data type of floating point numbers, but it differs in size. Instead of 8 bytes, here we have 4 bytes.int
– type for integers from -2,147,483,648 to 2,147,483,647.long
– eight-byte type for integers from -263 up to 263.short
– a two-byte integer type from -32,768 to 32,767.
As for the mathematical operators used in Java, there are 5 of them: +, -, * used for multiplication, / which performs division and % which allows division with remainder. In addition, logical operators are used for the boolean type.
Sample questions
After the initial phase of the interview, during which you can expect to test interpersonal skills or topics based on the nature of the project the candidate will potentially be working on, expect general questions that test more than just general knowledge of the language. After them, however, you can expect specific technical questions. Let's take a look at the ones that appear most often.
What is inheritance in Java?
Inheritance is a Java feature that allows code from one class to be used in another class. A new class (subclass) inherits functions from an existing class (superclass). This allows Java to reuse already written code, so that new classes can receive fields and methods after classes of the super field type. Each class has at least one super class, and in case this one is not specified, the super class is Object
, which no longer has a super class above.
What is encapsulation in Java?
Encapsulation is also called data encapsulation. In a nutshell, it's about a Java feature that allows you to protect your data. It is enough to specify the type of a variable as private so that it is impossible for another class to modify it later, while the value of a private
variable is available only to its own class. Variable modifiers that allow you to take advantage of encapsulation are the already mentioned private
, which makes the data visible only inside the class. The value of a private variable cannot be inherited (see above). If there is no modifier (keyword), the value of the variable is visible in the whole package. The protected
keyword allows visibility of data in the package and inheritance, public data is globally visible and can be inherited.
What is the difference between an array and lists?
For Java arrays, it is necessary to specify their size at the time of declaration, placing an object requires defining an index. The most important feature of lists that make the difference compared to arrays is the dynamic size – it does not have to be predetermined at the time of declaration. Lists do not have to have indexes either.
What are keywords?
Keywords are 67 reserved words in Java that have specific predefined uses. We have already dealt with examples of keywords, these are the modifiers described above that allow data encapsulation. Keywords can also be words that specify variable types (e.g. string
), loops (e.g. while
).
What is method overriding?
The concept of method overrides follows directly from inheritance. It occurs when a subclass has the same methods declared as a superclass. To make an override happen, the following conditions must be met: the method in both classes must have the same name and parameters, and there must be inheritance.
What are the constructors?
Constructors in Java are a special kind of methods or rather we can say are similar to them. Constructors are used to initialize objects, and can also be used to initialize values for object attributes. There are key differences from ordinary methods: constructors must have the same name as the classes in which they are defined, they also do not return a type or void, and they are called only once, when objects are initialized.
What causes the use of the keyword final?
The use of the final
keyword varies depending on what we apply them for:
- in relation to the class it will result in the fact that these will no longer be expandable. However, this does not mean that it will be unchangeable. It will just no longer be expandable.
- In the case of methods, the use of the final keyword will ensure that such a method cannot be overwritten.
final
variables cannot be replaced by others after initialization, the value assigned once when declaring a variable remains unchanged.- Fields marked
final
can either be fixed or its value will only be given once
A separate part of the interview may be practical tasks, and it is also possible that the candidate will be asked to do "homework" – in such a case he will be asked to solve a more elaborate problem. The most common type of practical tasks we can get during our interview are those where the candidate is asked to analyze a code and give the results on that basis. It is then necessary to be vigilant, as the task is often designed to test knowledge of nuances or Java catches that less experienced developers may overlook.
Useful links
There are, of course, examples that can be multiplied, so it is recommended to track online databases on your own. At the very end, for completeness or refreshment, we suggest some useful links:
- Job offers for Java Developers,
- Java Developer - how to start a career,
- Java Developer - jobs and salaries in Poland,
- Java 18 available now. Learn all the news,
- 10 excellent GitHub repositories for every Java developer,
- Java trends predictions in 2022.