Core Java interview questions and answers

Basic Core java technical interview questions for freshers (J2EE) Collection
     
1.  What is java run time environment?
2.  How java is platform independent language?
3.  What is difference between compiler and interpreter?
4.  Java is secure language. Why?
5.  Why main function in java is static?
6.  What is abstract class and what is use of abstract class?
7.  Why a class cannot be static?
8.  Why abstract class cannot be final?
9.  What are final class, final method and final variable?
Answer:
A final class is special type of class which cannot be inherited i.e. we cannot create any subclass of final class. All the methods and variables of final class are also final.
A final method is special type of method which cannot be overridden in the subclass.
A final variable is special type of variable which after assigning a value at the time of declaration we cannot modified its value. It is necessary to initialize the final variable at the time of declaration.
10. What is default access specifier?
11. What is static import in java?
12. What is difference between checked and unchecked exception?
13. What is wrapper class in java?
14. What is generic?
15. What is difference between throw and throws keyword?
16. Can interface implements another interface?
17. Is it possible that any class which extends an abstract class and doesn't override all the method of that abstract class?
18. Is it true, all the methods and member variables of final class is also final? If it is true then why and if is false then why?
19. Can abstract class have a method which has body?
20. What is automatic type casting?
21. Why in java array can be declared as: int [] array;
22. Can a method whose return type is void have return keyword?
23. What is task of >>> operator?
24. What is meaning of variable number of argument in java?
25. What are difference between private, protected, public and default access specifiers?
26. What are the non access specifiers in java?
27. What is error in the declaration: float f=5.5;
28. Which of the following comparison more appropriate and why?
(a) if (a==5)
(b) if (5==a)
29. What are differences between following two if statements
(a) if (a&b)
(b) if (a&&b)
30. What is meaning of multiple catch clauses?
31. What is meaning of package in java?
32. What is difference between path and classpath command?
33. What is meaning of access protection?
34. Defined interface?
35. What are difference between class and interface?
36. What is use of this keyword?
37. How can you find the class name of given object?
38. Can exception in java can be cause of compilation error? If yes then why?
39. What are the properties of nested interface?
40. What is nested class?
41. Can class be protected? Why?
42. Can class be private? Why?
43. What are the properties of constructor?
44. What is default constructor?
45. What are uses of super keyword?
Answer:
(a) It is used to access the super class member variable from subclass either it is hidden in subclass or not.
(b) It is used to access the super class method from the subclass either it has overridden in subclass or not.
(c) In method form super keyword is used to call super class constructor.
46. What is dynamic method dispatch?
47. What is difference between c++ and java?
48. Give any examples of run time polymorphism.
49. What is difference between late and early binding?
50. What is encapsulation?
51. What is difference between overloading and overriding?
52. What is difference between final, finally and finalize ()?
Answer:
finalize (): It is method of Object class. This method is called by java garbage collector when garbage collector think there is not any reference of object of any class and it deletes the object of that class automatically.
53. What is meaning of abstraction?
54. How can you delete any object in java?
55. What is garbage collection in java?
56. Why java doesn't support multiple inheritances?
57. How can you say java is robust language?
58. Define inheritance.
Answer:
Inheritance is mechanism by which we can derive a new class from a already existing class. New class is called subclass or child class while exiting class is called as super class or sub class. Sub class may inherit some or all properties of super class. For this we use extends keyword in java. So, inheritance is based on the concept of re-usability.
59. What is JVM?
60. What is quick logical operator?

61. What is difference between .exe file and .class file?

62. What is byte code?

63. What is Unicode character?

64. Give an example of dynamic initialization in java?

65. What is multidimensional array in java?

65. What is difference between break and continue keyword?

66. What is for each version of loop?

67. What is class in java?

68. What is object in java?

69. When new operator allocates the memory for objects:

(a) Compiler time

(b) Run time

70. What is multithreading programming?

Answer:

Thread is smallest unit of code. In a program when two or more threads execute at the same or concurrently is known as multithreading programming. Each thread has different path of execution. It makes program more efficient because each thread perform different task. Some tasks like to read or write the files or print a text is slower process. In this time can be utilized by the other thread to perform other tasks, which maximize the utilization of CPU. Hence a thread program is also known as multitasking program.

71. Can sub class inherit constructors from the super class? Why?

Answer: Not, Sub class cannot inherit the constructors of super class by using extends keyword because constructors are not members of any class and extends keyword only inherits members of any class.

72. Which class is super class of all the classes in java?

Answer:

Object

Object class has defined in java.lang package.

73. If any subclass is in different package of the super class then which type of members of super class, it will not inherit?

Answer:

(a) protected members.

(b) Members which have default access specifier

74. What is difference between hidden methods and overridden methods?

Answer:

When we writes any method with same name, with same parameters and return type i.e. with same signature of any method of super class in the subclass then subclass method is called as overridden method while when you override any static method of super class in the subclass then that super class method is known as hidden method.

Example:

class Top{
void display(){
System.out.println("Top:display");

}
static void show(){ //hidden method
System.out.println("Top:show");

}
}

public class Test extends Top{
void display(){ //overridden method
System.out.println("Test:display");
}

static void show(){
System.out.println("Test:show");
}

public static void main(String [] args){

}
}

75. What is no-argument super class constructor?
Answer:
If super class has not any constructor or it has only no-argument constructor and if you doesn't call super class constructor from explicitly from subclass constructor then java compiler automatically inset a no-argument of constructor at the first line of each subclass class constructors either it has written explicitly or not to call the super class constructors. Such constructor is known as no-argument super class constructor.
76. What is constructor chaining in java?
Answer:
When you creates object of any class it calls the constructor of this class either its constructor has written explicitly or not and this constructor also calls its super class constructor either explicitly or implicitly and so on until it doesn't call the constructor of Object class. Such phenomenon of constructor calling is known as constructor chaining.
77. Suppose any class implements any interface and it overrides all the methods of that interface. If any other class extends that class then it is necessary to override the all the methods in subclass which has already overridden in the super class? If yes then why and if not then why?
Answer:
78. Why we cannot use abstract keyword before methods of an interface?
79. What are differences between an abstract class and an interface?
(a)All the methods and variables of interface are final and static.
(b)A class can implement more than one interface.
(c) All the methods of an interface are abstract i.e. which cannot have anybody.
(d)If any class is implementing any interface then it is necessary to overrides all the methods of an interface.
(e) An interface can extend more than other interface but it cannot extend any class.
(a)Abstract class can have methods and variables which is not static and final.
(b)A class can extends only one abstract class at a time.
(c) An abstract class can have a method which is not abstract i.e. which has method’s body.
(d) If any class which extends an abstract class which may override the all the abstract method of abstract class or it is itself an abstract class.
(e) An abstract class can extend another class or it can implement more than interfaces.
(f) We cannot create object of abstract class.
80. Declare a class which implements an interface but it is not necessary to override all the methods of an interface?
81. What is API?

4 comments:

Anonymous said...

plz provide the answers of all the ques....

Anonymous said...

please give the answers of all questions as soon as possible.

Anonymous said...

very good collection of questions .........
and could be better if solutions were also provided..

Anonymous said...

superb job......
very good questions