Viva
Viva
A paradigm based on concepts of objects, which contain data (fields) and methods. Core principles:
Encapsulation, Inheritance, Polymorphism, and Abstraction.
2)What is Encapsulation?
Wrapping data and code together as a single unit; achieved using access modifiers and getter/setter
methods.
3)What is Inheritance?
A mechanism where one class (child) acquires properties and methods of another (parent) class.
4)What is Polymorphism?
The ability of a method to perform differently based on the object calling it. Types: Compile-time (method
overloading) and runtime (method overriding).
5)What is Abstraction?
Hiding implementation details and showing only essential features. Achieved using abstract classes and
interfaces.
Collections
17)What is a Deque?
A double-ended queue that supports element insertion and removal at both ends.
1)What is an array?
A fixed-size data structure to store homogeneous elements.
Loops
1)What is JVM?
Java Virtual Machine; it executes Java bytecode.
2)What is JDK?
Java Development Kit; includes tools for development (compiler, debugger) and JRE.
3)What is JRE?
Java Runtime Environment; contains JVM and libraries for running Java programs.
Exception Handling
3)What is the purpose of the finally block? Executes code regardless of whether an exception is thrown or
not.
1)What is JDBC?
JDBC (Java Database Connectivity) is an API in Java that enables applications to interact with relational
databases.
Servlets
1) What is a servlet?
A servlet is a Java program that runs on a web server, processes client requests, and generates dynamic
web content.
Lifecycle of a Servlet
Loading and Instantiation
// Example servlet class
public class MyServlet extends HttpServlet {
// Servlet methods will be defined here
}
Initialization
@Override
public void init() throws ServletException {
// Initialization code here
}
Request Handling
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// Handle GET request
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// Handle POST request
}
Destruction
@Override
public void destroy() {
// Cleanup code here
}
1)What is JSP?
JSP is a technology used to create dynamic web content by embedding Java code into HTML.
Lifecycle of a JSP
Translation Phase
Compilation Phase
Initialization Phase
Request Processing Phase
Destruction Phase
Spring Boot
1)What is Angular?
Angular is a TypeScript-based front-end framework for building web applications.
Syntaxs:
1. Loops
For Loop
for (int i = 0; i < n; i++) {
// code block
}
While Loop
while (condition) {
// code block
}
Do-While Loop
do {
// code block
} while (condition);
2. Exception Handling
Try-Catch Block
try {
// code that may throw an exception
} catch (ExceptionType e) {
// handle exception
} finally {
// code that will always execute
}
3. Abstraction
Single Level Abstraction (using Interfaces)
interface Animal {
void makeSound();
}
4. Encapsulation
class Person {
private String name; // private variable
5. Array Syntax
Declare and Initialize an Array
int[] numbers = new int[5]; // declaration
int[] numbers = {1, 2, 3, 4, 5}; // initialization
6. ArrayList Syntax
Importing ArrayList
import java.util.ArrayList;
Creating an ArrayList
ArrayList<String> list = new ArrayList<>();
7. Method Syntax
Defining a Method
returnType methodName(parameters) {
// method body
return value; // if return type is not void
}
Example of a Method
public int add(int a, int b) {
return a + b;
}
9. Creating Objects
Using Constructor to Create Objects
class Car {
String model;