1. What is Java?
Java is a high-level, object-oriented, platform-independent programming language developed by Sun
Microsystems (now owned by Oracle). It was released in 1995 and is known for its "Write Once, Run
Anywhere" (WORA) capability.
2. What is a Class and Object ?
• Class: A blueprint or template to create objects. Contains fields (variables) and methods(functions).
• Object: An instance of a class.
3. How to Create an Object (Syntax)
ClassName obj = new ClassName(); // e.g., Student s = new Student();
4. What is a constructor
• Special method called when an object is created.
• Same name as class, no return type.
5. What is Method Overloading and Overriding
• Method Overloading
Same method name, different parameters (compile-time polymorphism).
• Method Overriding
Subclass provides a specific implementation of a method in the superclass (runtime polymorphism).
6. What is Polymorphism ?
Polymorphism means "many forms" — in Java, it allows one interface or method to be used for different
underlying forms (data types or implementations).
7. What are the Types of Polymorphism
Two types they are,
Compile-time Polymorphism (also called Method Overloading)
Runtime Polymorphism (also called Method Overriding)
8. What is Final keyword
Used with variable (makes it constant), method (cannot override), class (cannot inherit).
1. Final Variable
• Once a variable is declared as final, its value cannot be changed (it becomes a constant).
2. Final Method
• A final method cannot be overridden by subclasses.
3. Final Class
• A final class cannot be extended (no subclass can be created).
9. What is Abstraction
• Abstraction It means hiding internal implementation details and showing only the essential features of an
object
10. What is a String
• A String is a sequence of characters. It is not a primitive data type—it's an object of the String Once a
string is created, it cannot be changed.
11. What is StringBuilder
A StringBuilder is a mutable sequence of characters—unlike String,it is faster than String
12. What is StringBuffer in Java?
StringBuffer is a mutable, thread-safe class used to work with strings that can be modified after creation.
13. What is a Variable in Java?
A variable in Java is a named memory location used to store data during the execution of a program. Each
variable has:
• A data type (e.g., int, String)
• A name
• A value
14. What is a Data Type?
A data type in Java defines the type of data a variable can hold, such as integers, decimals, characters, or objects.
It helps the compiler allocate memory and perform type checking.
Data types like int,char,float,double.
15. Define loops
Loops are used to execute a block of code repeatedly as long as a certain condition is true. Java supports three
main types of loops:
1. for Loop
Best when the number of iterations is known.
2. while Loop
Used when the number of iterations is unknown; runs as long as the condition is true.
3. do-while Loop
Same as while loop, but executes at least once, because the condition is checked after the loop body.
16. What Are Conditional Statements in Java?
They control the flow of execution by running different code blocks depending on a condition is true or false.
1. if Statement
Executes a block of code only if the condition is true.
2. if-else Statement
Executes one block if the condition is true, and another if it is false.
3.switch Statement
Used to select one block of code from multiple options based on the value of a variable.
17. Servlet & Applet
• Servlet – Java programs run on server, handle web requests like login forms (used in backend).
• Applet – Java program run in a browser like games (mostly outdated now).
18. Difference Between break and continue
Both break and continue are loop control statements used to alter the flow of loops, but they behave
differently.
Break Statement
• Terminates the entire loop or switch block immediately.
Continue Statement
Skips the current iteration and moves to the next iteration of the loop.
19. Difference Between throw and throws
Both throw and throws are used in exception handling, but they serve different purposes.
1. throw
1. Used to explicitly throw an exception object in the code.
2. Can only be used inside a method or block.
2. throws
o Declares the possibility of an exception being thrown by a method.
o in the method signature.
o Can declare multiple exceptions separated by commas.
20. Difference Between List and Set in Java
List and Set are both part of the Java Collection Framework, but they are used for different purposes based on how
they store and manage elements.
LIST:
o Maintains insertion order
o Allows duplicates
o Slightly slower for search (in large data)
SET:
o Does not guarantee order
o Does NOT allow duplicates
o Faster In search
21. Why try and catch Blocks Are Used ?
It provides try and catch blocks as part of exception handling to manage runtime errors gracefully, without
crashing the program.
1. try Block
• Contains code that might throw an exception..
2. catch Block
• Catches and handles exceptions thrown in the try block.
22. What is the difference between ArrayList and LinkedList?
ArrayList is fast for accessing, LinkedList is fast for inserting/deleting.
23. What is a Map?
A key-value pair collection where keys are unique.
Program questions:
24.Factorial of a Number
public class Factorial {
public static void main(String[] args) {
int num = 5;
int fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i;
}
System.out.println("Factorial: " + fact);
}
}
25.Reverse a String
public class ReverseString {
public static void main(String[] args) {
String str = "Java";
String reversed = "";
for (int i = str.length() - 1; i >= 0; i--) {
reversed += str.charAt(i);
}
System.out.println("Reversed: " + reversed);
}
}