Part 5
Basic core java interview questions and answers for freshers covered in this post:
Can you declare constructor static, final, abstract and synchronized?
- We cannot declare constructor static, final, abstract and
synchronized.
- Purpose of all four keywords given above is different.
Can we override or overload the constructor?
- We cannot override the constructor but we can overload the constructor.
- Constructor overriding is not possible because the constructor must have
the same name of the class and doesn’t have any return type. But for
overriding signature must be same. So ultimately overriding is not
possible.
- Constructor overloading is possible because the constructor name is the
same as class name and type of parameter and no of parameters are different
so constructor overloading is allowed.
What is the difference between HashMap and TreeMap?
|
HashMap |
TreeMap |
1. |
The underlying data structure of HashMap is HashTable. |
The underlying data structure of TreeMap is a RED-BLACK tree. |
2. |
HashMap allows only one null key and multiple null values. |
TreeMap doesn’t allow a single null key but allows multiple null
values. |
3. |
HashMap doesn’t maintain any order. |
TreeMap maintains natural sorting order which is ascending. |
4. |
HashMap allows heterogeneous objects. |
TreeMap allows only homogeneous objects because TreeMap inserts the
elements according to some natural sorting order. |
5. |
Performance of HashMap is higher than TreeMap because it provides
constant-time performance that is O(1) for basic operation. |
The performance of TreeMap is lower than HashMap because it
provides the performance of O(log(n)) for most operations. |
6. |
HashMap uses equals() to compare the keys. |
TreeMap uses the compareTo() method to compare the keys. |
7. |
HashMap implements Map interface. |
TreeMap implements NavigableMap interface. |
8. |
HashMap provides some basic methods for operation. |
TreeMap provides some special methods for operation like
firstKey(), lastKey(), tailMap() etc. |
9. |
HashMap is the best option when you don’t want the elements in some
type of sorting order. |
Hashtable is the best option when you want the elements in some
type of sorting order. |
What is the difference between JDK, JRE and JVM?
|
JDK |
JRE |
JVM |
1. |
JDK stands for Java Development Kit. |
JRE stands for Java Runtime Environment. |
JVM stands for Java Virtual Machine. |
2. |
JDK is superset of JRE. |
JRE is a subset of JDK. |
JVM is a subset of JRE |
3. |
JDK is a software development kit to develop applications in
java. |
It is a software bundle that provides java class libraries with the
necessary components to run java code. |
JVM executes java byte code and provides an environment for
executing it. |
4. |
JDK enables developers to create a java program that can be
executed and run by the JRE and JVM. |
JRE is a part of java that creates the JVM. |
It is the java platform component that executes source code. |
5. |
JDK containes the tools to debugging, developing and monitoring the
code. |
It contains the class libraries and other supporting files that JVM
requires to execute the program. |
Software development tools are not included in JVM. |
Can we trigger the garbage collection from java code?
- Yes, we can just recommend to JVM for garbage collections. But we cannot
force JVM.
- We can recommend invoking the System.gc() method. But, it's not guaranteed
garbage collectors will execute.
What are the features introduced in Java 8?
- Following are the features introduced in Java 8.
1. Lambda Expression.
2. Functional Interface.
3. Default methods in Interface.
4. Static methods in Interface.
5. Predicate functional interface.
6. Function functional interface.
7. Consumer functional interface.
8. Method reference and constructor reference (::).
9. Stream API.
10. Date and Time (JODA API).
In functional interface how many default methods can be declared?
- There is no limit on declaring default methods inside the
interface.
- You can have n number of methods inside the interface.
What is Predicate functional interface?
- Predicate is used to perform a particular condition check.
- Predicate can be used like if condition. It will always return a Boolean
value.
- Please refer to the below example.
@FunctionalInterface public interface Predicate<T> {
} |
What is Stream API?
- Stream API is mostly used to process collection objects.
- Stream API can be used to filter out some elements based on some sort of
conditions and map some values according to some process.
- Stream is an interface present in java.util.stream package.
Can you call static method with method
reference?
- Surely, we can call the static method with method
reference.
- 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.
|
0 Comments