0% found this document useful (0 votes)
9 views10 pages

Viva

Uploaded by

akhileswarj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

Viva

Uploaded by

akhileswarj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

1)What is Object-Oriented Programming (OOP)?

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.

6)What is the difference between Abstract Class and Interface?


Abstract Class: Can have method implementations, supports inheritance.
Interface: Only contains method signatures (until Java 8), supports multiple inheritance.

7)Can you override a private or static method?


No, private methods are not inherited, and static methods are bound to the class.

8)What is method overloading?


Defining multiple methods with the same name but different parameter lists.

9)What is method overriding?


Providing a new implementation for a method in the subclass that exists in the parent class.

10)What is the super keyword?


Used to refer to the parent class’s methods, variables, or constructor.

11)What is the difference between this and super?


this: Refers to the current object.
super: Refers to the parent class’s object.

12)Can a constructor be overridden?


No, constructors are not inherited.

13)What is a static method? Can it be overridden?


A method that belongs to the class rather than an instance. It cannot be overridden, but it can be hidden.

14)What is the purpose of the final keyword in a class?


Prevents the class from being subclassed.

15)What is an inner class?


A class defined within another class. It can access the outer class’s members.

16)What is the difference between an interface and a class?


Interface: Defines a contract with no implementation (prior to Java 8).
Class: Can have state (fields) and implementation (methods).
17)What is multiple inheritance? Does Java support it?
Acquiring features from multiple parents. Java supports it through interfaces but not through classes.

18)What is the purpose of an abstract method?


To enforce subclasses to provide specific implementations.

Collections

1)What is the Java Collection Framework?


A set of classes and interfaces for working with collections (e.g., List, Set, Map).

3) What is the difference between List, Set, and Map?


List: Allows duplicates, maintains insertion order (e.g., ArrayList).
Set: No duplicates, unordered (e.g., HashSet).
Map: Key-value pairs, keys are unique (e.g., HashMap).

4)What is the difference between ArrayList and LinkedList?


ArrayList: Better for random access, uses a dynamic array.
LinkedList: Better for frequent insertions/deletions, uses a doubly-linked list.

5)What is the difference between HashMap and Hashtable?


HashMap: Non-synchronized, allows one null key.
Hashtable: Synchronized, does not allow null keys/values.

6)What is the difference between HashSet and TreeSet?


HashSet: Unordered, uses hashing.
TreeSet: Ordered, elements are sorted.

7)Why use collections instead of arrays?


Collections provide dynamic sizing, ready-made methods for manipulation, and support for
heterogeneous elements (e.g., in List).

8)What is the difference between LinkedHashMap and HashMap?


HashMap: Unordered.
LinkedHashMap: Maintains insertion order.

9)What is the difference between TreeMap and HashMap?


HashMap: Unordered.
TreeMap: Maintains natural or custom ordering.

10)How does a HashSet work?


Uses a HashMap internally to store elements as keys with a constant dummy value.

11)What is the purpose of Collections and Arrays classes in Java?


Utility classes that provide methods for operations like sorting, searching, and conversion.

12)What is the difference between Vector and ArrayList?


Vector: Synchronized.
ArrayList: Non-synchronized, faster.

13)What is the difference between Iterator and ListIterator?


Iterator: Forward traversal only.
ListIterator: Bi-directional traversal.

14)What is the purpose of the Comparable and Comparator interfaces?


Comparable: Defines natural ordering for objects.
Comparator: Defines custom ordering.

15)How does a PriorityQueue work?


Maintains elements in sorted order based on natural or custom priority.

16)What are the differences between HashSet and LinkedHashSet?


HashSet: No order guarantee.
LinkedHashSet: Maintains insertion order.

17)What is a Deque?
A double-ended queue that supports element insertion and removal at both ends.

18)What is the difference between ArrayDeque and LinkedList as a queue?


ArrayDeque: Faster, resizable array implementation.
LinkedList: Uses a linked list structure, higher memory overhead.

19)How does a TreeSet ensure order?


Uses a TreeMap internally and maintains a Red-Black Tree structure for sorting.

Arrays and Strings

1)What is an array?
A fixed-size data structure to store homogeneous elements.

2)What is the difference between Array and ArrayList?


Array: Fixed size, can hold primitives.
ArrayList: Dynamic size, holds objects only.

3)What is a String in Java?


A sequence of characters stored as an object of the String class. Immutable.

4)What is the difference between String, StringBuilder, and StringBuffer?


String: Immutable.
StringBuilder: Mutable, non-synchronized, faster.
StringBuffer: Mutable, synchronized, thread-safe.

5)How do you compare two strings?


Use equals() for content comparison. Use == for reference comparison.

Loops

1)What are the types of loops in Java?


For loop
While loop
Do-while loop
Enhanced for loop (for-each)

2)What is the difference between break and continue?


break: Exits the loop entirely.
continue: Skips the current iteration and moves to the next.

JRE, JDK, JVM

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.

4)What is the difference between JDK and JRE?


JDK: Includes JRE and development tools.
JRE: Includes JVM and libraries for running Java programs.

Exception Handling

1) What is Exception Handling?


A mechanism to handle runtime errors and maintain program flow using try-catch blocks.

2)What is the difference between Checked and Unchecked Exceptions?


Checked: Checked at compile-time (e.g., IOException).
Unchecked: Checked at runtime (e.g., NullPointerException).

3)What is the purpose of the finally block? Executes code regardless of whether an exception is thrown or
not.

JDBC (Java Database Connectivity)

1)What is JDBC?
JDBC (Java Database Connectivity) is an API in Java that enables applications to interact with relational
databases.

2)What are the main steps to connect to a database using JDBC?


Load the driver class (Class.forName).
Class.forName("org.apache.derby.jdbc.ClientDriver"); // Example for derby

Establish a connection (DriverManager.getConnection).


Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/database_name",
"username", "password");

Create a statement (Connection.createStatement).


Statement statement = connection.createStatement();

Execute queries (executeQuery or executeUpdate).


ResultSet resultSet = statement.executeQuery("SELECT * FROM table_name");
int rowsAffected = statement.executeUpdate("INSERT INTO table_name (column1, column2) VALUES
(value1, value2)");

Close the connection.

4)What is the difference between Statement and PreparedStatement?


Statement: Executes static SQL queries.
PreparedStatement: Executes precompiled SQL queries and supports parameterized queries, which help
prevent SQL injection.
5)What is a ResultSet in JDBC?
It is an interface that represents the result set obtained by executing a query and allows navigation
through retrieved rows.

7)What is the purpose of DriverManager?


It manages database drivers and establishes connections between the Java application and database.

10)How does PreparedStatement prevent SQL injection?


It uses placeholders (?) for parameters, which are treated as data and not executable code, preventing
malicious queries.

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.

2)What are the lifecycle methods of a servlet?


init(): Initializes the servlet.
service(): Processes requests.
destroy(): Cleans up resources before servlet destruction.

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
}

3)What is the purpose of doGet() and doPost() methods?


doGet(): Handles HTTP GET requests.
doPost(): Handles HTTP POST requests.

4) What is the difference between HttpServlet and GenericServlet?


HttpServlet: Specifically handles HTTP requests.
GenericServlet: Protocol-independent; can handle any type of request.

5)What is the deployment descriptor (web.xml) used for?


It is used to configure servlet mappings, context parameters, and other settings for the web application.

6)How do you handle session management in servlets?


Cookies.
URL rewriting.
HttpSession API.

7)What is the purpose of the ServletConfig and ServletContext objects?


ServletConfig: Provides configuration for a specific servlet.
ServletContext: Provides configuration for the entire web application.

8)How can you redirect a request to another resource?


Using response.sendRedirect() or RequestDispatcher.

JSP (JavaServer Pages)

1)What is JSP?
JSP is a technology used to create dynamic web content by embedding Java code into HTML.

2)What are the advantages of JSP over servlets?


Easier to write and maintain.
Allows embedding Java code directly in HTML.

Lifecycle of a JSP
Translation Phase
Compilation Phase
Initialization Phase
Request Processing Phase
Destruction Phase

Lifecycle of a Web Application


Deployment
Initialization
Request Handling
Session Management
shut down

3)What are JSP directives?


Instructions for the JSP engine, such as @page, @include, and @taglib.
4)What is the difference between <jsp:include> and <%@ include %>?
<jsp:include>: Includes content dynamically at runtime.
<%@ include %>: Includes content statically during translation.

5)What are JSP scripting elements?


<% ... %>: Scriptlet for Java code.
<%= ... %>: Expression for outputting data.
<%! ... %>: Declaration for class-level variables and methods.

6)What is the purpose of JSP implicit objects?


They are predefined objects like request, response, session, etc., that simplify development.

7)How do you manage sessions in JSP?


Using the session implicit object.

8)What are custom tags in JSP?


User-defined tags for reusability and modularity, implemented using tag libraries.

9)What is the difference between JSP and HTML?


JSP supports dynamic content with Java code, while HTML is static.

10)How is a JSP page converted into a servlet?


The JSP engine converts the JSP into a servlet during the translation phase.

Spring Boot

1)What is Spring Boot?


It is a framework that simplifies Java application development by providing pre-configured settings and
auto-configuration.

2)What are the main features of Spring Boot?


Auto-configuration.
Embedded servers (like Tomcat).
Spring Boot starters.

3)What is the purpose of the application.properties or application.yml file?


To configure application-level settings, such as database connections and server ports.

4)What is a Spring Boot starter dependency?


A pre-configured dependency that simplifies adding related libraries, e.g., spring-boot-starter-web for web
applications.

5)What is the role of the @SpringBootApplication annotation?


It enables component scanning, auto-configuration, and defines the application as a Spring Boot app.

6)What is the difference between @RestController and @Controller?


@Controller: Returns views (e.g., JSP or Thymeleaf).
@RestController: Returns JSON or other formats for REST APIs.

7)How do you configure a database in Spring Boot?


By specifying the database properties in application.properties or application.yml.
Angular

1)What is Angular?
Angular is a TypeScript-based front-end framework for building web applications.

2)What are the main features of Angular?


Component-based architecture.
Dependency injection.
Two-way data binding.

3)What is the difference between AngularJS and Angular?


AngularJS: Based on JavaScript.
Angular: Uses TypeScript, has improved performance and modularity.

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();
}

Multi-Level Abstraction (using Abstract Classes)


abstract class Animal {
abstract void makeSound();
}

class Dog extends Animal {


void makeSound() {
System.out.println("Bark");
}
}

4. Encapsulation
class Person {
private String name; // private variable

public String getName() { // getter method


return name;
}

public void setName(String name) { // setter method


this.name = name;
}
}

5. Array Syntax
Declare and Initialize an Array
int[] numbers = new int[5]; // declaration
int[] numbers = {1, 2, 3, 4, 5}; // initialization

Accessing Array Elements


int firstNumber = numbers[0]; // access first element

6. ArrayList Syntax
Importing ArrayList
import java.util.ArrayList;

Creating an ArrayList
ArrayList<String> list = new ArrayList<>();

Adding Elements to ArrayList


list.add("Element");

Accessing Elements in ArrayList


String element = list.get(0); // access first element

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;
}

8. Return Methods Syntax


Returning Values from a Method
public String getGreeting() {
return "Hello, World!";
}

9. Creating Objects
Using Constructor to Create Objects
class Car {
String model;

Car(String model) { // constructor


this.model = model;
}
}

Car myCar = new Car("Toyota");

You might also like