Interview process for hiring a Java programmer consists in two or three parts. In the initial stages (phone interview, first face to face interview), the interviewers will ask you mostly screening, and behavioral questions, trying to understand your personality, attitude to various work-related situations, and whether you fit to their company.
The final stage of an interview process consists in technical questions that will test you readiness for the job, and whether you really can work with Java. We will have a look at them in this article.
15 common technical questions for programmers who work with Java
- Question: Can you define an Iterator?
Answer: Some collection classes provide traversal of their contents using a java.util.Iterator interface. This particular interface enables you to walk-through a collection of objects, operating on every object in turn. Keep in mind whenever using Iterators that these include a snapshot of the collection at the moment the Iterator has been obtained. That’s why typically it isn’t recommended to modify the particular collection itself while traversing an Iterator.
- Question: What is the reason for garbage collection in Java, and in which situation we use it?
Answer: The reason for garbage collection is usually to recognize and discard objects which are not anymore needed by a program, so their resources can be reclaimed. Any Java object will be subject to garbage collection any time it becomes inaccessible to the program within that it is used.
- Question: Can you identify the 1st argument of the String array in main method?
Answer: The String array is actually empty. It doesn’t have any kind of element. It is different for example in comparison to C/C++, where the first element will be the program name by default.
- Question: Do you know what is the catch or declare rule for method declarations?
Answer: Whenever the checked exception might be thrown within body of the method, the method have to possibly catch this exception or declare this exception in its throws clause.
- Question: Can you name the main difference between preemptive scheduling and time slicing?
Answer: When preemptive scheduling is set, the highest priority process executes till it gets into the waiting or dead states or till the higher priority process starts to exist. Oppositely, when time slicing is set, any process executes for the predetermined slice of time after which reenters the pool of ready tasks. The scheduler after that decides about the task that should execute next, depending on priority along with other factors.
- Question: Can you define runtime exceptions?
Answer: Runtime exception is an exception which is thrown at runtime as a reason of either wrong input data or wrong program logic etc. Runtime exceptions are never checked by the compiler at compile time.
- Question: Can you say what is the difference between defining the variable and declaring the variable?
Answer: When you declare a variable, you simply mention the type of the variable and the name of it. You do not initialize it. But whenever defining a variable, you have to declare it and also carry out the initialization.
For example String t, is purely a declaration, while String t = new String (“rtfd”) is the definition.
- Question: Can you explain various ways of using thread in Java?
Answer: The thread may be implemented using runnable interface or simply by inheriting from the predefined Thread class. The former one is definitely more useful, because when you are going for multiple inheritance, the only interface can do the job.
- Question: Is there any method that simply have to be implemented by each and every task?
Answer: Yes there is. All tasks must implement the run() method, doesn’t matter if we speak about subclass of Thread or implement the Runnable interface.
- Question: To run Java programs, do I need to set on my machine any environment variables?
Answer: Yes, you need to. PATH and also CLASSPATH are the two variables you need to set on your machine to be able to run Java programs.
- Question: Can you define Overriding?
Answer: Overriding applies in a case when class defines a method using the same name, return type, and arguments as a method in its super-class. When this happens, the method in the class overrides the method in the super-class.
Whenever the method is invoked for an object of the class, it will after be the new definition of the method that is called, and not the method definition from super-class. That is the basic description of overriding.
- Question: Are objects in Java passed by the value or by the reference?
Answer: Objects in Java are passed only by value, as Java does not support passing by reference. When we look at the object reference itself, it is so passed by value and both the original reference and parameter copy refer to the same object .
- Question: Can you name the main difference between static and non-static variables in Java?
Answer: The static variable is linked to the entire class rather than to specific instances of a particular class. Oppositely, non-static variable takes on unique value with every object instance.
- Question: What will be the default value of local variables?
Answer: In Java, local variables will not be initialized to any default value, neither primitives nor object references, that’s why you have to initialize every variable. In case try to use them without initializing them before, the java compiler will not compile the code at all.
- Question: What is synchronization in Java and why it is essential?
Answer: With respect to multi-threading, synchronization is the ability to manage the accessibility of multiple threads to shared resources. Without having synchronization running, it will be possible for any thread to modify a shared object while some other thread is in the process of using or changing that exact object’s value. This will lead to significant errors, that’s why the synchronization is so important.
Special Tip: Download the full list of Java interview questions in a simple, one page long .PDF, and practice your interview answers anytime later:
More than just technical skills
Java is a popular programming language, and you will typically compete with at least few other people in your interview.
To succeed, you will need more than juts good technical skills. You will have to answer the behavioral questions well, and you will have to convince the interviewers to hire you, and not one of the other job applicants. You will have to make a great impression on the interviewing panel.
Have a look at the following articles to prepare for everything that awaits in your interview:
- Screening interview questions -Typically the first stage of an interview process. Companies conduct it online, on Skype, over the phone. Most employers will screen out more than fifty percent of job applicants, before inviting the rest for the in-person interviews. Read the article and learn how to make the cut.
- Behavioral interview questions – Inquiring about your past, we try to understand how you would act in your new job, while facing various challenges and tasks. Typically a second stage of the interview process for programmers’ jobs.
- Interview Success Package – Brilliant answers to 30 most common interview questions, and a guide on how to impress your interviewers. If you want some help from the professionals, you should have a look at this package.