Java Interview Questions and Answers covered in this post:
What is object-oriented language? Is java 100% object-oriented
language? Why?
- Object-oriented programming is about creating an object which can
have its data and methods.
- Java supports primitive data types like int, float, double etc. which is not an object, so Java is not a purely object-oriented language.
Is
null
keyword in java?
- No. null is not a keyword in java. Null is like literals like true and false in java.
What is the difference between compile-time polymorphism and run-time polymorphism?
|
Compile time Polymorphism |
Run time polymorphism |
1. |
Method overloading is an example of Compile-time binding.
|
Method overriding is an example of Run-time binding. |
2. |
Compile-time polymorphism can be achieved by static binding.
|
Run-time polymorphism can be achieved by dynamic binding. |
3. |
Inheritance is not mandatory to implement compile-time
polymorphism.
|
Inheritance is mandatory to implement Run- time
polymorphism. |
What are method overriding and method overloading?
|
Method Overriding |
Method Overloading |
1. |
Method overriding means creating a method with the same signature
in a parent class and child class. |
Method overloading means creating multiple methods with a
different signature and the same name in a class. |
2. |
Method overriding is run time polymorphism. |
Method overloading is compiled time polymorphism. |
3. |
We can have a single method in both classes. |
We can have multiple methods in a single class. |
4. |
Method overriding is dynamic binding. |
Method overloading is static binding. |
5. |
Covariant return applicable in method overriding. |
Covariant return cannot applicable in method overloading. |
6. |
A private and static method cannot be overridden. |
A private and static method can be overloaded. |
Can you override the private method?
- No. The private method cannot override because the private method is not visible in the child class. If the method is not accessible or visible in child class how can we override the method?
What is equals() and hashcode() contract?
- If the two objects are equal then they should have the same hashcode and
if two objects are not equal then they may or may not have the same
hashcode.
- Objet1.equals(Object2) if true then hashcode must be same of both
objects.
- Object1.equals(Object2) if false then hashcode may be or may not be
same.
- As per the oracle documentation, both methods should be overridden to get the complete equality mechanism you must override equals() and hashcode() methods.
Which is the parent class of the Exception hierarchy?
- Parent Class of Exception is Throwable.
What is the default size of Map?
- Default size of the map is 16.
What is the difference between ArrayList and Vector?
|
ArrayList |
Vector |
1. |
ArrayList is not thread-safe. |
Vector is thread-safe. |
2. |
Methods of ArrayList are not thread-safe. |
All methods of Vector are thread-safe. |
3. |
The performance of ArrayList is best than Vector. |
The performance of Vector is low as compared to ArrayList. |
4. |
ArrayList is not a legacy class. Introduced in Java 1.2 |
Vector is a legacy class introduced in 1.0 |
What is Lambda Expression?
- Lambda expression is an anonymous function without having return type,
modifier and name.
- To enable functional programming in Java we have to use a
lambda expression.
- We can pass the procedure and function directly.
-
Normal Method. |
Lambda Expression. |
public
void
m1() {
System.out.println("Hello");
} |
System.out.println("Hello"); } Lambda Expression will be like,
System.out.println("Hello");
} |
public
void
m1(int a, int b) {
System.out.println(a+b);
} |
System.out.println("Hello"); } Lambda Expression will be like,
System.out.println(a+b);
} |
public
int
m1(String s) {
return s.length();
} |
return s.length(); } Lambda Expression will be like,
return s.length();
} |
-
If your lambda expression has only one line of code then it is allowed to
skp the curly braces {}.
1.
-
If your lambda expression has only one parameter then it is allowed to
skip parenthesis as well.
1.
- If lambda expression return something then return keyword is also
optional.
1.
E.g. please refer above example.
- Lambda expression can have body inside curly braces if
there are multiple statements.
1.
Statement 1;
Statement 2;
Statement 3;
};
- Java interview questions and answers all MNC - Click here
- Basic core java interview questions and answers for freshers - Click here
- Core java interview questions for 3 years experience - Click here
- Core java interview questions and answers for 3-5 years exp - Click here
- Core java interview questions and Answers for 5 - 7 Years exp - Click here
- Basic Java Interview Questions and Answers - Click here
- Java interview questions and answers on oops - Click here
- Java interview questions and answers on Strings - Click here
- Java interview questions on exception handling - Click here
- Interview questions on multithreading in java for experienced - Click here
- Interview questions on serialization in java for experienced - Click here
- Interview questions on inner class in java for experienced - Click here
- Interview questions on Collections in java for experienced - Click here
Thank you techies for visiting this blog. I hope you enjoyed this blog and got more technical knowledge. I have tried to cover all types of questions and provided examples tested on eclipse as much as I can. Guys, please don’t just mug up the questions and answers. Try to clear your concepts with examples. Try to write a code on eclipse once you read the concepts. It will help you to memorize the concepts for a very long time. Simultaneously you will be prepared for interview programs as well. It will help you to survive in the IT sector for a long time. It may be easy to crack an interview but it's really tough to survive in the IT industry with inadequate knowledge and skills. I have collected all the questions from actual interviews attended by my friends, colleagues, college mate and classmate. I have covered frequently asked questions as well as challenging questions. I have included many programs to understand the concept thoroughly. I will try to explain the concept with the help of a real-time program in eclipse. You can share more questions which are not covered in this blog or post. Always welcome your suggestions and queries. I will definitely try to resolve it. Please comment your queries and new set of questions under the comment sections. I will create a new post for those questions.
My total experience is 10. Initially I had worked on some support
projects and then I moved to java projects. I had worked with many
multi-national companies like R-Systems, Tata Consultancy
Services, Cybage Softwares. Fortunately, TCS and Cybage has
given me an opportunity to take interviews for experienced
candidates. I have conducted more than 1000 interviews by now.
Mock sessions will be conducted for minimal charges. I will guide you personally on how to crack interviews. All sessions will be online sessions only. My interview book will be provided free of cost if you enroll for personal training. Once you have done practice then I assured you will definitely crack almost all java interviews. I have published my book named with "All MNC Java Interview" which is available on amazon. You can go through it or you can directly contact to me if you are interested to read the book. I will give you special discount. I have covered near about 550 questions and answers with program tested on eclipse and necessary diagram. I have covered interview questions asked in all reputed MNC like TCS, Infosys, Capgemini, Tech Mahindra, Cognizant, City Bank, Barclays, Amdocs, Mindtree etc. My purpose behind this book is, help you to get a job in your dream company. I can understand this is a struggling period for job seekers and freshers. Everybody must have gone from this phase. so never give up. Keep upgrading yourself. I am sure you will get a job in your dream company. All the best!!! Please reach out to me for personal training for interview preparation.
You can reach out to me at
mncjavainterview@gmail.com.
|
3 Comments
Really a great book. Helped me learn easily an in intresting way. This gave me a lot of confidence for the interview. Very small things are clarified in the book. This is a very interesting book. Thank you Sir for making it so easily available.
ReplyDeleteNice compilation. Very helpful to get one stop interview preparation questions.
ReplyDeleteReally....Nice question/answer
ReplyDelete