Java Interview QUESTIONS
Java Interview QUESTIONS
2. What is class?
- A class in java is a collec on of data members and member func ons. A class is a
user-de ned type that describes what a certain type of object will look like. A Class is
like an object constructor, or a "blueprint" for crea ng objects.
3. What is object?
- A Java object is a member of a Java class. It is also called an instance of a class. Java
objects have three primary characteris cs: iden ty, state, and behavior. These
characteris cs are the building blocks of any class object and set the scene for how
they are used.
9. What is interface ?
- The interface in Java is a mechanism to achieve abstrac on. There can be only
abstract methods in the Java interface, not method body. It is used to achieve
abstrac on, mul ple inheritance and to achieve loose Coupling in Java.
In other words, you can say that interfaces can have abstract methods and variables. It
cannot have a method body.
Java Interface also represents the IS-A rela onship.
27.What is a ClassLoader?
- Java Classloader is the program that belongs to JRE (Java Run me Environment). The
task of ClassLoader is to load the required classes and interfaces to the JVM when
required.
How would you di eren ate between a String, StringBu er, and a StringBuilder?
- Storage area: In string, the String pool serves as the storage area. For StringBuilder
and StringBu er, heap memory is the storage area.
Mutability: A String is immutable, whereas both the StringBuilder and StringBu er are
mutable.
E ciency: It is quite slow to work with a String. However, StringBuilder is the fastest in
performing opera ons. The speed of a StringBu er is more than a String and less than
ffi
ff
ti
ti
ff
ti
ff
ff
ti
ti
ff
ti
a StringBuilder. (For example appending a character is fastest in StringBuilder and very
slow in String because a new memory is required for the new String with appended
character.)
Thread-safe: In the case of a threaded environment, StringBuilder and StringBu er are
used whereas a String is not used. However, StringBuilder is suitable for an
environment with a single thread, and a StringBu er is suitable for mul ple threads.
32.Oop's concepts
1. Object
2. Class
3. Inheritance
4. Polymorphism
5. Abstrac on
ti
ti
ff
ti
ti
ff
fi
fi
ti
ft
ti
ti
ti
ff
6. Encapsula on
7. Coupling
8. Cohesion
9. Associa on
10.Aggrega on
11.Composi on
ti
ti
ti
ti