Frequently Asked Interview Questions: Java Basics
Frequently Asked Interview Questions: Java Basics
1. What is JAVA?
3. What is Polymorphism?
8. Using one line of code, how can it be proved that the array is not
null but empty?
Print args.length
The code “Print args.length” will print 0, which proves it is empty and not
null. Because in case it is null there will be a NullPointerException with
the expression “print args.length”
Overloading takes place when two or more methods in one class are
given the same method name but contains different parameters.
11. How many objects are created in the following piece of code?
12. What are wrapper classes and why are wrapper classes
required?
Java Wrapper class help us to use Java primitive data types as objects.
So, using a Java wrapper allows primitive data type function like an
object. It is required in case want an object reference to a primitive
value, where their basic form as int, char, long, etc. is not sufficient.
13. Does garbage collection guarantee that a program will not run
out of memory?
No, garbage collection does not guarantee that a program will not run
out of memory. It just runs asynchronously when the system is idle and
when a separate thread is activated the garbage collector shifts to a
consistent state before it terminates.
if(set.add(array[i]) == false)
boolean Boolean
byte Byte
char Character
float Float
int Integer
long Long
short Short
double Double
17. Can I import the same package/class twice? Will the JVM load
the package twice at runtime?
Yes, we can import same package/class twice, but class is created only
once i.e. memory allocation happens only once. This does not affect the
compilation of the program and it runs fine.
18. How can one have control over the serialization process?
Exceptions Errors