Interview Questions
Interview Questions
2)length(arrays) vs length()
5)Access Modifiers
7)Abstract Method : Even though we don't have implementation still we can declare a
method with abstract modifier.That is abstract methods have only declaration but
not implementation. Hence abstract method declaration should compulsory ends with
semicolon.
6)synchronized
1. Synchronized is the modifier applicable for methods and blocks but not for
variables and classes.
2. If a method or block declared with synchronized keyword then at a time only one
thread is allow to execute that method or block on the given object.
7)What is interface?
10)polymorphism
12)overriding/method hiding
13)Constructor?
1. Object creation is not enough, compulsory we should perform initialization then
only the object is in a position to provide the response properly.
2. Whenever we are creating an object some piece of the code will be executed
automatically to perform initialization of an object this piece of the code is
nothing but constructor.
3. Hence the main objective of constructor is to perform initialization of an
object.
Static Block:
1)Static blocks will be executed at the time of class loading hence if we want to
perform any activity at the time of class loading, we have to define that activity
inside static block.
2)Within a class we can take any no. Of static blocks and all these static blocks
will be executed from top to bottom.
16)Exception Hirarchy
Checked Exceptions : The exceptions which are checked by the compiler whether
programmer
handling or not, for smooth execution of the program at runtime, are called checked
exceptions.
Example :
FileNotFoundException
Unchecked Exceptions : The exceptions which are not checked by the compiler whether
programmer
handing or not, are called unchecked exceptions.
Example :
ArithmeticException
NullPointerException
18)final/finally/finalize
final:
• final is the modifier applicable for classes, methods and variables.
• If a class declared as the final then child class creation is not possible.
• If a method declared as the final then overriding of that method is not
possible.
• If a variable declared as the final then reassignment is not possible.
finally:
• finally is the block always associated with try-catch to maintain clean up
code which should be executed always irrespective of whether exception raised or
not raised and whether handled or not handled.
finalize:
• finalize is a method, always invoked by Garbage Collector just before
destroying
an object to perform cleanup activities.
19)throw and throws keyword
Throw Keyword:
Sometimes we can create Exception object explicitly and we can hand over to the JVM
manually by using throw keyword.
Throws Statement:
In our program if there is any chance of raising checked exception then compulsory
we should handle either by try catch or by throws keyword otherwise the code won't
compile.
20)Srting/StringBuffer/StringBuilder
1. If the content is fixed and won't change frequently then we should go for
String.
2. If the content will change frequently but Thread safety is required then we
should go for StringBuffer.
3. If the content will change frequently and Thread safety is not required then we
should go for StringBuilder.
What is the differnce between above 2 statements? Go through String Constant Pool
concepts
25)Wrapper Classes
28)Serialization?
28)Collections, cursors
29)Generics
30)application.yaml
31)pom.xml
32)dependencies
33)@value
34) https://www.javatpoint.com/java-programs