Java Tutorials Series - Interview Questions

We have already covered basic core Java concepts in our previous articles. Now we will be sharing few Java interview questions that can trick you in an interview. This is the most common mistakes usually students do. They do study basic core concepts of Java but do no go through tricky interview questions which is necessary to grab a job offer.

What is the difference between JDK, JRE and JVM?
JDK -Development kit required by a java developer. It consisted of various APIs through which you can write your code. JDK contains various packages for ex - java.io, java.util. Other than this, java and java is also used for execution and compilation of the byte code.
JRE-  is a Runtime environment, JVM uses JRE. JRE is a set of libraries required by JVM to execute your code.
JVM - It is an abstract machine. It is a software which is already provided by the platform, whenever we write a Java source code, it gets compiled into the byte code. JVM is that layer which is going to execute your byte code.

What is Synchronization -
Whenever we talk about threads, we come across synchronisation. When multiple threads accesses same object, the situation where we uses Synchronisation. For example - Let's say there's one seat left to be booked for Movie and multiple people are trying to book it. Multiple people will create multiple threads to access single object for a single resource. Whoever books it first will get a seat after which no one should be able to book it anymore since it is already occupied. So using Synchronisation,  we need to use keyword 'Synchronise' the object is locked, so all the concurrent threads. It avoids memory consistency errors. 

Synchronisation in Java

What is the difference between process and thread?
Threads are subsets of processes.

What are Wrapper classes?
We can convert Java primitives to reference types. Each and every primitive has wrapper class defined. We need not to import any additional class for this. When we speaking about Wrapper class concept, we should mention the concepts of Boxing and Unboxing. Please consider below examples -

int i = 10;
Integer boxing = new Integer(i); // Boxing(Constructing the object)

int j = boxing.intValue();  //Unboxing(extracting the value from object)

Difference between StringBuffer and StringBuilder?
We already know Strings are immutable, which is we cannot change it. StringBuffer and StringBuilder are mutable. StringBuffer operations are thread safe, by default it is synchronised. StringBuilder is not thread safe, it can only work in single threaded environment. StringBuilder is better in performance because there is no concept of thread in it.

What is the difference between Heap and Stack?


Comments

Popular posts from this blog

Azure Tutorials Series - Azure Networking

Coforge Interview Questions | Automation Testing profile

Testing in CI/CD