Java Interview Questions and Answers covered in this post:
Can I declare a final and abstract method in abstract class?
- You cannot declare final and abstract at a time. Either final or abstract
method can be declared.
- You can declare the final method or abstract method inside the abstract
class individually.
What is static binding and dynamic binding?
-
Static binding occurs compile time.
-
Dynamic binding occurs runtime
-
Best example of static binding is method overloading.
-
Best example of dynamic binding is method overriding.
What is the use of trim() method in the String class?
-
Trim() of String class is used to remove the blank spaces of
String.
-
Trim() method removes blank spaces before and after the
String.
-
Trim() method doesn’t remove the blank spaces in between
String.
What are the multiple ways to create a thread? Which one is
recommendable?
-
There are two ways to create a thread.
1.
Thread Class:
You can extend the Thread class and create a thread.
2.
Runnable Interface: You can implement a Runnable interface and create a thread.
- Second one is recommendable which is implementing a Runnable interface
because if you implement a runnable interface then you will have an option
to extends one more class.
- Please refer to the below example.
1. Extending Thread Class.
package
simplifiedjava.crackedInterview; public class CreatingThreadUsingThreadClassDemo extends Thread{ Thread t = new Thread();
public
static
void
main(String[] args) {
// TODO
Auto-generated method stub
} }
2. Implementing Runnable Interface.
package
simplifiedjava.crackedInterview; public class CreatingThreadUsingThreadClassDemo implements Runnable{ Thread t = new Thread();
public
static
void
main(String[] args) {
// TODO
Auto-generated method stub }
@Override
public
void
run() { // TODO Auto-generated method stub
}
} |
What is the purpose of Inner classes?
- It is a way of logically grouping classes that are only used in one place: If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together. Nesting such "helper classes" makes their package more streamlined.
- It increases encapsulation: Consider two top-level classes, A and B,
where B needs access to members of A that would otherwise be declared
private. By hiding class B within class A, A's members can be declared
private and B can access them. In addition, B itself can be hidden from
the outside world.
What is the difference between Regular Inner Class and Static Inner
Class?
|
Regular Inner Class |
Static Inner Class |
1. |
Outer and Inner regular classes are strongly associated with each
other. |
Outer and nested static classes are not strongly associated with
each other. |
2. |
Static members are not allowed. i.e. static methods and static
fields. Still, if you want to declare a static field inside the
inner class then you must declare with the final keyword as well
and assign some value to it.
e.g. static final int
c = 10; |
Static members are allowed. |
3. |
We cannot declare main() inside the inner class so we can’t run
directly through the command prompt. |
We can declare the main method inside the inner class so we can
call or run directly through the command prompt. |
What is load factor in collection API? What is the default load
factor?
- Load factor is a measure that decides when to increase the size of the
collection.
- Default load factor is 75%. It means when your collection object gets
full by 75% then collection size will increase the space internally.
- Every collection object has its own way or different formula to increase
the size internally.
Can you explain internal working of ArrayList?
- When you create an object of ArrayList default size of the ArrayList is
10.
- Means the initial size of the ArrayList is 10.
- When the ArrayList gets to fill 75% then internally JVM performs many
operations.
- Internally JVM creates a new ArrayList, Copy all the elements of the old
ArrayList into the new ArrayList.
- New ArrayList object size will be calculated by this formula.
1. New Size = ((Current Size * 3 ) / 2) + 1.
- Old ArrayList objects will be eligible for garbage collection.
- Reference variable points to the new ArrayList object.
- Every time JVM performs the same process when an object gets full of
75%.
- Please refer below image to better understanding.
Explain the defined method in Stack?
- In Stack there are 5 main methods can be used to perform
basic operations.
1. Push(Object O): To insert an object into stack.
2. Pop(): To remove and return top of the stack.
3. Peek(): To return top of the object without removing
it.
4. Empty(): return true if the stack is empty.
5. Search(): returns offset if the element is available otherwise,
returns -1.
What is EntrySet?
- A map is a group of key-value pair.Each key-value pair is called an
Entry. Set of Entry is called EntrySet.
- Entry is an inner interface of Map Interface.
- Inside entry actual key and value pair will be stored.
- While iterating the map object we have to place iterator on Entry, not on
a map.
- Without an existing Map object there is no chance of existing Entry
object.
- Please refer to the below image for entry set.
- 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