Uif 50 QB Answers
Uif 50 QB Answers
UNIT-1
✅ What is React?
React is an open-source JavaScript library developed by Facebook for building user interfaces (UI),
especially single-page applications (SPA) where data changes dynamically without refreshing the
page.
React follows a component-based architecture, meaning the UI is divided into reusable components,
each managing its own state.
Efficient UI updates: React uses a Virtual DOM that efficiently updates and renders only the
components that change.
Fast Performance: With virtual DOM and optimized rendering, React apps are faster.
SEO Friendly: Compared to other frontend libraries, React is better optimized for SEO.
Easier Debugging: React DevTools help in inspecting component states and props easily.
✅ Features of React
jsx
CopyEdit
2. Virtual DOM:
o React creates an in-memory data structure cache and only updates changed
elements.
3. Component-Based Architecture:
o UIs are broken into small, isolated, reusable components.
Example:
jsx
CopyEdit
function Welcome() {
o Data flows from parent to child component using props, ensuring better control.
5. Declarative UI:
o You describe what the UI should look like, and React takes care of the how.
6. React Native:
o Functional components can manage state and lifecycle methods using hooks like
useState, useEffect, etc.
Q2. What is a React Component? Explain Class Component and Functional Component with
examples.
A component is the building block of any React application. It returns JSX (HTML + JavaScript) that
tells what should appear on the screen.
🔹 1. Class Component
Example:
jsx
CopyEdit
render() {
return <h1>Hello from Class Component</h1>;
🔹 2. Functional Component
With Hooks (since React 16.8), can also handle state and side effects.
Example:
jsx
CopyEdit
function Welcome() {
jsx
CopyEdit
function Counter() {
return (
<div>
</div>
);
}
Q3. Write the steps involved in React installation.
o Verify:
bash
CopyEdit
node -v
npm -v
bash
CopyEdit
bash
CopyEdit
cd my-app
bash
CopyEdit
npm start
jsx
CopyEdit
constructor() {
super();
this.state = { count: 0 };
render() {
return (
<div>
<p>{this.state.count}</p>
</div>
);
jsx
CopyEdit
function Counter() {
return (
<div>
<p>{count}</p>
</div>
);
}
Q5. What are Props in React and how do they differ from React State?
Example:
jsx
CopyEdit
function Welcome(props) {
// Usage
Q6. Explain the types of forms in React. Write a code to create a basic form in React.
Difficulty: Medium
1. Controlled Components
2. Uncontrolled Components
jsx
CopyEdit
function MyForm() {
e.preventDefault();
};
return (
<form onSubmit={handleSubmit}>
<label>Name: </label>
<input
type="text"
value={name}
/>
<button type="submit">Submit</button>
</form>
);
Difficulty: Medium
shouldComponentUpdate(),
Updating When state or props change.
componentDidUpdate()
jsx
CopyEdit
constructor(props) {
super(props);
console.log('Constructor');
componentDidMount() {
console.log('Component Mounted');
componentDidUpdate() {
console.log('Component Updated');
componentWillUnmount() {
console.log('Component Unmounted');
render() {
}
}
Note: Functional components use Hooks like useEffect to simulate lifecycle behavior.
Difficulty: Medium
🔹 Example:
jsx
CopyEdit
function Greet(props) {
// Usage
Q9. What is React JSX? What are the advantages of React JSX? Write a program using React JSX.
Difficulty: Easy
✅ What is JSX?
JSX stands for JavaScript XML. It allows writing HTML-like syntax inside JavaScript, which React
converts into React.createElement() calls.
✅ Advantages of JSX:
jsx
CopyEdit
import React from 'react';
function Greeting() {
Q10. What is Virtual DOM? How virtual DOM is different from actual DOM?
Difficulty: Easy
✅ Virtual DOM:
Whenever the state of a component changes, a new Virtual DOM is created and compared
with the previous one using Diffing Algorithm.
✅ UNIT-2: Q11–Q20
Q11. How to define an event in React? Write a program for creating an “onClick” event.
Difficulty: Medium
React handles events similarly to HTML, but with camelCase and JSX syntax.
jsx
CopyEdit
function ClickButton() {
};
return (
);
jsx
CopyEdit
return (
<ol>
<li key={index}>{item}</li>
))}
</ol>
);
Difficulty: Hard
Keys help React identify which items changed, are added, or are removed.
Boosts performance.
🔹 Example:
jsx
CopyEdit
<ul>
<li key={index}>{fruit}</li>
))}
</ul>
);
Difficulty: Easy
Purpose Identify list items uniquely Access DOM nodes or React elements
Q15. What is React Router? Explain the purpose of React Router with an example.
Difficulty: Hard
✅ React Router:
A routing library for React used to create single-page applications with navigation between
views.
🔹 Example:
jsx
CopyEdit
function App() {
return (
<BrowserRouter>
<Routes>
</Routes>
</BrowserRouter>
);
Difficulty: Hard
✅ What is an HOC?
A Higher-Order Component is a function that takes a component and returns a new enhanced
component.
jsx
CopyEdit
console.log("Props:", props);
};
};
Use Case: Add logging, auth checks, theming, etc., without changing original components.
Difficulty: Medium
jsx
CopyEdit
function StudentTable() {
const students = [
];
return (
<table border="1">
<thead>
<tr><th>ID</th><th>Name</th><th>Age</th></tr>
</thead>
<tbody>
{students.map((student) => (
<tr key={student.id}>
<td>{student.id}</td>
<td>{student.name}</td>
<td>{student.age}</td>
</tr>
))}
</tbody>
</table>
);
Q18. What are React Hooks? Write a program using useState Hook in React.
Difficulty: Hard
Hooks let you use state and lifecycle features in functional components.
🔹 Common Hooks:
useState()
useEffect()
useContext()
useRef()
jsx
CopyEdit
function Counter() {
return (
<>
<p>Count: {count}</p>
</>
);
Difficulty: Medium
✅ What is Redux?
Redux is a state management library used with React. It stores the entire application state in a
single object.
✅ Components of Redux:
Component Description
Q20. What is the importance of code splitting in React? Explain with an example.
Difficulty: Hard
jsx
CopyEdit
function App() {
return (
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>
);
Difficulty: Easy
✅ What is Angular?
Feature Description
Two-Way Binding Syncs data between the component and the template automatically.
RxJS and Observables Supports reactive programming using RxJS for asynchronous data streams.
Difficulty: Easy
Difficulty: Medium
✅ Generating a Component:
bash
CopyEdit
# or shorthand
ng g c component-name
🔹 Example:
bash
CopyEdit
ng g c student
It creates:
student.component.ts
student.component.html
student.component.css
student.component.spec.ts
Q24. Write the classification of Angular directives. Explain ngIf directive with an example.
Difficulty: Medium
✅ Types of Directives:
1. Structural Directives – Change the DOM layout (e.g., *ngIf, *ngFor, *ngSwitch)
🔹 ngIf Example:
html
CopyEdit
ts
CopyEdit
isLoggedIn = true;
i. ngFor
ii. ngSwitch
Difficulty: Medium
html
CopyEdit
<ul>
</ul>
Component:
ts
CopyEdit
html
CopyEdit
<div [ngSwitch]="role">
</div>
Q26. Write down the steps for Routing in Angular and write a program to create a simple webpage
using Angular Router.
Difficulty: Hard
ts
CopyEdit
2. Define Routes:
ts
CopyEdit
];
3. Add to imports:
ts
CopyEdit
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
html
CopyEdit
<nav>
<a routerLink="/">Home</a>
<a routerLink="/about">About</a>
</nav>
<router-outlet></router-outlet>
Q27. Write down the installation steps of Angular.
Difficulty: Easy
✅ Installation Steps:
1. Install Node.js
Download from: https://nodejs.org
bash
CopyEdit
bash
CopyEdit
ng new my-app
bash
CopyEdit
cd my-app
ng serve
Difficulty: Medium
html
CopyEdit
</p>
Or dynamically:
html
CopyEdit
ts
CopyEdit
styleObject = {
color: 'green',
'font-size.px': 20
};
Q29. What are attribute directives in Angular? Write a program in Angular using ngClass directive.
Difficulty: Medium
✅ Attribute Directives:
🔹 ngClass Example:
html
CopyEdit
In component:
ts
CopyEdit
isImportant = true;
CSS:
css
CopyEdit
.highlight {
color: red;
font-weight: bold;
}
Q30. Write a program in Angular to display the message “Welcome to Angular” and style the text
by applying any three different CSS styles.
Difficulty: Medium
html
CopyEdit
Component:
ts
CopyEdit
styles = {
color: 'purple',
'font-size.px': 30,
'text-align': 'center'
};
Q31. Write the differences between template driven forms and reactive forms in Angular.
Difficulty: Easy
Feature Template Driven Form Reactive Form
Form Creation Created in HTML using directives Created in component class using code
Control Less control over form Full control via FormGroup, FormControl
Difficulty: Medium
ts
CopyEdit
@NgModule({
imports: [FormsModule]
})
🔹 Step 2: app.component.html
html
CopyEdit
<label>Name:</label>
<label>Email:</label>
<button type="submit">Submit</button>
</form>
🔹 Step 3: app.component.ts
ts
CopyEdit
submitForm(data: any) {
console.log(data);
Difficulty: Hard
ts
CopyEdit
@NgModule({
imports: [ReactiveFormsModule]
})
🔹 Step 2: app.component.ts
ts
CopyEdit
});
submitForm() {
console.log(this.userForm.value);
}
🔹 Step 3: app.component.html
html
CopyEdit
<label>Name:</label>
<input formControlName="name">
<label>Email:</label>
<input formControlName="email">
<button type="submit">Submit</button>
</form>
Q34. Define Angular Pipes. Explain built-in Angular pipes with examples.
Difficulty: Medium
a) Lowercase pipe
b) Uppercase pipe
c) Date pipe
d) Currency pipe
Difficulty: Medium
🔹 app.component.ts
ts
CopyEdit
price = 1234.56;
🔹 app.component.html
html
CopyEdit
Difficulty: Medium
bash
CopyEdit
🔹 reverse.pipe.ts
ts
CopyEdit
return value.split('').reverse().join('');
}
🔹 app.component.html
html
CopyEdit
Difficulty: Hard
✅ Angular Services
Services are used to write reusable logic, such as API calls, data sharing, etc.
DI is a design pattern in Angular that allows injecting services into components or other services.
🔹 Example Service:
ts
CopyEdit
getMessage() {
🔹 Injecting in a Component:
ts
CopyEdit
ngOnInit() {
console.log(this.dataService.getMessage());
Difficulty: Medium
✅ Angular HTTP Services:
🔹 Setup:
ts
CopyEdit
@NgModule({
imports: [HttpClientModule]
})
ts
CopyEdit
ngOnInit() {
this.http.get('https://api.example.com/data').subscribe(result => {
console.log(result);
});
Difficulty: Medium
Part Description
a) Percent pipe
b) Decimal pipe
c) Slice pipe
Difficulty: Medium
🔹 app.component.ts
ts
CopyEdit
value = 0.5678;
price = 1234.56789;
🔹 app.component.html
html
CopyEdit
Q41. What is Tkinter? Write the steps to create a simple window using Tkinter.
Difficulty: Easy
✅ What is Tkinter?
Tkinter is the standard GUI (Graphical User Interface) library for Python. It provides a fast and easy
way to create GUI applications using widgets such as buttons, labels, text boxes, and menus. Tkinter
acts as a wrapper around the Tcl/Tk GUI toolkit.
🔹 Key Features of Tkinter:
Widget-rich: Supports a variety of widgets like Label, Button, Entry, Menu, Canvas, etc.
python
CopyEdit
import tkinter as tk
window = tk.Tk()
window.geometry("400x300")
window.mainloop()
✅ Explanation:
mainloop(): Runs the application and waits for events (like button clicks or key presses).
**Q42. Define Widget in Tkinter. Write a Python program to create the following widgets:
a. Label Widget
b. Button Widget**
Difficulty: Medium
✅ What is a Widget in Tkinter?
In Tkinter, a widget is an element of the graphical user interface (GUI). Each widget serves a specific
purpose in building interactive applications. For example:
🔹 a. Label Widget:
Syntax:
python
CopyEdit
🔹 b. Button Widget:
Syntax:
python
CopyEdit
python
CopyEdit
import tkinter as tk
window = tk.Tk()
window.title("Tkinter Widgets Example")
window.geometry("400x200")
def on_button_click():
button.pack()
window.mainloop()
✅ Explanation of Code:
Line Description
label.config() Changes the text and color of the label on button click
Q43. Explain the importance of Entry widget and CheckButton widget with an example.
Difficulty: Medium
✅ Entry Widget:
The Entry widget allows users to input a single line of text (like usernames, emails, etc.).
Commonly used for collecting data from the user.
Syntax:
python
CopyEdit
entry = tk.Entry(parent)
✅ CheckButton Widget:
A Checkbutton allows the user to select or deselect options (like "I agree", "Subscribe").
Syntax:
python
CopyEdit
✅ Program Example
python
CopyEdit
import tkinter as tk
def show_data():
name = entry_name.get()
agreement = var_agree.get()
label_output.config(text=message)
window = tk.Tk()
window.geometry("300x200")
# Entry widget
entry_name = tk.Entry(window)
entry_name.pack()
# Checkbutton widget
var_agree = tk.IntVar()
check.pack()
# Submit Button
submit.pack(pady=10)
label_output = tk.Label(window)
label_output.pack()
window.mainloop()
Q44. Define Geometry Manager classes and list the types of Geometry Manager classes. Explain
any one type with an example.
Difficulty: Hard
Geometry managers are used to control the placement and layout of widgets in a window.
python
CopyEdit
import tkinter as tk
window = tk.Tk()
window.title("pack() Example")
window.geometry("300x200")
window.mainloop()
Difficulty: Hard
The grid() manager places widgets in a matrix format using rows and columns.
python
CopyEdit
import tkinter as tk
window = tk.Tk()
window.title("grid() Example")
window.geometry("300x150")
entry_user = tk.Entry(window)
entry_user.grid(row=0, column=1)
tk.Label(window, text="Password").grid(row=1, column=0)
entry_pass.grid(row=1, column=1)
btn.grid(row=2, column=1)
window.mainloop()
Q46. Explain how events are handled in Tkinter with an example program.
Difficulty: Hard
Tkinter uses an event-driven model, meaning it waits for user actions (events) like clicks, key
presses, etc., and responds using event handlers (callback functions).
python
CopyEdit
widget.bind("<event>", handler_function)
python
CopyEdit
import tkinter as tk
def on_key_press(event):
def on_mouse_click(event):
label.config(text=f"Mouse Clicked at ({event.x}, {event.y})")
window = tk.Tk()
window.title("Event Handling")
window.geometry("300x150")
label.pack(pady=20)
window.bind("<Key>", on_key_press)
window.bind("<Button-1>", on_mouse_click)
window.mainloop()
a. RadioButton Widget
b. List Widget**
Difficulty: Medium
python
CopyEdit
import tkinter as tk
def show_selection():
selected = radio_var.get()
window = tk.Tk()
window.geometry("300x250")
# RadioButton
radio_var = tk.StringVar()
# Listbox
listbox = tk.Listbox(window)
listbox.pack()
window.mainloop()
Difficulty: Medium
python
CopyEdit
import tkinter as tk
window = tk.Tk()
window.title("Scrollbar Example")
window.geometry("300x200")
# Text widget
# Vertical scrollbar
text.config(yscrollcommand=scrollbar.set)
for i in range(50):
window.mainloop()
Q49. Write a program to design a Text Widget and Message Widget using Tkinter.
Difficulty: Medium
python
CopyEdit
import tkinter as tk
window = tk.Tk()
window.geometry("400x300")
text_box.pack()
msg.pack(pady=20)
window.mainloop()
Q50. What is a GUI? List the Python libraries available for designing a GUI. Write a program to
display “Hello world!!” message in Tkinter.
Difficulty: Easy
✅ What is a GUI?
A Graphical User Interface (GUI) is a visual interface that allows users to interact with software using
elements like buttons, menus, windows, etc., instead of using a command-line interface (CLI).
python
CopyEdit
import tkinter as tk
window = tk.Tk()
window.title("Hello App")
window.geometry("250x100")
label.pack(pady=20)
window.mainloop()