0% found this document useful (0 votes)
16 views17 pages

Ese 1

The document provides a comprehensive overview of various programming concepts in C#, including exception handling, event handling, and the structure of a C# program. It also covers topics like LINQ architecture, CRUD operations using LINQ to SQL, and the differences between DataReader and DataSet for disconnected data access. Additionally, it includes examples of mouse click events, class inheritance, and stored procedures in SQL, along with a JavaScript program for sorting arrays.

Uploaded by

whiteyaksha24
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)
16 views17 pages

Ese 1

The document provides a comprehensive overview of various programming concepts in C#, including exception handling, event handling, and the structure of a C# program. It also covers topics like LINQ architecture, CRUD operations using LINQ to SQL, and the differences between DataReader and DataSet for disconnected data access. Additionally, it includes examples of mouse click events, class inheritance, and stored procedures in SQL, along with a JavaScript program for sorting arrays.

Uploaded by

whiteyaksha24
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/ 17

U-1

Q.1) Write a program to handle the Mouse Click Event using C# and explain the concept
of event handling ?
—-> Exception handling is a crucial aspect of error management in C# programming. It enables
developers to anticipate and gracefully handle unexpected situations that may arise during program
execution. Core Exception Classes: 1) System.Exception: The root class of all exceptions in C# . 2)
System.ApplicationException 3)
System.SystemException.Specific Exception Classes: 1) ArgumentException: Thrown when an invalid
argument is passed to a method or constructor. 2) FormatException. 3) IndexOutOfRangeException. 4)
NullReferenceException. 5)
FileNotFoundException. 6) IOException. 7) OutOfMemoryException. Handling Exceptions with try-catch
Blocks: The primary mechanism for handling exceptions in C# is the try-catch block. The try block
encloses the code that may throw an exception, while the catch block specifies the code to execute when
an exception occurs. Syntax :
try
{ // Code that may throw an exception} catch (ExceptionType1 exceptionVariable1) { // Handle
exceptionType1} catch (ExceptionType2 exceptionVariable2)
{ // Handle exceptionType2}
finally
{ // Code that always executes, regardless of exceptions}

Example : try
{
int[] numbers = new int[5];
numbers[5] = 10; // Attempting to access an out-of-bounds index
}
catch (IndexOutOfRangeException ex)
{
Console.WriteLine("Index out of range: " + ex.Message);
}

Taxonomy of Built-in Exception Classes in C# : C# provides a comprehensive set of built-in


exception classes that tackle various types of errors. These classes are organized in a hierarchical
structure, inheriting from the base class
System.Exception. This inheritance allows for specific exception types to be handled more precisely.

Q.2) Write a program to handle the Mouse Click Event using C# and explain the concept of
event handling. —--->
using System; using System.Windows.Forms;
public class MouseClickExample : Form
{
public MouseClickExample()
{
this.Text = "Mouse Click Event Example";
this.Size = new Size(300, 200);
this.MouseClick += new
MouseEventHandler(this.Form_MouseClick);
}private void Form_MouseClick(object sender, MouseEventArgs e){ Console.WriteLine("Mouse clicked at
coordinates: " + e.X + ", " + e.Y);}
static void Main(){Application.Run(new MouseClickExample());}}

Event handling is a fundamental concept in programming that enables applications to respond to user
interactions or system events. In C#events are represented by classes that inherit from the
System.EventArgs class. When an event occurs, the corresponding event handler method is invoked,
allowing the program to take appropriate action.
Q.3)Write a C# code to create a class Laptop which inherits the base class LaptopBase.
LaptopBase has several constant values that are used in the main method.
—---> using System;
class LaptopBase
{
const string BRAND_DELL = "Dell"; const string BRAND_SONY = "Sony"; const int
PRICE_DELL = 1500; const int PRICE_SONY = 2000; const string PROCESSOR_DELL = "i5";
const string PROCESSOR_SONY = "i9"; const int RAM_DELL = 4; const int RAM_SONY = 8;
const int HDD_DELL = 1;
const int HDD_SONY = 1;
public void PrintSpecifications()
{

Console.WriteLine("*******************************
*****"); }
}
class Laptop : LaptopBase
{
private string brand; private int price; private string processor; private int ram;
private int hdd;

public Laptop(string brand, int price, string


processor, int ram, int hdd)
{
this.brand = brand; this.price = price; this.processor = processor; this.ram = ram;
this.hdd = hdd;
}

public void PrintDetails()


{
Console.WriteLine("Name : " + brand);
Console.WriteLine("Price : $" + price);
Console.WriteLine("Processor : " + processor);
Console.WriteLine("Ram : " + ram + "GB"); Console.WriteLine("HDD : " + hdd + "TB");
}
}
class MainClass
{
public static void Main(string[] args)
{
Laptop laptopDell = new
Laptop(LaptopBase.BRAND_DELL,
LaptopBase.PRICE_DELL,
LaptopBase.PROCESSOR_DELL,
LaptopBase.RAM_DELL,
LaptopBase.HDD_DELL);
laptopDell.PrintSpecifications();
laptopDell.PrintDetails();
Laptop laptopSony = new
Laptop(LaptopBase.BRAND_SONY,
LaptopBase.PRICE_SONY,
LaptopBase.PROCESSOR_SONY,
LaptopBase.RAM_SONY,
LaptopBase.HDD_SONY);
laptopSony.PrintSpecifications();
laptopSony.PrintDetails();
}
}
Q.4) Define Delegate. What are the multicast delegates?
—---> Definition of Delegate: In programming, a delegate is a type that represents references to methods
with a particular parameter list and return type. It acts as a function pointer, allowing you to encapsulate a
method and invoke it indirectly. Delegates are particularly useful for event handling, callback mechanisms,
and asynchronous programming.

Multicast Delegates: A multicast delegate, also known as a combinable delegate, is a special type of delegate
that can hold references to multiple methods. When a multicast delegate is invoked, it calls all the methods
it references in the order they were added. This enables you to chain together multiple methods and execute
them in sequence.
Q.5) Describe the structure of a C# Program with proper code structure. Explain the jump
statements available in C#?
—--> 1. Namespaces: C# programs often belong to namespaces, which are hierarchical structures for
organizing code. Typically, the namespace declaration is placed at the beginning of the program. 2. Using
Directives: Using directives specify which namespaces and classes are accessible within the program.3.
Class Declarations: Classes are the fundamental building blocks of object-oriented programming.4.
Method Declarations: Methods are blocks of code that define specific actions or functionalities within a
class. 5. Main Method: The Main method is the entry point of a C# application. 6.Statements: Statements
are the basic building blocks of C# code. They represent instructions that the program executes . 7.
Control Flow Statements: Control flow statements determine the order in which statements are executed.
Jump Statements in C#:
1) break: Terminates the current loop or switch statement and transfers control to the following
statement.2) continue: Skips the remaining iterations of the current loop and starts the next iteration.
3) return: Exits the current method and returns a value (if applicable) to the caller. 4)goto: Jumps to a
specific labeled statement within the program.
5) throw: Raises an exception, which is a special type of error that interrupts the normal program flow.

Q.6) Write a program to add two numbers. Only condition is if the sum of numbers is odd
it fires an event that prints a message using delegates. —--> using System;

public delegate void OddSumEventHandler(int


sum); class NumberAdder
{
public event OddSumEventHandler OnOddSum;
public void AddNumbers(int a, int b)
{ int sum = a + b; if (sum % 2 == 1)
{ OnOddSum(sum);
}}}
class Program
{ static void Main(string[] args)
{NumberAdder adder = new NumberAdder(); adder.OnOddSum += new
OddSumEventHandler(OnOddSumEventHandl
er); adder.AddNumbers(5, 3);
}
static void OnOddSumEventHandler(int sum)
{
Console.WriteLine("The sum of the numbers is odd: " + sum);
}
}

U-2
Q.1) Write steps to establish ADO.NET SQL Server Connection and create a table of
Student(id ,name ,email , join_date) write code in Program.cs file.
—-> Step 1: Install SQL Server and SQL Server Management Studio (SSMS) Step 2: Create a SQL Server
Database Step 3: Establish an ADO.NET SQL Server
Connection. Step 4: Create the Student Table

Program.cs :

using System; using System.Data.SqlClient; namespace AdoNetStudentTable


{class Program{ static void Main(string[] args)
{ // Establish SQL Server connection string connectionString =
"Server=localhost;Database=StudentDB;Truste d_Connection=True"; using (SqlConnection connection =
new
SqlConnection(connectionString))
{ connection.Open();
// Create the Student table string createTableSql = "CREATE TABLE Student (id INT
IDENTITY(1,1) PRIMARY KEY, name VARCHAR(50) NOT NULL, email VARCHAR(100)
NOT NULL, join_date DATE NOT NULL)";
SqlCommand createTableCommand = new SqlCommand(createTableSql,
connection); createTableCommand.ExecuteNonQuery(); Console.WriteLine("Student table created
successfully.");
}} }}

Q.2) Describe the architecture of LINQ?


—> LINQ (Language Integrated Query) is a powerful feature in .NET programming languages like C#
that enables querying data from various sources using a unified syntax.

The LINQ architecture consists of three primary layers:1. Language Extension: The language extension
layer sits at the top of the architecture and provides the query syntax that developers use to formulate
queries. 2. Query Provider : The query provider layer acts as an intermediary between the query
expressions and the data source. It translates the query expressions into a format that the underlying
data source can understand.mory collections.3. Data Source: The data source layer represents the actual
data being queried. It encompasses various types of data storage, including databases, file systems, and
network resources.
This layered architecture provides several advantages for LINQ: 1.) Unified Query Syntax
2.) Expressive Query Language 3.) Improved
Performance 4.) Enhanced Developer
Productivity.

Q.3) How would we use LINQ to SQL to perform CRUD operations?


—-> 1) Create Operation (Insert): To insert a new record into a SQL Server table using LINQ to SQL, you
can create an instance of the corresponding data class, set its properties with the desired values, and
add it to the data context's table collection. 2) Read Operation (Select): To retrieve data from a SQL
Server table using LINQ to SQL, you can use the data context's table collection to query the database.
3) Update Operation (Update): To update an existing record in a SQL Server table using LINQ to SQL,
you can modify the properties of the corresponding data object and then call the
SubmitChanges() method. 4) Delete Operation (Delete): To remove a record from a SQL Server table using
LINQ to SQL, you can retrieve the corresponding data object and then call the DeleteOnSubmit() method on
the data context's table collection.

Q.4) Consider the employee database and solve the following queries using SQL. All the
primary keys are underlined and highlighted. Employee (emp_name, street, city) Works
(emp_name, company_name, salary) Company (company_name, city) Manages
(emp_name, manager_name) (a) Find the names of all the employees who work for Royal
Bank Corporation. (b) Find the names, street addresses, and cities of residence of all
employees who work for Royal Bank Corporation and earn more than 300000 per annum. (c)
Find the names of all employees in this database who live in the same city as the companies
for which they work. (d) Find the names of all the employees who earn more than every
employee of First Bank Corporation.
—-> a)
SELECT emp_name
FROM Employee
INNER JOIN Works ON Employee.emp_name = Works.emp_name
WHERE Works.company_name = 'Royal Bank
Corporation'; b)
SELECT e.emp_name, e.street, e.city
FROM Employee e
INNER JOIN Works w ON e.emp_name =
w.emp_name
WHERE w.company_name = 'Royal Bank
Corporation'
AND w.salary > 300000;
c)
SELECT e.emp_name
FROM Employee e
INNER JOIN Works w ON e.emp_name =
w.emp_name
INNER JOIN Company c ON w.company_name
= c.company_name WHERE e.city = c.city; d)
SELECT e.emp_name
FROM Employee e
WHERE e.salary > ( SELECT MIN(salary)
FROM Works w2
WHERE w2.company_name = 'First Bank
Corporation'
);
Q.5) Create a stored Procedure named "SelectAllCustomers" that selects all records from
the "Customers" table.
Explain how LINQ is better than Stored
Procedures.
—--->
CREATE PROCEDURE SelectAllCustomers
AS
BEGIN SELECT *
FROM Customers; END;

LINQ is better than stored procedures:


Feature LINQ Stored Procedures

Syntax C# code SQL


Type Compile-time
safety type checking No type checking

Supports a wide
range of query Limited to basic
Power operations operations query

Can be
dynamically
generated at
Flexibility runtime Static
Integration
with
oth
er Better integrated
technologi with other .NET
es technologies Limited integration

U.3
Q.1) Write a JavaScript program to sort the elements of an array in ascending order.
—---> function sortAscending(array) {
for (let i = 0; i < array.length; i++) {
for (let j = 0; j < array.length - i - 1; j++) {
if (array[j] > array[j + 1]) { const temp = array[j]; array[j] = array[j + 1]; array[j + 1] =
temp; }}}
return array;}
const numbers = [5, 2, 4, 1, 3];
Const sortedNumbers=
sortAscending(numbers);
console.log(sortedNumbers); // Output: [1, 2, 3, 4, 5]

Q.2) If anyone wants to perform the operations in Disconnected mode, Which one should we
use: DataReader or DataSet? Explain why?
—-> For performing operations in disconnected mode, the preferred choice is the DataSet object.
DataReader: 1) A forward-only, read-only data stream that retrieves data from a database. 2) Does not
provide any caching or data manipulation capabilities. 3) Requires an active connection to the database to
function. 4) Not suitable for disconnected data access. DataSet: 1) An in-memory representation of a
database that holds data in tables and relationships. 2) Provides caching and data manipulation capabilities,
including filtering, sorting, and grouping. 3) Does not require an active connection to the database to function.
4) Ideal for disconnected data access and scenarios where persistent storage of data is needed.
Q.3) Explain the working of the following controls : (i) Button (ii) Checkbox (iii) Label (iv)
Textbox.
—-->
(i) Button : A button is a control that allows the user to trigger an action when clicked. It is typically used
to submit forms, navigate between pages, or perform other tasks. When a button is clicked, it fires an
event that can be handled by JavaScript or other code. (ii) Checkbox : A checkbox is a control that allows
the user to select or deselect an option. It is typically used to represent a binary choice, such as yes or
no, true or false, or on or off. When a checkbox is checked or unchecked, it fires an event that can be
handled by
JavaScript or other code. (iii) Label : A label is a control that is used to display text. It is typically used to
identify other controls, such as input fields or buttons.
(iv) Textbox: A textbox is a control that allows the user to enter text. It is typically used to collect user input,
such as names, addresses, or email addresses. When a textbox is edited, it fires an event that can be
handled by
JavaScript or other code.

Q.4) Write HTML code to display the following table with a background color cyan in the
center of the web page:

—-->
<!DOCTYPE html>
<html>
<head>
<title>Exam Schedule</title>
<style> table { background-color: cyan; margin: 0 auto; width: 80%; border-collapse:
collapse;} th, td {
padding: 8px; text-align: left;
border: 1px solid #ddd;
}
</style>
</head>
<body>
<table>
<caption>Exam Schedule</caption>
<tr>
<th>Exam Date</th>
<th>Time of Exam</th>
<th>Course Code</th>
<th>Course Begin</th>
<th>Course End</th>
<th>Name</th>
</tr>
<tr>
<td>05/07/2022</td>
<td>11.00 a.m. - 12.00 p.m.</td>
<td>CS-255</td>
<td>DM 2.30 p.m.</td>
<td>3.30 p.m.</td>
<td>CS-256 COA</td>
</tr>
<tr>
<td>06/07/2022</td>
<td>11.00 a.m. - 12.00 p.m.</td>
<td>CS-257</td>
<td>SE 2.30 p.m.</td> <td>3.30 p.m.</td>
<td>CS-258 DAA</td>
</tr>
<tr>
<td>07/07/2022</td>
<td>11.00 a.m. - 12.00 p.m.</td>
<td>HUT-255</td>
<td>OB 2.30 p.m.</td>
<td>3.30 p.m.</td>
<td>ITT-42 PP</td>
</tr>
</table>
</body>
</html>
Q.5) Elaborate the concept of ADO.NET? What are the objects of ADO.NET?

—-> ADO.NET (ActiveX Data Objects for .NET) is a set of classes in the .NET Framework that facilitate
data access from various sources, including relational databases, XML documents, and other data
sources. It provides a consistent programming model for accessing and manipulating data.
Core components of ADO.NET :
1) Connection: Represents the connection to the data source, establishing a communication channel
between the application and the data store. 2) Command: Represents a command that can be executed
against the data source. 3) DataReader: Provides a read-only stream of data. 4) DataAdapter: Bridge the
gap between datasets and data sources . 5) DataSet: Represents a disconnected data cache. 6)
DataTable: Represents a two-dimensional tabular data structure, similar to a database table. 7) DataView:
Provides a filtered and sorted view of an underlying DataTable.

ADO.NET Objects : 1) Connection Objects: Classes like SqlConnection, OracleConnection, and


MySqlConnection establish connections to specific data sources. 2) Command Objects: Classes like
SqlCommand, OracleCommand, and MySqlCommand encapsulate SQL statements or stored
procedures. 3) Data Reader Objects: Classes like SqlDataReader, OracleDataReader, and
MySqlDataReader provide sequential data retrieval. 4) Data Adapter Objects: Classes like
SqlDataAdapter, OracleDataAdapter, and MySqlDataAdapter bridge datasets and data sources. 5)
DataSet Objects: Classes like DataSet and DataTable represent in-memory data structures for
disconnected data access. 6) Data View
Objects: Classes like DataView provide filtered and sorted views of underlying DataTable objects. 7) Data
Provider Objects: Classes like SqlClientFactory, OracleClientFactory, and MySqlClientFactory create
connection objects for specific data sources.
U-4
Q.1) Explain Configure Services and Configure method in ASP.NET?
—>
Feature ConfigureServices Configure

Register services with


the dependency Configure the HTTP
Purpose injection (DI) container. request pipeline

Called first during Called after


startup ConfigureServices
Timing

Define how to
handle HTTP
Responsi Manage object creation
requests
bility and lifetime
Q.2) How the edit functionality would work in ASP.NET MVC application.

—-> 1.The user clicks on the "Edit" link for a particular student on the index page. 2. This sends an HTTP
GET request to the Edit action method of the StudentController class. 3. The Edit action method retrieves
the student data from the database based on the ID parameter that is passed in the request. 4. The Edit
action method then renders the Edit view, passing in the student data as a model. 5.The Edit view displays
a form with the student data pre-populated. 6. The user makes any necessary changes to the student data
and submits the form. 7. This sends an HTTP POST request to the Edit action method, with the updated
student data in the request body. 8. The Edit action method validates the updated student data and saves it
to the database. 9. The Edit action method then redirects the user back to the index page.
Q.3) Draw and explain MVC application life cycle?
—--> The ASP.NET MVC application lifecycle is the sequence of events that happen every time an HTTP
request is handled by the application. It can be divided into the following stages:1.)Request: The client
sends an HTTP request to the server. The request includes the URL of the resource that the client wants
to access.The framework then parses the request and extracts the relevant information, such as the URL,
the HTTP method, and the request headers.2) Routing: The ASP.NET MVC framework routes the request
to the appropriate controller action. The routing process uses the URL and the route table to match the
request to a controller action. 3)Action execution: The controller action executes and returns a result. The
controller action is a method on a controller class. It is responsible for handling the request and returning
a result.4)Result execution: The ASP.NET MVC framework executes the result

and sends the response to the client. The result can be a view, a redirect, or a JSON object.
Q.4) How do you implement Forms authentication in MVC? What are the benefits of Forms
authentication?
—--> Steps :
1. Configure the web.config file:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" /> </authentication>
2. Create login and logout pages: You need to create a login page where users can enter their credentials
and a logout page to end their session. 3. Implement user authentication in your controller: In your
controller, you need to implement the action method that handles user authentication. 4. Use the
[Authorize] attribute to protect controller actions: You can use the [Authorize] attribute to protect
controller actions from unauthorized access.

Benefits of Forms authentication : 1. Ease of implementation: Forms authentication is easy to implement


and configure. 2. Flexibility: Forms authentication can be customized to meet the specific needs of your
application. 3. Scalability: Forms authentication can be used to scale to large applications. 4. Integration
with ASP.NET membership: Forms authentication can be integrated with ASP.NET
membership to provide additional features, such as role-based security.
Q.5) Explain what is routing in MVC. Justify the importance of three segments of
routing. —---> MVC, routing plays a crucial role in mapping incoming URLs to controller
actions. It acts as a bridge between the external world of URLs and the internal structure
of the application.

Importance of Three Segments in Routing :

1. Controller Name: The controller name identifies the specific controller class that should handle the request.
2.Action Method Name: The action method name specifies the specific method within the controller that
should be invoked to process the request.
3.Parameters: Parameters provide additional information to the action method, allowing it to handle specific
data or requests.
Q.6) Where Do We Use Middleware Components in the ASP.NET Core
Application?

—---> Common Use Cases for Middleware :


1. Authentication and authorization: Middleware components can be used to implement authentication
and authorization mechanisms, ensuring that only authorized users can access protected resources. 2.
Logging and error handling: Middleware components can be used to log incoming requests, responses,
and errors. 3. Content negotiation: Middleware components can be used to negotiate the content type
of responses based on the client's capabilities. 4. Caching: Middleware components can be used to
implement caching strategies, improving application performance.
5 .Request modification and redirection:
Middleware components can be used to modify incoming requests, such as adding headers or rewriting
URLs.

U-5
Q.1) Describe different types of Dependency injection in MVC.

—--->1 .Constructor Injection: It is the most common and recommended type of


dependency injection. It involves passing the dependencies to the constructor of the class that needs
them. 2. Setter Injection: It is a less common type of dependency injection. It involves setting the
dependencies on a property of the class that needs them. 3. Method Injection: It is the least common
type of dependency injection. It involves passing the dependencies to a method of the class that needs
them.
Benefits of Dependency Injection: 1. Loose coupling.2. Reusability. 3. Configurability.
Q.2) What are Data Annotation Validator Attributes in MVC?
—----> Data annotation validator attributes are attributes that are used to specify validation rules for
model properties in ASP.NET MVC applications.

Benefits of using data annotation validator attributes: 1.Ease of use. 2.Declarative syntax .
3. Automatic validation error messages.
Common Data Annotation Validator Attributes: 1.Required: This attribute specifies that a property is
required and cannot be null or empty. 2.StringLength: This attribute specifies the maximum and minimum
length of a string property. 3.Range: This attribute specifies the range of values that a numeric property can
have. 4.RegularExpression: This attribute specifies a regular expression that a property value must match.
5.EmailAddress. 6.Url.
7.Phone: This attribute specifies that a property value must be a valid phone number.

Q.3) Clarify what is the best practice with Web API error management.
—-> Here are some best practices for Web API error management:
1. Use Proper HTTP Status Codes:
2. Provide Error Details:
3. Use a Consistent Error Format:
4. Log Errors:
5. Use Exception Filters:
6. Implement Error Monitoring:
7. Provide User-Friendly Error Messages:
8. Offer Error Documentation:
9. Use Error Handling Middleware:
10. Consider Error Retries for Transient Errors:

Q.4) Illustrate the use of remote validation in MVC?

—--->It is a feature that allows you to validate data against a remote server without having to submit the
entire form. This is useful for situations where the data cannot be validated on the client.
To use remote validation, you will need to create a controller action that can handle the validation request.

Q.5) How can you incorporate both authentication and authorization mechanisms into a
Web API, and could you provide examples to illustrate this?

—----> it is crucial for securing access to sensitive data and enforcing user permissions. Authentication
verifies the identity of the user, while authorization determines what actions the user is allowed to
perform.

Example Scenario: Protecting an API Endpoint

Consider an API endpoint that retrieves a user's profile information. To protect this endpoint, you can
implement both authentication and authorization: 1 .Authentication: Use token-based authentication to
verify the identity of the user making the request. This ensures that only authenticated users can
access the endpoint. 2. Authorization: Use claims-based authorization to check if the user has the
required claim, such as "accessProfile," to retrieve the profile information. This ensures that only
authorized users can access the sensitive data.

Q.6) What are the Exception filters in MVC?


—-> They are a powerful mechanism for handling exceptions that occur during the execution of an
application.

Purpose of Exception Filters : 1. Centralized Error Handling: 2. Consistent Error Responses: 3.


Customizable Error Handling: 4. logging and monitoring.

Types of Exception Filters : 1.Global Exception Filters: These filters apply to all controllers and actions
in the application. They are typically used to handle common errors, such as 404 Not Found or 500
Internal Server Error. 2. Controller-specific Exception Filters: These filters are applied to specific
controllers or actions, allowing for more granular error handling. They are useful for handling errors
specific to a particular controller or action.

U-6
Q.1) Can a container autonomously initiate a restart, and what are the reasons for such
behavior? —--->Yes, a container can autonomously initiate a restart. This is called a restart policy.
Reasons : 1. The container has crashed: If the container crashes, it will be restarted automatically. 2.The
container has been updated: If the container has been updated, it will need to be restarted in order for the
new image to be used.3.The container has been unhealthy: If the container is unhealthy, it will be restarted
automatically.

Q.2) Enlist and explain any 4 Common Programming Principles.


—----->1. Keep It Simple (KISS) : The KISS principle states that software should be as simple as possible
to understand, use, and maintain. 2. Don't Repeat Yourself (DRY) : The DRY principle states that every
piece of knowledge should have a single, unambiguous, authoritative representation within a system. This
means that programmers should avoid duplicating code, data, or logic. 3. Single Responsibility Principle
(SRP) : The SRP states that a class should have only one reason to change. 4. Open-Closed Principle
(OCP) : The OCP states that software should be open for extension but closed for modification.

Q.3) Why should anyone Learn DevOps?


—----> Reasons : 1. Increased demand for DevOps professionals: This means that there are plenty of job
opportunities available for those with DevOps skills. 2.High salaries: DevOps professionals are in high
demand, and this translates to high salaries. 3. Career growth opportunities. 4. Make a real impact on
businesses: DevOps is essential for businesses that want to deliver high-quality software quickly and
efficiently. 5. Future-proof your career: DevOps is a future-proof skill. 6. Gain a comprehensive
understanding of software development lifecycle.7. Improve your problem-solving skills. 8. Become a more
versatile software engineer. 9. Join a thriving community: The DevOps community is a vibrant and
supportive group of professionals who are passionate about sharing their knowledge and helping others
succeed.

Q.4) Enlist the DevOps Automation


Tools? Which tools are the best? Explain in brief.
—--> 1. Terraform: Terraform is an infrastructure as code (IaC) tool that allows you to define and
manage your infrastructure using a declarative language.2.Ansible: Ansible is another popular IaC tool
that is known for its ease of use and flexibility.3. Chef: Chef is a popular configuration management tool
that uses a Ruby DSL to define and manage
configuration.4. Docker: Docker is a containerization platform that allows you to package your
applications and their dependencies into lightweight, portable containers.5.Jenkins: Jenkins is a
continuous integration (CI) and continuous delivery (CD) tool that automates the process of building,
testing, and deploying software.6.CircleCI: CircleCI is a cloud-based CI/CD tool that is popular among
startups and small businesses.7. Travis CI: Travis CI is another cloud-based CI/CD tool that is popular
among open-source projects.

Q.5) Discuss the term Dockers. Is Dockers a virtual machine?

—--->Docker is a platform for building, running, and managing containers. Containers are lightweight,
portable, and self-sufficient environments that contain an application and all of its dependencies. This
makes them easy to deploy and manage across different environments.

No, they are different as follows:


Virtual
Feature Docker Machine

Operating
system Host Guest
Resource
isolation Shared Isolated
Performance High Medium

Portability High Low


Q.6) What is the sequence of events that constitutes the lifecycle of a Docker container?
—->1.Created: The container is created from a Docker image. This involves copying the image's file
system to the host system and creating a container process that runs the image's entry point command.
2.Running: The container is started and its main process begins executing. The container is now in a state
where it can perform its intended function.
3.Paused: The container is paused and its processes are suspended. 4.Resumed: The container is
resumed and its processes continue executing. 5.Stopped: The container is stopped and its processes are
terminated. The container is no longer in memory and its resources are released. 6.Destroyed: The
container is destroyed and its filesystem is removed from the host system.

Here is a diagram that illustrates the Docker container lifecycle:


[Created] --> [Running] --> [Paused] -->
[Resumed] --> [Stopped] --> [Destroyed]

You might also like