Best Interview Questions to Ask an Entry Level & Senior Java Developer

Entry Level Java Developer

Are you looking to hire a Java developer? Or do you have interviews coming on the way? The best way to get ready for an interview and to identify a talented developer as an employer is to understand what the role and main functions will be. As remote tech recruiters, we have interviewed Java developers for more than a decade.  In this article, you’ll learn the key interview questions to ask an entry-level and/or senior Java developer. Ihor Shcherbinin, our Director of Recruitment put together a list of key questions that will guide you in your interview process, either you are an employer or a job seeker.

What is Java

Java is one of the most popular programming languages worldwide. Over 9 million developers use it daily. These are some interesting facts about this programming language: 

  • Java’s initial name was ‘’Oak’’.
  • It was developed in 1995 by Microsystems (Now it belongs to Oracle).
  • Most developers who use Java build software, computer games, and mobile apps.
  • It’s the second most popular language.
  • Java is the programming language of Android.
  • It’s used by 95% of the enterprises as their primary language.

Why Hire a Java Developer? 

For many, 2020 is known as the ‘quarantine year.’ Most companies who had to lock their doors started strengthening their online presence.  Some of them use LinkedIn strategies or any type of social media to connect with their customers. Others opt for a more significant digital presence by building business applications and websites. The results? More loyal customers and engaged users that turn into potential customers. 

If you hire a Java developer, you’ll have someone on your team capable of designing, developing, and managing Java-based applications, depending of course if you’ll be hiring an entry-level java developer or a senior one. Different applications such as: 

  1. Mobile applications
  2. Desktop GUI applications
  3. Web-based applications
  4. Enterprise applications
  5. Scientific applications
  6. Gaming applications
  7. Big Data technologies
  8. Business applications
  9. Distributed applications
  10. Cloud-based applications

8 Key Java Interview Questions for Entry Level Java Junior Developers 

Junior Java developers are a great way to strengthen your IT team. Although they are still not experts in the field, they have valuable and fresh knowledge. Talented entry-level developers are aware of all the new things happening in the programming world, and they bring a great set of skills your team needs. But how to screen a junior developer who has basic knowledge?

Many managers (not only in the IT industry) avoid entry-level java developers because they think they don’t have time to teach them things. Or they are scared that juniors will screw things.  Yet, entry-level employees have all the new ideas, and information seniors sometimes are lacking. If you have an upcoming interview with an entry-level Java developer, you should know that identifying talented ones is not easy.

That’s why we made a list with the 8 best junior Java developer interview questions:

1. How does Java achieve platform independence?

Java platform independency means that the Java program can run on any platform or operating system without suffering any changes. This is possible because of the bytecode. 

When the Java program runs in a particular machine it is sent to the Java compiler. The result of this is the conversion of the original code into an intermediate code called bytecode. This bytecode is sent to Java Virtual Machine (JVM) which resides in the RAM of any operating system. JVM recognizes the platform and converts the bytecodes into native machine code.

2. What are the various access specifiers for Java classes?

Access specifiers are the keywords used before a class name that defines the access scope. 

There are four types of access specifiers:

1.  Private: When a variable is declared as private, it can be accessed only from the same class to which they belong.
2.  Public: Methods and variables that have public access can be accessed by all the other classes in the project.
3.  Protected: When a variable is declared as protected it means that it can be accessed within the same package classes and subclasses of any other packages.
4.  Default: Methods and variables can be accessed only from the same package and not from outside of its native package.

3. What is the Difference Between ArrayList and HashSet in Java?

The following ones are the main differences between ArrayList and HashSet: 

Implementation

ArrayList: Implements List interface.

HashSet: Implements Set interface.

Duplicates

ArrayList: Allows duplicates values.

HashSet: Doesn’t allow duplicates values.

Constructor

ArrayList: Have three constructor which are ArrayList (), ArrayList (int capacity), ArrayList (int Collection c).

HashSet: Have four constructor which are HashSet (), HashSet (int capacity), HashSet (Collection c), and HashSet (int capacity, float loadFactor).

Order

ArrayList: Maintains the order of the object in which they are inserted.

HashSet: Doesn’t maintain any order.

Null Object

ArrayList: It’s possible to add any number of null value.

HashSet: Allow one null value.

Syntax

ArrayList:

ArrayList list=new ArrayList ();

HashSet:

HashSet set=new HashSet ();

4. What is a Java ClassLoader?

The Java Classloader belongs to the Java runtime environment that loads classes on demand into the Java Virtual Machine (JVM). Classes are loaded from the local file system, a remote file system, or even from the web.

When the JVM is started, three class loaders are used:

1.   Bootstrap Classloader: Loads core Java API file rt.jar from folder.

2.   Extension Classloader: Loads jar files from folder.

3.   System Classloader: Loads jar files from path specified in the CLASSPATH environment variable.

5. Explain the main difference between fail-fast and fail-safe iterators

The main difference between fail-fast and fail-safe iterators is whether or not the collection can be modified while it is being iterated.

Fail-fast iterators operate directly on the collection itself. This means that during iteration, fail-fast iterators fail as soon as they realize that the collection has been modified.

Fail-safe iterators operate on a cloned copy of the collection and therefore do not throw any exception if the collection is modified during iteration.

6. What are loops in Java? – Explain the three types of loops 

Loops are used in Java to execute a statement or a block of statement repeatedly. There are three types of loops in Java:

1. For Loops

For Loops are used in Java to execute statements repeatedly for a given number of times.

2. While Loops

While Loops are used when determined statements need to be executed repeatedly until a condition is fulfilled.  In While Loops, condition is checked before the execution of block statements.

3. Do While Loops

Do While Loop is the same as While loop with the only difference that condition is checked after the execution of block statements. 

7. What is the Final Keyword in Java? – Provide an example

In Java, the final keyword is used in several contexts to define an entity that can only be assigned once. This means that when using the final keyword, the value can’t be modified in the future. Once a final variable has been assigned, it ALWAYS contains the same value.

For example, if you ever see the final keyword with a parameter variable, it means that the value of this variable cannot be changed anywhere in the function. For example: 

class finalParameter {
	public static void example( final int parameter ) {
      parameter = 4; //attempting to reassign a value to a parameter throws an error
	}
}

8. What is default switch case/ – Provide an example

In a switch statement, default case is executed when no other switch condition matches. It can be declared only once all other switch cases have been coded.

For example:

public class switchExample {
	int score = 4;
	public static void main(String args[]) {
        switch (score) {
            case 1:
                system.out.println("Score is 1");
                break;
            case 2:
                system.out.println("Score is 2");
                break;
            default:
                system.out.println("Default Case");
    	}
	}
}

8 Key Interview Questions for Senior Java Developers

Hiring junior developers have a lot of benefits. However, sometimes your team needs a seasoned senior-level Java developer that puts all their knowledge on the table. If this is your case, and you’re looking to scale your IT team with programmers with years of experience upon their shoulders, we got you covered. These are the critical interview questions for senior-level Java developers: 

1. What are the benefits of using Spring?

Using the Spring framework has many benefits, such as:

  • It’s lightweight – the basic version is around 2MB.
  • Spring supports Aspect-oriented programming (AOP) and enables cohesive development; it separates application business logic from system services.
  • Spring’s web framework is a well-designed web MVC framework.
  • Spring provides a transaction management interface that can scale to both local and global transactions.
  • Exception handling – Spring provides a convenient API to translate technology-specific exceptions into consistent unchecked exceptions.

2. Compare the wait () and sleep () methods in Java

wait() pauses the thread until the specified number of milliseconds have elapsed or until it receives the desired notification from another thread – these happen without keeping a hold on the monitor/lock of the shared object.

sleep() blocks operations that keep a hold on the monitor/lock of the shared object for the specified number of milliseconds.

Overall, wait() is used in multithreaded applications with notify() or notifvALL() to synchronize and avoid race conditions. On the other hand, sleep () is using for polling or to check determined results. 

3. Read/convert an InputStream into a String in Java

You can do it by using Apache commons IOUtils to copy the InputStream into a StringWriter like:

StringWriter writer = new StringWriter () ;
IOUtils.copy (inputStream, writer, encoding) ;
String theString = writer.toString () ;

Or

// NB: does not close inputStrem, you’ll have to use try-with-resources for that
String theString = IOUtils.toString (inputStream, encoding) ;

4. Does Java have static class?

Java can’t make a top-level class static but you can simulate it with the following:

1)  Declare your class final: This prevents extension of the class since extending a static class doesn’t make sense.

2)  Make the constructor private.

3)  Make the members and functions of the class static.

5. Is it secure to store sensitive data (password, social security number, etc.) in a character array? Or is it better to secure it in a String? 

Is more secure to store it in a character array.

In Java, Strings are immutable and are stored in the String pool. Once a String is created, it stays in the pool in memory until the garbage collector takes it away. Even after you’re done processing the string value it remains available in memory for an indeterminate time and this makes it more insecure because you have no real control over it. Anyone having access to a memory dump could extract sensitive data.

On the other hand, if you use a mutable object like a character array, to store the value, you can set it to blank once you are done with it – it will no longer be retained in memory. 

6) How can you catch an exception thrown by another thread in Java?

It can be done by using Thread.UncaughtExceptionHandler

Here’s a simple example

// create our uncaught exception handler
Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() {
    public void uncaughtException(Thread th, Throwable ex) {
        System.out.println("Uncaught exception: " + ex);
    }
};

// create another thread
Thread otherThread = new Thread() {
    public void run() {
        System.out.println("Sleeping ...");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            System.out.println("Interrupted.");
        }
        System.out.println("Throwing exception ...");
        throw new RuntimeException();
    }
};

// set our uncaught exception handler as the one to be used when the new thread
// throws an uncaught exception
otherThread.setUncaughtExceptionHandler(handler);

// start the other thread - our uncaught exception handler will be invoked when
// the other thread throws an uncaught exception
otherThread.start();

7. What is the Java Classloader?

The Java Classloader refers to the part of the Java runtime environment that loads classes on demand into the Java Virtual Machine (JVM).  There are three class loaders used when the JVM is started:

  1. Bootstrap Classloader
  2. Extension Classloader
  3. System/Application Classloader

8. How Does the Get Method of HashMap Work in Java?

HashMap is based upon hash table data structure and uses hashCode () method to calculate hash code to find the bucket location on the underlying array and equals () method to search the object in the same bucked in case of a collision. 

Need Help Hiring an Entry Level and/or a Senior Java Developer?

Suppose you are still wondering what are the basic questions asked in Java interviews, or how to conduct a more technical interview, including specific coding questions. In that case, your best option is to get help from experts.  Having technical background during interviews is necessary, but also interviewers need specific skills to know when a candidate will fit into a company’s culture and when they are not. Plenty of candidates have a solid skill set but hate code reviews or can’t stand working on teams.  But don’t worry! At DistantJob, all of our headhunters are skilled enough to identify the most talented junior Java remote developers that will fit your company perfectly. All you need to do is:

1.   Contact us.

2.   Tell us the skills you are looking for in candidates.

In less than two weeks, you’ll be onboarding your new entry-level Java developer.

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email

or... Subscribe to our newsletter and get exclusive content and bloopers

Gabriela Molina

Gabriela Molina

Gabriela Molina is the writer and executive editor of the DistantJob blog. As a former freelance journalist, she has covered a wide range of topics throughout her career. She was featured in Datasciencentral, Simpleprogrammer, to name a few. She is currently specializing in the areas of technology, leadership, and remote work.