Industry experts declared 2021 “the year of Java developers”, after demand and salary levels increased for qualified, experienced Java developers. Last year, Glassdoor ranked Java developer as the number one job in the US, with a job satisfaction rating of 4.2 out of 5.
As you grow your career as a Java developer, the interview questions and assessments you may be asked will evolve accordingly. Not only has the market changed over the past few years, but senior Java developers will be asked to manage more complex projects — and oversee developers who are highly skilled, too.
Prepare for your next job interview by reviewing some of these common senior java developer interview questions and thinking through answers that reflect your experience and expertise.
Compare the sleep() and wait() methods in Java: when and why would you use one over the other?
Sleep() is a method that’s used to pause a process for a few seconds or a specified period of milliseconds. In contrast, wait() pauses the thread until a specified number of milliseconds has elapsed or until you call the notify() or notifyAll(). Essentially, the biggest difference is that wait() releases the lock or monitor while sleep() doesn’t release the lock or monitor while waiting.
Sleep() is commonly used for polling and checking for results at regular intervals. Wait(), on the other hand, is better suited for multithreaded applications; used with notify() or notifyAll(), it can help achieve synchronization.
Interviewers ask this question to ensure you have technical knowledge of Java, but also so to see how you can correct a team member’s work if needed. Senior Java developers would understand this key difference and be able to share with other developers the proper application of these processes.
How is Java SE related to Java EE?
There are four platforms of the Java programming language: Java Platform, Standard Edition (Java SE), Java Platform, Enterprise Edition (Java EE), Java Platform, Micro Edition (Java ME), and JavaFX. The main ones are Java SE and Java EE.
Java SE provides the core functionality of the Java programming language. This API defines the basic types and objects of the language, all the way up to high-level networking, security, database access, and XML parsing. The Java SE platform consists of development tools, class libraries and toolkits, deployment technologies, and more.
Java EE, by comparison, is a platform built on top of Java SE. It provides an API and runtime environment that can be utilized for running large-scale, multi-tiered, and secure network applications. Java EE includes many components of the Java Standard Edition (Java SE).
What is the volatile keyword in Java?
Java grants each thread its own stack that includes its own copy of variables that it can access. The thread copies the value of all accessible variables into its own stack when it’s created.
The volatile keyword tells the JVM when a variable may be modified in another threat. The volatile keyword guarantees global ordering on reads and writes to a variable. It ensures that every thread accessing a volatile field will read the variable’s current value, instead of a cached value.
How would you create an immutable object?
An immutable object is one that cannot change after it’s constructive. It’s a key foundation of simple, reliable code. However, Java developers are sometimes reluctant to use immutable objects if they need to account for updates down the line.
Oracle offers four ways to create immutable objects:
1. Don't provide "setter" methods — methods that modify fields or objects referred to by fields.
2. Make all fields final and private.
3. Don't allow subclasses to override methods. The simplest way to do this is to declare the class as final. A more sophisticated approach is to make the constructor private and construct instances in factory methods.
4. If the instance fields include references to mutable objects, don't allow those objects to be changed:
- Don't provide methods that modify the mutable objects.
- Don't share references to the mutable objects. Never store references to external, mutable oaZ
This strategy is considered advanced and shows that you’re at the senior level of development.
Would it be more secure to store PII in a character array or a string?
Strings are immutable, and as we covered in the previous question, that means they cannot be changed. As a result, once the string is created, it stays in memory even after you’re done processing the spring value. This can put PII (personally identifiable information, such as SSNs, credit card numbers, or birth dates) at risk. Anyone that has access to a memory dump can potentially extract this valuable data.
A character array is mutable, so you can set it to blank once you’ve finished with it. This keeps the PII from falling into the wrong hands.
Security is one of the biggest threats companies of all sizes face. Data breaches cost businesses millions, if not billions of dollars each year. Senior Java developers must understand how to securely work with potentially sensitive IP, customer data, and other proprietary information.
What are method references, and how are they useful?
Method references were added in Java 8 — interviewers will ask this question to make sure you’re staying up to date with the biggest industry trends. Method references are used to create simple lambda expressions. There are four kinds of method references:
1. Static methods
2. Instance methods of particular objects
3. Instance methods of an arbitrary object of a particular type
Method references allow Java developers to create straightforward, condensed code that clearly communicates what is going on.
Ultimately, senior Java developer interview questions will seek to evaluate a candidate’s depth and breadth of knowledge. Prepare by studying recent trends and Java updates, understanding the business’ unique needs, and brushing up on skills that you’re already familiar with so you can guide others.
To learn more about preparing for a job interview, read our blog and apply to join our roster of top developers worldwide.