Frequently Asked Java Interview Questions
Wikipedia
Search results
Monday, May 19, 2014
Friday, April 11, 2014
Java Interview Common Questionnaire
Hi Guys,
Based on my experience in the software industry, there are some important topics you need to prepare for the interview for any of your dream company.
If you study this topic, you will definitely crack the technical round interview, I will also suggest some books at the end of the topic which will get you through understanding java in easy way.
The topics you need to focus on, for the Technical Interview on Java:
class A{
public void getMeSomething(){
}
}
class B extends class A{
private void getMeSomething(){
}
}
In this case it wont work. Like this you will find many more examples go through "SCJP" Java the book which I recommend the most and the "Head First Java".
2. Constructors:
private A(){
}
}
when you actually create the instance of class A then at that time constructor gets invoked. In this example only we cannot directly create the instance of the class directly we have to rely on the method in the class.
class A{
A(){
syso("A");
}
}
class B extends A{
B(){
syso("B");
}
public static void main(String []args){
B b = new B();
}
}
In this case the output will be A , B. Because the super class constructor get called first the the child class in this case. Like this you will find a lot of question easy when your concept will be clear. I recommend strongly to read Java SCJP book thoroughly even if you are still pursuing degree of engineering.
3.String: String is the most important concept to understand once you understand the concept of the string and string pool it will be a lot better for you to answer the question on the string:
try{
...................
......................
}finally{
...............
}
}
number format exception occurs;
}catch(Exception e){
syso("Exception");
}catch(NumberFormatException e){
syso("number format Exception");
}
For Java you should try reading SCJP and java headfirst it will be very helpful and the most convenient way to learn java.
Based on my experience in the software industry, there are some important topics you need to prepare for the interview for any of your dream company.
If you study this topic, you will definitely crack the technical round interview, I will also suggest some books at the end of the topic which will get you through understanding java in easy way.
The topics you need to focus on, for the Technical Interview on Java:
- Inheritance : In this you have to be perfect in the concept of "overriding" and "overloading". Much more tricky questions are asked on this topic which will confuse you but if you keep in mind the basic principal then it will be just a piece of cake for you.
class A{
public void getMeSomething(){
}
}
class B extends class A{
private void getMeSomething(){
}
}
In this case it wont work. Like this you will find many more examples go through "SCJP" Java the book which I recommend the most and the "Head First Java".
2. Constructors:
- In java constructors play an important role. Interviewer may ask many confusing questions on constructors. Such as can constructor of the class can be private? so do you get it now, if you make the constructor private then no one except that method of that class only can create an object of that class and ultimately none other class will be able to create the object of that class.
private A(){
}
}
when you actually create the instance of class A then at that time constructor gets invoked. In this example only we cannot directly create the instance of the class directly we have to rely on the method in the class.
- Most important thing the interviewer ask about constructor is that he will extend the classes and write the System.out.println(""); in it and he will ask you to what it will print after creating an object of the child class. Let me explain this with example:
class A{
A(){
syso("A");
}
}
class B extends A{
B(){
syso("B");
}
public static void main(String []args){
B b = new B();
}
}
In this case the output will be A , B. Because the super class constructor get called first the the child class in this case. Like this you will find a lot of question easy when your concept will be clear. I recommend strongly to read Java SCJP book thoroughly even if you are still pursuing degree of engineering.
3.String: String is the most important concept to understand once you understand the concept of the string and string pool it will be a lot better for you to answer the question on the string:
- You need to study the how the object are created and destroyed on the heap.
- Pay extra attention towards what are the different methods in the String class that can used such as substring, length ,lastIndexOf etc.
- Interviewer will ask the difference between String Buffer and String Builder for sure. Main difference is that String Buffer is synchronized and StringBuilder is not.
- Read all the methods related to the StringBuffer and StringBuilder also.
- The types of exceptions?
- How will you create the custom exceptions?
- Can the try block be written without the catch and only using finally?
try{
...................
......................
}finally{
...............
}
}
- And the answer to the above question is "Yes", it is possible to write the try block without using the catch block but in this case the finally block will not be used to catch the exceptions.
- Like this they will also ask what is the use of the finally block?
- what will happen if we catch the generalized exception first and then the particular exception?
number format exception occurs;
}catch(Exception e){
syso("Exception");
}catch(NumberFormatException e){
syso("number format Exception");
}
- In the above case, It will show the unreachable code exception because all the exception will be consumed by the above Exception catch statement.
5. Collections : Java Collections chapter what you have to really focus on most of the question come from this chapter:
6. Equals and Hashcode : The main question asked on this type will be:
- Define ArrayList<?>(); ?
- How to sort any collection?
- How to use comparable Interface?
- How to sort two objects based on the particular instance variable?
6. Equals and Hashcode : The main question asked on this type will be:
- Is it necessary to override both hashcode and equals method at the same time?
- What will happen if the equals is overridden and not the hashcode?
7. Difference between Interface and abstraction? when should we use interface and when should we use Abstraction? :
- The case where the implementation changes according the class we should use the interface. Suppose the birds class and Jet Plane class is there, both have the method in common fly but how they fly has to be written in the concrete class by the developer.And In case of abstraction consider the example of the alarm clock the may come with certain functions such as the current time and date. When you have to set the alarm that functionality may be given to the developer to implement it or if the developer wants then he can also override the in-built methods. And we can extend only one abstract class and we can implement multiple interfaces.
For Java you should try reading SCJP and java headfirst it will be very helpful and the most convenient way to learn java.
Please let me know if you like the blog.
Subscribe to:
Posts (Atom)