Java Interview Questions and Answers covered in this post:
What is Actual Parameter and what is Formal Parameter?
- Actual Parameters: If we pass the parameters while calling a
function are called Actual Parameter.
- Formal Parameter: If we are catching parameters in function are
called formal parameters.
package simplifiedjava.crackedInterview; public class ActualAndFormalParameters {
public
static
void
main(String[] args) {
int
a
= 10;
int
b
= 20;
addition(a,b); // a and b are Actual Parameter }
public
static
void
addition(int
num1, int
num2) {
// num1 and num2 are formal parameters
}
} |
Can you overload the private method?
- Yes. We can overload the private method. There is no need to have a
parent-child relationship to overload the method.
- While method overloading we need to differentiate the type of parameter or
number of the parameter so we can overload private methods.
Can we modify the existing String object? If I tried to change the
existing String object then what will happen?
- No we cannot modify the existing String class object.
- If you are trying to modify an existing string object then internally new
object will be created and if you pointing to a newly created object to
reference variable then the old object will be eligible for garbage
collection.
What is the difference between the throw and throws keyword?
|
Throw |
Throws |
1. |
Throw keyword can be used to throw an exception manually or
explicitly. |
Throws keyword can be used to declare the list of exceptions. |
2. |
Throw can be declared inside a method. |
Throws can be declared in method definition followed by the
parameter list. |
3. |
Only one Exception can be thrown with the throw keyword. |
Multiple Exceptions can be declared with the throws keyword. |
4. |
The checked exception cannot throw with the throw keyword. |
Checked and Unchecked exceptions can declare with the throws
keyword. |
Explain the thread life cycle?
- There are five states of the thread life cycle.
1. New: When a thread gets newly created.
2. Runnable: When you invoke the start() method then the thread enters
into a runnable state.
3. Running: When the scheduler allocates time slots in CPU then that
thread enters into a running state.
4. Blocked: When you invoke the wait() method then that thread enters
into a waiting state.
5. Terminate: after execution of the thread enters into a dead state.
What is the ThreadGroup?
- Thread group represents a set of threads.
- ThreadGroup belongs to java.lang.ThreadGroup.
- A thread is allowed to access information about its own thread group but
not to access information about its thread group's parent thread group or
any other thread group.
- A thread group can also include the other thread group. The thread group creates a tree in which every thread group except the initial thread group has a parent.
What is a Thread pool?
- Thread pool is a set of threads that resides in a single
place.
What is ConcurrentHashMap? What are the Characteristics of
ConcurrentHashMap?
- ConcurrentHashMap is the concurrent class with key and value pairs
belonging to java.util.Concurrent package.
- ConcurrentHashMap is a concurrent version of HashMap. We can say it is a
thread-safe HashMap.
- Characteristics of ConcurrentHashMap are as follows.
1. Characteristics of ConcurrentHashMap are as follows.
2. The underlying data structure is Hashtable.
3. Null is not allowed either key or value.
4. ConcurrentHashMap allows any number of reading operations at a time and
only 16 write operations at a time when the concurrency level is 16.
5. Instead of getting a whole map object lock concurrency divides map objects
into 16 parts because the default size of ConcurrentHashMap is 16.
6. To perform read operation would not require any type of lock but for write
operation thread must get Bucket level lock or Segment level lock.
7. ConcurrentHashMap allows concurrent read and thread-safe write
operations.
8. While one thread performs read operations other 16 threads can perform
write operations at a time.
9. ConcurrentHashMap never throw ConcurrentModificationException.
- Please refer to the below example.
package simplifiedjava.crackedInterview; import java.util.concurrent.ConcurrentHashMap; public class ConcurrentHashMapDemo {
public static void
main(String[] args) {
ConcurrentHashMap<Integer, String> map = new
ConcurrentHashMap<Integer, String>();
map.put(101, "Yogesh");
map.put(102, "Arpita");
map.putIfAbsent(103, "Shweta");
System.out.println(map);
map.putIfAbsent(102, "Shruti");
map.putIfAbsent(104, "Shivani");
System.out.println(map);
map.replace(104, "Prajakta");
System.out.println(map);
map.remove(101);
System.out.println(map);
}
}
Output:
{101=Yogesh, 102=Arpita, 103=Shweta}
{101=Yogesh, 102=Arpita, 103=Shweta, 104=Shivani}
{101=Yogesh, 102=Arpita, 103=Shweta, 104=Prajakta} {102=Arpita, 103=Shweta, 104=Prajakta} |
What is bounded type parameter?
- We can bound type parameters to the particular range by using extends
keyword such types are called bounded types.
- Please refer to the below example.
class Test <T extends Number>{
} |
What is JVM?
- JVM stands for Java Virtual Machine.
- Implementation of JVM is JRE(Java Runtime Environment).
- JVM is responsible to manage memory, creating an object, destroying
objects, instantiating classes etc.
- 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
Questions covered in upcoming post:
1. What is the difference between Instance variable and Class Variable.
2. What are the main pillars of OOPs Concepts? Explain the OOPS Concepts.
3. Can I declare final method inside a interface.
4. What is constructor chaining.
5. What is the difference between final method and abstract method.
6. How java reclaims a memory. what is garbage collections. Who is responsible for garbage collection.
7. What is widening.
8. What is narrowing.
9. Why String is immutable.
10.What are the advantages and disadvantages of Inner class.
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