Core JAVA Question & Answer
Core JAVA Question & Answer
1. What is “JAVA”?
➢ JAVA is a high-level, object-oriented, platform-independent, secure programming language.
• It was developed by James Gosling in June 1991.
• First name was OAE and rename it into JAVA on 1995.
20. What is the difference between “static variable” and “local variable”?
➢
static variable Local variable
It’s created inside class and
1 1 It’s created inside a method.
outside the methods.
It has global access and can be use
2 2 It is work only inside the method.
anywhere in to the program.
3 We can use it without initialize it 3 We can’t use without initialized it
21. What are the data types in java and how much their memory size?
➢ There are 8 types of data type-
Data Memory Default
S/L remarks
Type size value
1 byte 1 Byte 0 Max value= +127, Min Value= -128
2 short 2 Byte 0 -
Integer
3 int 4 Byte 0 - value
“long” value terminates with ‘l’ or
4 long 8 Byte 0 ‘L’. (ex- 1.02L) Primitive
“float” value terminates with ‘f’ or
5 float 4 Byte 0.0 ‘F’. (ex- 1.02f) Decimal data
value type
6 double 8 Byte 0.0 -
<empty
7 char 2 Byte One digit value (ex- ‘c’)
space>
Having no number and quotation (ex- true,
8 boolean N/A false false)
This are also data type but not a keyword
9 String - null This is not a keyword, it’s a class. (ex- “Mike”)
Not a keyword, it is a dynamic data type variable (available
10 var dynamic - after JDK version 10)
34. Can we make multiple methods with same name in a same program?
➢ Yes, we can do it, by providing different type of arguments and different numbers of
argument.
• During calling statement we have to gives same type or same numbers of
arguments to call a particular one method.
35. Can we create more than one “main” methods in the same class?
➢ Yes, but providing different numbers of arguments and different types of arguments
36. What is the difference between “return” and “return value”?
➢
return return value
We use return keyword only inside We can’t use return value statement
1 1
the void methods. inside a void method.
If a method is not a void, then
2 It’s optional to use inside method. 2
writing return value is mandatory.
return keyword will transfer control It will transfer control and value both
3 3
to method calling statement. to the method calling statement.
79. What are the differences between “Interface” and “Abstract Class”?
➢ The Differences are-
Interface Abstract Class
1 There are 100% incomplete. 1 There 0 to 100% incomplete.
Interface can contain only incomplete Abstract Class can Consists of complete and
2 2
methods incomplete both methods.
3 Support multiple Inheritance. 3 Doesn’t support multiple Inheritance.
We create here only static and final variables,
Here we can create static, non-static & final
4 because all variables here by default static 4
variables.
and final.
99. What are differences between “Compile time” and “Run time” Exception?
➢ The differences are-
Compile time Exception Run time Exception
It found at during Program Execution
1 It found during compile time 1
time.
2 It’s detected by the compiler 2 It’s not detectable by the compiler.
It’s doesn’t detectable that why we
For this case the compiler prevents the
3 3 can’t prevent the code from the
code from the execution
execution
The example of this type of error is:
The example of this type of error is:
syntax and semicolon error. Such as
4 4 division bye zero, determining the
missing semicolon at the end of the
square root of a negative number.
statement.
100. What is “ArithmeticException”?
➢ This class handle Arithmetic Exception like dividing a number by zero.
103. What is the difference between using “Exception” class and “NumberFormatException”
class in catch block?
➢ When we use “NumberFormatException” class in catch block, then it can handle only
Number Format Exception, but if we use “Exception” class in catch block, then it can be
handling all the Exceptions occur in try block.
110. What are the differences between “final”, “finally” and “finalize”?
➢ The differences are-
Compared by “final” “finally” “finalize”
Basic 1 It’s a keyword in Java. 1 It’s a block in Java. 1 It’s a method in Java.
It’s always associated
It’s applicable for class, It’s applicable to any
Applicable 2 2 with “try-catch” 2
methods and variables. object.
block.
1> If a variable “final” then
it value can’t be
“finalize” method
change. A “finally” block clean
performs to clean up
2> If a method is “final” up the resources
Working 3 3 3 activities related to
then it can’t be override which use in try
the object before its
by the child class. block,
destruction.
3> If a class is “final” then
it can’t be inherited.
“finally” block “finalize()” method
“final” method is executes just after execute just before
Execution 4 4 4
executed when is call. the execution of try- the destruction of
catch block the object.
111. W
112. W
113. W
114. W
115. W
116. W
117. W
118. W
119. W
120. W
121. W
122. W
123. W
124. W
125. W
126. W
127. W
128. W
129. W
130. W
131. w