Angular Interview Qu
Angular Interview Qu
What is Angular?
TypeScript is a superset of JavaScript that adds static typing to the language. Angular is built using
TypeScript, and it leverages features such as classes, interfaces, and decorators to enable strong
typing and better tooling for large-scale applications.
Some key features include two-way data binding, dependency injection, modular development,
declarative templates, and a powerful CLI (Command Line Interface).
Two-way data binding is a synchronization mechanism between the model and the view. Changes in
the model automatically reflect in the view, and vice versa. This is often achieved using the
[(ngModel)] directive in Angular.
Decorators are used to enhance the behavior of classes in Angular. They are annotations that provide
metadata for the Angular compiler. For example, @Component is used to define a component, and
@Injectable is used for services.
Dependency Injection (DI) is a design pattern used in Angular to create and manage dependencies
between different parts of an application. It helps in making components and services more modular
and reusable.
NgModule is a core building block of Angular applications. It is used to define a cohesive set of
components, directives, pipes, and services. Angular applications are modular, and each module can
have its own components, services, and more.
What is the difference between ngOnInit and constructor in Angular?
The constructor is a TypeScript feature and is used for class initialization. On the other hand,
ngOnInit is an Angular lifecycle hook that is called after the constructor and is specifically meant for
initialization code related to Angular.
Angular CLI (Command Line Interface) is a powerful tool for initializing, developing, scaffolding, and
maintaining Angular applications. It provides commands to generate components, services, modules,
and more, making the development process more efficient.
Directives in Angular are markers on a DOM element that tell Angular to attach a behavior to that
DOM element or transform the DOM element and its children. Examples include ngIf, ngFor, and
custom directives created by developers.
Certainly! *ngIf and *ngFor are structural directives in Angular that are used to conditionally render
or repeat elements in the DOM.
*ngIf
The *ngIf directive is used for conditional rendering. It evaluates an expression, and if the expression
is truthy, it renders the associated HTML template; otherwise, it removes the template from the
DOM.
Example:
html
Copy code
<div *ngIf="isUserLoggedIn">
</div>
In this example, the div element is only rendered if the isUserLoggedIn expression is true.
*ngFor
The *ngFor directive is used for iterating over a collection (such as an array) and rendering a
template for each item in the collection.
Example:
html
Copy code
<ul>
</ul>
In this example, the li element is repeated for each item in the items array.
Both *ngIf and *ngFor are prefixed with an asterisk (*) because they are structural directives. The
asterisk is a shorthand notation provided by Angular to make the code more readable.
Remember that *ngIf and *ngFor can be used together, allowing you to conditionally render and
repeat elements based on your application logic.
html
Copy code
<div *ngIf="showList">
<ul>
</ul>
</div>
In this case, the list will only be rendered if showList is true, and it will iterate over the items array if
the condition is met.
Jsp-java server page
JDBC
API
JDBC(Java Database Connectivity) is a Java API, which is helpful in interaction with the
database to retrieve, manipulate and process the data using SQL. It will make use of JDBC
drivers for connecting with the database. By using JDBC, we can access tabular data stored
in various types of relational databases such as Oracle, MySQL, MS Access, etc.
What is ResultSet?
The java.sql.ResultSet interface represents the database result set, which is obtained after the
execution of SQL query using Statement objects.
Object of ResultSet maintains a cursor pointing to the current row of data in the result set.
Initially, the cursor is located before the first row. Then the cursor is moved to the next row by
using the next() method. The next() method can be used to iterate through the result set with
the help of a while loop. If there are no further rows, the next() method will return false.
Example for the creation of ResultSet is given below:
ResultSet rs = con.executeQuery(sqlQuery).
Types of drivers
2, Native-API drive- The Native API driver uses the client-side libraries of the database. The driver
converts JDBC method calls into native calls of the database API. It is not written entirely in Java
3. ) Network Protocol drive- The Network Protocol driver uses middleware (application server)
that converts JDBC calls directly or indirectly into the vendor-specific database protocol. It is fully
written in Java. No client-side library is required
4) Thin driver The thin driver converts JDBC calls directly into the vendor-specific database
protocol. That is why it is known as a thin driver. It is fully written in Java language
Checked Exceptions:
Checked exceptions are exceptions that are checked at compile-time.
Code that may throw a checked exception must be enclosed in a try-catch block or declared in
the method signature using the throws keyword. This ensures that the calling code handles the
exception or declares it in its own throws clause.
Unchecked exceptions are exceptions that are not checked at compile-time but are checked at
runtime.