Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,
Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,
Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers
1. What is an abstract class?
Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. An abstract class can contain no abstract methods also i.e. abstract class may contain concrete methods.
2. what are class variables?
Class variables are global to a class and belong to the entire set of objects that class creates. Only one memory location is created for each variable.3.
3. What is the Collection interface?
The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.
4. What must a class do to implement an interface?
The class must provide all of the methods in the interface and identify the interface in its implements clause.
5. What is the Collections API?
The Collections API is a set of classes and interfaces that support operations on collections of objects.
6. What is an array?
Array is a group of related data items that share a common name.For instance, we can define an array name salary to represent a set of salaries of a group of employees.
Examples : salary[10]
7. What is a list iterator?
The List and Set collections provide iterators, which are objects that allow going over all the elements of a collection in sequence. The java.util.Iterator interface provides for one-way traversal and java.util.ListIterator is an iterator for lists that allows the programmer to traverse the list in either direction (i.e. forward and or backward) and modify the list during iteration.
8 What is the main difference between a String and a StringBuffer class?
String is immutable : you can’t modify a string object but can replace it by creating a new instance. Creating a new instance is rather expensive.
StringBuffer is mutable : use StringBuffer or StringBuilder when you want to modify the contents. StringBuilder was added in Java 5 and it is identical in all respects to StringBuffer except that it is not synchronized,which makes it slightly faster at the cost of not being thread-safe.
9. When to use serialization?
A common use of serialization is to use it to send an object over the network or if the state of an object needs to be persisted to a flat file or a database.
10. What is the main difference between shallow cloning and deep cloning of objects?
Java supports shallow cloning of objects by default when a class implements the java.lang.Cloneable interface.
Deep cloning through serialization is faster to develop and easier to maintain but carries a performance overhead.
21. What are wrapper classes?
primitive data types may be converted into object types by using the wrapper classes contained in the java.lang package.
Exampes : int, float, long, char, double
11. What is the difference between an instance variable and a static variable?
Class variables are called static variables. There is only one occurrence of a class variable per JVM per class loader.When a class is loaded the class variables are initialized.
Instance variables are non-static and there is one occurrence of an instance variable in each class instance.Also known as a member variable or a field.
12 Where and how can you use a private constructor?
Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing.The instantiation is done by a public static method (i.e. a static factory method) within the same class.
13. What is type casting?
Type casting means treating a variable of one type as though it is another type.
Examples :
int m = 5;
byte n =i;
14. What is a user defined exception?
User defined exceptions may be implemented by defining a new exception class by extending the Exception class.
15. What is an instanceof operator?
Instanceof is an object reference operator and returns true if the object on the left-hand side is an instance of the glass given to the right hand side.This operator allows to determine whether the object belongs to a particular class or not.
16. What are runtime exceptions?
Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time.
17 What is the difference between an interface and an abstract class?
An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.
18. what is a package?
A package is a namespace that organizes a set of related classes and interfaces.The classes contained in the packages of other programs can be easily reused.Packages, classes can be unique compared with classes in other packages.That is, two classes in two different packages can have the same name.
20. Why do threads block on I/O?
Threads block on i/o (that is enters the waiting state) so that other threads may execute while the i/o Operation is performed.
21. What is the List interface?
The List interface provides support for ordered collections of objects.
22. What is the Vector class?
The Vector class provides the capability to implement a growable array of objects.
23 What is the base class of all classes?
java.lang.Object
24 What is the importance of static variable?
static variables are class level variables where all objects of the class refer to the same variable. If one object changes the value then the change gets reflected in all the objects.
25. What is the difference between a while statement and a do while statement?
A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do while statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do whilestatement will always execute the body of a loop at least once.
Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,
Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers
Java Language Interview Question and Answers:
1. What is an abstract class?
Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. An abstract class can contain no abstract methods also i.e. abstract class may contain concrete methods.
2. what are class variables?
Class variables are global to a class and belong to the entire set of objects that class creates. Only one memory location is created for each variable.3.
3. What is the Collection interface?
The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.
4. What must a class do to implement an interface?
The class must provide all of the methods in the interface and identify the interface in its implements clause.
5. What is the Collections API?
The Collections API is a set of classes and interfaces that support operations on collections of objects.
6. What is an array?
Array is a group of related data items that share a common name.For instance, we can define an array name salary to represent a set of salaries of a group of employees.
Examples : salary[10]
7. What is a list iterator?
The List and Set collections provide iterators, which are objects that allow going over all the elements of a collection in sequence. The java.util.Iterator interface provides for one-way traversal and java.util.ListIterator is an iterator for lists that allows the programmer to traverse the list in either direction (i.e. forward and or backward) and modify the list during iteration.
8 What is the main difference between a String and a StringBuffer class?
String is immutable : you can’t modify a string object but can replace it by creating a new instance. Creating a new instance is rather expensive.
StringBuffer is mutable : use StringBuffer or StringBuilder when you want to modify the contents. StringBuilder was added in Java 5 and it is identical in all respects to StringBuffer except that it is not synchronized,which makes it slightly faster at the cost of not being thread-safe.
9. When to use serialization?
A common use of serialization is to use it to send an object over the network or if the state of an object needs to be persisted to a flat file or a database.
10. What is the main difference between shallow cloning and deep cloning of objects?
Java supports shallow cloning of objects by default when a class implements the java.lang.Cloneable interface.
Deep cloning through serialization is faster to develop and easier to maintain but carries a performance overhead.
21. What are wrapper classes?
primitive data types may be converted into object types by using the wrapper classes contained in the java.lang package.
Exampes : int, float, long, char, double
11. What is the difference between an instance variable and a static variable?
Class variables are called static variables. There is only one occurrence of a class variable per JVM per class loader.When a class is loaded the class variables are initialized.
Instance variables are non-static and there is one occurrence of an instance variable in each class instance.Also known as a member variable or a field.
12 Where and how can you use a private constructor?
Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing.The instantiation is done by a public static method (i.e. a static factory method) within the same class.
13. What is type casting?
Type casting means treating a variable of one type as though it is another type.
Examples :
int m = 5;
byte n =i;
14. What is a user defined exception?
User defined exceptions may be implemented by defining a new exception class by extending the Exception class.
15. What is an instanceof operator?
Instanceof is an object reference operator and returns true if the object on the left-hand side is an instance of the glass given to the right hand side.This operator allows to determine whether the object belongs to a particular class or not.
16. What are runtime exceptions?
Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time.
17 What is the difference between an interface and an abstract class?
An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.
18. what is a package?
A package is a namespace that organizes a set of related classes and interfaces.The classes contained in the packages of other programs can be easily reused.Packages, classes can be unique compared with classes in other packages.That is, two classes in two different packages can have the same name.
20. Why do threads block on I/O?
Threads block on i/o (that is enters the waiting state) so that other threads may execute while the i/o Operation is performed.
21. What is the List interface?
The List interface provides support for ordered collections of objects.
22. What is the Vector class?
The Vector class provides the capability to implement a growable array of objects.
23 What is the base class of all classes?
java.lang.Object
24 What is the importance of static variable?
static variables are class level variables where all objects of the class refer to the same variable. If one object changes the value then the change gets reflected in all the objects.
25. What is the difference between a while statement and a do while statement?
A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do while statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do whilestatement will always execute the body of a loop at least once.