Let s keep this thread for discussing Java Interview questions Experience

+7 votes

Hi guys, I know a lot of you people have been interested in reading the most common questions asked in Java developer interviews...
Reading from this Edureka blog will probably boost your confidence and help you massively: https://goo.gl/Fa1XM1
PS: Read it first, thank me later. 

During your Java developer interviews, If you came across questions not mentioned in this blog, then please feel free to comment the answer in this thread. For the welfare of the community, let me get it added to Edureka's Java Interview Questions blog. Also feel free to share your interview experience....The others could learn a thing or two from your experience... :)

Jul 18, 2018 in Career Counselling by Vardhan
• 13,150 points
6,130 views

20 answers to this question.

+1 vote
Best answer

Hello everyone here is an updated blog for Java Interview Questions. Your last minute sheet to brush up most frequently asked Interview Question.

Refer the Blog "Top 75 Java Interview Questions You Must Prepare In 2019".

All the best to everyone.

answered Jan 17, 2019 by Edureka
• 4,220 points

selected Jan 17, 2019 by Priyaj
0 votes
Great initiative @Vardhan!
answered Jul 18, 2018 by donotcall
• 650 points
Thanks @Rohit!
Just trying to help the community in their prospective endevours.
+1 vote

Thank you @Vardhan your blog was really helpful and covered all the important questions. There was a basic question which i thought i answered correctly but unfortunately i didn't. The question was 

What makes Java Platform independent?

many people still don't know this, they just know as Java is platform independent but when asked why they are like its a feature of java. Again there is a misunderstanding as wether JVM or JAVA is platform independent?
Hope people going for the next interview won't be puzzled by this question. 
answered Jul 18, 2018 by bug_seeker
• 15,510 points

edited Jul 19, 2018 by bug_seeker
@bug_seeker you are true about the fact that many candidates don't get the difference
Let me first tell you as what does Platform independent mean? Take the literal meaning that "The java source code can run on all operating systems".
We write the program that is understood by humans, now the machine(your computer) has to figure out as what have you written and what do you want from the lines of code that you have written. So, the compiler converts the human language into a  machines understandable format. This may be a sequence of machine instructions that can be executed by the CPU directly, or it may be an intermediate representation that is interpreted by a virtual machine. This intermediate representation in Java is the Java Byte code. This Java Byte code make Java platform independent. There is a catch in this, Java forsure is platform independent but Java Virtual Machine is not. So be sure with these two teems “Java” and “Java Virtual Machine”.
Hope this answer helps you and many others for their coming interview.
All the best
Thank you @priyajkumar this is the exact answer.
0 votes

Hey Vardhan, I had referred this blog and it helped me a lot, thank you soo much.

My interview went pretty fine. I was asked 6 questions and answered all except there was this one question "can you make array volatile in java" and i froze coz i didn't know the answer.  But I did the research and found it out.

Yes you can make an array volatile in java but only reference pointing to an array will be visible to all threads, not the whole array. 

suppose you have a reference variable called primes as shown below:

 protected volatile int[] primes = new int[10];

then if you assign a new array to primes variable, change will be visible to all threads, but changes to individual indices will not be covered under volatile guarantee i.e.

 primes = new int[20]; 

will follow the "happens-before" rule and cause memory barrier refresh, but following code will not do so 

primes[0] = 10; 
primes[1] = 20; 
primes[2] = 30; 
primes[3] = 40;

Probably you should add this in your blog so it might be helpful for the others.
 

answered Jul 18, 2018 by Hannah
• 18,520 points

edited Jul 19, 2018 by Hannah
That is true. int[] is nothing but a reference to primes or reference to primes[0]. You make the reference volatile.
0 votes

Hey @Vardhan, great initiative from your end.
I read your blog on important questions for Java Interview.
I had this one question asked in one of my interview and i was partially correct, may be thats the reason I didn't get the part.
The question was 


Can you execute a java program without main method.

Yes you may be thinking Yes or No as an answer but I am sure that you will mess it up when asked about the explanation

Let me answer this as my Interviewer corrected me for the same and asked me to search as what is the most appropriate answer.

For you entire phase of education on Java you were taught that you should always use public static void main(String []args) and when you think you are all set for the interview, the interviewer asks you can you run your program without main method? Many programmer would  answer that they can run Java program without main method by writing code in static initializer block, which is true but partially. Yes, code written in static initializer block is executed before calling main method, but you won't be able to run a class by using Java command, or Eclipse or anything else, until it got  public static void main(String args[]) method on it. If you try to run such programs, you will get following error :

Error: Main method not found in class JavaAppWithoutMain, please define the main method as:   public static void main(String[] args)

Hope this explanation will help you in your future Interviews.
All the best everyone..

answered Jul 19, 2018 by Priyaj
• 58,020 points
0 votes
Heyy Vardhan thanks a lot for the blog, it was very helpful.

I couldn't answer one question, if anyone knows the answer please do let me know..

whats the difference between hashmap and hashtable in java?
answered Jul 20, 2018 by Anisha
This might help
1) HashMap is non synchronized. It is not-thread safe and can't be shared between many threads without proper synchronization code.   
Hashtable is synchronized. It is thread-safe and can be shared with many threads.
2) HashMap allows one null key and multiple null values.   
    Hashtable doesn't allow any null key or value.
3) HashMap is a new class introduced in JDK 1.2.   
    Hashtable is a legacy class.
4) HashMap is fast.   
    Hashtable is slow.
5) We can make the HashMap as synchronized by calling this code
Map m = Collections.synchronizedMap(hashMap);   
Hashtable is internally synchronized and can't be unsynchronized.
6) HashMap is traversed by Iterator.
    Hashtable is traversed by Enumerator and Iterator.
7) Iterator in HashMap is fail-fast.   
   Enumerator in Hashtable is not fail-fast.
8) HashMap inherits AbstractMap class.   
    Hashtable inherits Dictionary class.
0 votes

Hey @Vardhan this one friend of mine he had his interview yesterday and he had this one question asked to him and I found it amusing that even though people have a very good working knowledge of Java still they fall for this type of questions. The question was

What is the difference between "==" and .'equals' ?

According to me I will say that better to start with their working and then jump to the differences as it would give your interviewer that you know the use of both and the differences too. So you can go as such

In general both equals() and “==” operator in Java are used to compare objects to check equality but here are some of the differences between the two:

  1. Main difference between .equals() method and == operator is that one is method and other is operator.

  2. We can use == operators for reference comparison (address comparison) and .equals() method for content comparison. In simple words, == checks if both objects point to the same memory location whereas .equals() evaluates to the comparison of values in the objects.

  3. If a class does not override the equals method, then by default it uses equals(Object o) method of the closest parent class that has overridden this method.

Hope this will help all of the people ready to face an Interview.
All the best 
answered Jul 20, 2018 by Priyaj
• 58,020 points
0 votes
Thank you so much for this blog, it was very helpful especially because i had to study everything in the last minute.

i was asked this one question which wasn't mentioned in the blog.

"wait(), notify() code for producer consumer problem"

Can someone explain this to me?
answered Jul 20, 2018 by krishti
0 votes
Hi sir. Why shouldnt we declare main method as private or protected?
answered Jul 22, 2018 by Rahul
0 votes
In C, C++ we could use int, float as return type of main function.. In Java, why is it compulsory that the return type of main function is void? Why cant we use int or float?
answered Jul 22, 2018 by Sanjeev
0 votes
Hi sir.. I was working on arrays and came across this doubt.. Integers are used to index arrays (0,1,2,3........). Even negative numbers are integers (signed integers), then why cant we use negative numbers to index arrays?
answered Jul 22, 2018 by Aditya
0 votes
If there is a finally block in my code, is there a way to skip its execution without removing that block or commenting it? I want the finally block to be there as usually but my making some changed to the code, i want to skip its execution, is it possible?
answered Jul 22, 2018 by Mrudula
0 votes
Why is garbage collector used in Java and how it actually helps in a real world java application?
answered Jul 22, 2018 by Sumitra
0 votes
Hello sir.. I have a doubt about throw and throws.. I have read that throw is used when i can handle the exception and throws is used when I cant handle the exception. But i am not understanding the difference during practical application. In what situations should i use throw and in what situation should i use throws?
answered Jul 22, 2018 by Kategar
0 votes
Can someone tell me how to use try and catch if I dont know what type of exception a particular block of code in try block might return?
answered Jul 22, 2018 by Shantanu
0 votes
Hi Vardhan sir... I went through the blog that you suggested.. It really helped me during the technical round. Most of the questions asked during the interview were present in the blog and i was prepared for it... Thank you!!
answered Jul 22, 2018 by Imran
0 votes
I was asked "what ar̥e threadlocal variables in java" for my interview, i wasn't able to answer

Can someone explain?
answered Jul 24, 2018 by Arch
The ThreadLocal class in Java enables you to create variables that can only be read and written by the same thread. Thus, even if two threads are executing the same code, and the code has a reference to aThreadLocal variable, then the two threads cannot see each other's ThreadLocal variables.
Creating threadlocal variable
private ThreadLocal myThreadLocal = new ThreadLocal();
Once a ThreadLocal has been created you can set the value to be stored in it like this:
myThreadLocal.set("A thread local value");
You read the value stored in a ThreadLocal like this:
String threadLocalValue = (String) myThreadLocal.get();
The get() method returns an Object and the set() method takes an Object as parameter.
0 votes
I have attended a couple of interviews and the questions were too basic regarding the data-structures and flow of working. I wish I had this blog before, it would have helped me perform better in the interview..
answered Jul 25, 2018 by Chaitra
0 votes

Hello, hope you guys are getting some benefits out of this thread.
I have a friend who recently had an interview and there he was asked this one question. I personally think that people who are into coding would know this but for people just reading interview question and answer would not be knowing this. The question was as follows:-

What is a Blank Variable ?

According to me I got a perfect way to answer this such that it has no pendent questions.
 

Before knowing Blank Variable lets talk about final Variable. A final variable in Java can be assigned a value only once, we can assign a value either in declaration or later.

Eg:-  

final int i = 10;
   i = 30; // Error because i is final.

Now, A blank final variable in Java is a final variable that is not initialized during declaration.

Blank final variables are used to create immutable objects (objects whose members can’t be changed once initialized).

A blank final variable in Java is a final variable that is not initialized during declaration. Below is a simple example of blank final.

  // A simple blank final example
   final int i;
   i = 30;

answered Jul 25, 2018 by Priyaj
• 58,020 points
0 votes
How are process and threads different from each other?
answered Aug 27, 2018 by Sammy
Process: An executing instance of a program is called a process.   
Thread: A thread is a subset of the process.
For more difference visit: https://www.edureka.co/blog/interview-questions/java-interview-questions/

Related Questions In Career Counselling

+11 votes
7 answers

“IMPORTANT” interview questions for DevOps

Hello everyone here is an updated blog ...READ MORE

answered Jan 17, 2019 in Career Counselling by Edureka
• 4,220 points
3,850 views
+2 votes
3 answers

**Important** Apache Spark Interview Questions (Bank)

Hi Priyaj I have this one question What is ...READ MORE

answered Aug 22, 2018 in Career Counselling by bug_seeker
• 15,510 points
2,091 views
+3 votes
4 answers
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,222 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
8,358 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
17,433 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points

edited Aug 4, 2023 by Khan Sarfaraz 4,875 views
+16 votes
6 answers
+11 votes
6 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP