Part 2
Core java interview questions and answers for 3-5 years experience covered in this post:
Can a constructor have a return
type? If no can you
explain why?
- Constructor is specially used to initialize the object, not the business
logic processing.
- If the constructor doesn’t have any business logic and nothing is going to
return so constructor doesn’t have a return type.
What's the difference between StackOverflowError and OutOfMemoryError in java?
- StackOverflowError: If there
is no memory available in the stack for storing function call or local
variable, JVM will throw StackOverflowError.
- OutOfMemoryError: If there is
no memory available on heap memory while creating an object then JVM will
throw OutOfMemoryError.
What will happen when an exception occurred in a thread?
- Exception behaviour won’t change in the case of non-threading or
multi-threading programming.
- Once an exception occurs and if it is not handled then your program will be
terminated abruptly.
- In the case of a multi-threading environment if an exception occurs then
the thread will die.
- If an uncaught exception handler is registered then it will get a
callback.
- Nested interface
Thread.UncaughtExceptionHandler
is defined for handlers invoked when a Thread abruptly terminates due to an
uncaught exception.
When a thread is about to terminate due to an uncaught exception the Java
Virtual Machine will query the thread for its UncaughtExceptionHandler
using
Thread.getUncaughtExceptionHandler()
and will invoke the handler's
uncaughtException() method,
passing the thread and the exception as arguments.
What are the methods used for Externalization?
- There are couple of methods which are used in Externalization
Interface.
1. writeExternal():This method
can be used to write the custom object for serialization.
2. readExternal():This method can
be used to read the custom object either from the network or file.
What is method local inner class?
- We can declare classes inside a method such types of inner classes are
called method local inner class.
- Method local inner class can be accessible only inside a method where it is
declared.
- Please refer to the below example.
package simplifiedjava.crackedInterview; public class MethodLocalInnerClassDemo {
public
static
void
main(String[] args) {
MethodLocalInnerClassDemo demo
= new
MethodLocalInnerClassDemo();
demo.invokeMethodInnerClass();
}
public
void
invokeMethodInnerClass() {
class
Inner{
public
void
sum(int
num1, int
num2) {
System.out.println("Addition is "+ (num1+num2));
}
}
Inner inner
= new
Inner();
inner.sum(100, 200);
}
} |
How many .class files will be created if there are 2 inner classes inside outer class?
- Total 3 .class files will be generated after successfully compiled a class which has two inner classes.
What is the difference between Collection and Collections?
|
Collection |
Collections |
1. |
The Collection is parent Interface. |
Collections is a utility class. |
2. |
It extends the Object class. |
It extends the Iterable interface. |
What is CircularQueue? What are the advantages of CircularQueue?
- Circular Queue is a linear data structure in which the operations are
performed based on FIFO (First In First Out) principle.
- The last element is connected back to the first element to make a circle.
- CircularQueue is also called 'Ring Buffer'.
- Circular queue is used in memory management and Process Scheduling.
- Advantages of Circular Queue:
1. All operations occur in constant time.
2. Doesn’t use dynamic memory.
3. No Memory leaks.
4. Simple Implementation.
5. Plays an important role in memory management.
What is Dictionary class?
- A java Dictionary is an abstract class that stores elements in the form of
key-value pairs.
- The Dictionary class is the abstract parent of any class, such as
Hashtable, which maps keys to values.
- Every key and every value is an object.
- In any one Dictionary object, every key is associated with at most one
value.
- Any non-null object can be used as a key and as a value.
- Please refer to the below example.
package simplifiedjava.crackedInterview;
import
java.util.Dictionary; import java.util.Hashtable; public class DictionaryClassDemo {
public static void
main(String[] args) {
Dictionary<Integer, String> dictionary = new
Hashtable<Integer, String>();
dictionary.put(10, "Ten");
dictionary.put(100, "Hundred");
dictionary.put(1000, "Thousand");
dictionary.put(1, "One");
System.out.println(dictionary);
}
} |
Can you declare public static void
main() method inside functional interface?
- Yes, we can declare the main() method inside the functional interface and
invoke the main() method from class with the interface name.
- But, It will be treated as a normal method.
- JVM always invoked the main method of a class not declared in the
interface.
- Please refer to the below example.
package simplifiedjava.crackedInterview.java8; public interface InterfaceForStaticMethod {
public
static
void
m1() {
System.out.println("m1() method called."); }
public
static
void
main(String[] args) {
System.out.println("Main method called.");
} } package simplifiedjava.crackedInterview.java8; public class StaticMethodDemo {
public
static
void
main(String[] args) {
InterfaceForStaticMethod.m1();
InterfaceForStaticMethod.main(args);
}
}
Output:
m1() method called. Main method called. |
- 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