ui final Flashcards
What is the use of the ‘os’ module in Node.js?
deals with operating systems
What is the purpose of the “path” module in Node.js?
handles file paths
Which command is used to install a package globally in Node.js using npm?
Apply -g
How do you handle file operations in Node.js?
“fs”
Which one is a key feature of Node.js?
Uses an event-driven, non-blocking architecture that works on single
threaded model and processes events using callbacks.
* For example, HTTP calls made to server from Node.js code is non-blocking,
asynchronous, does not wait for the response, and handles the response when it
comes, using a callback model.
* This makes Node.js extremely effective and scalable for managing concurrent
connections and processes.
Which of the following method of fs module is used to read a file in Node.js?
fs.readFile()
Which one of the following command will display all globally installed packages in npm?
npm ls –depth=0 -global
What does the “require” function in Node.js do?
a built-in function to include external modules
that exist in separate files
How do you append data to a file in Node.js?
fs.appendFile()
In the context of Node.js, what does the term “REPL” mean?
Read Evaluate Print Loop
How is callback function used in Node.js?
A callback is a function that is invoked after the asynchronous
operation is finished and is supplied as an input to another function.
* Asynchronous operations in Node.js, such as reading files, making
network requests, or querying databases, are non-blocking,
– This means the code doesn’t wait for the operation to complete before moving
on to the next line.
– Instead, it initiates the operation and continues executing the remaining code.
– When the asynchronous operation is complete, a callback function is called
to handle the result or any errors.
In Node.js, callbacks usually follow an error-first convention, where the first parameter of the callback
function is reserved for an error object.
– If no error occurred, this parameter will be null or undefined.
– If an error occurs, the subsequent parameters may hold additional data.
Which built-in module should you use to make a HTTP request in Node.js?
“http”
core modules of node.js
“fs”, which handles file system operations
* “http”, which creates HTTP servers and clients
* “path”, which handles file paths
* “os”, which deals with operating systems
How do you copy a file in Node.js?
fs.copyFile()
How do you read a file in Node.js?
fs.readFile()
How do you write a file in Node.js?
fs.writeFile()
Node Package Manager
npm is a package manager for node.js and is comprised of
three components
– Website - to discover packages (https://www.npmjs.com/)
– Command Line Interface (CLI) – to run commands from a terminal
* this is how most developers interact with npm.
* npm gets installed automatically when you install node.js
* npm –v //tells version of npm installed
– Registry - a large public database of JavaScript libraries and the
meta-information surrounding it.
External Modules
External modules produced by the community can be installed
and utilized in Node.js applications using package managers like
npm
* These modules are available for installation with a single
command and are kept in the npm registry.
* Examples of external modules include:
* Axios for sending HTTP requests,
* Moment.js for handling dates and times, and
* Mongoose for interacting with MongoDB databases
even-driven architecture of Node.js
Node.js is based on a non-blocking, event-driven architecture,
* as a result, it is extremely effective at managing concurrent connections and I/O activities.
* Node.js uses a “single-threaded, event-driven” architecture, which eliminates the
need to create new threads for every connection
* and instead allows a single event loop to manage multiple concurrent connections.
* An event loop is used by Node.js to control events and callbacks.
* The callbacks are triggered by the event loop, which continuously scans for events like incoming
requests or finished I/O operations.
* Node.js handles asynchronous actions by using callbacks as a common pattern.
* All I/O operations in Node.js are carried out asynchronously via callbacks,
* Enabling the program to carry out other tasks without waiting for the I/O activity to finish.
* Examples of this include reading from a file, sending an HTTP request, or querying a database.
execute the content of a JavaScript file (module) from inside
another JavaScript file, include the 2nd file in the first file
require(/relative path of the 2nd file) statement
Node.js built-in functions: exports
Exports allows you to call functions that are defined in one module
(calculator.js file) from another module (hello.js file) using module.exports
What does the @SpringBootApplication annotation do in Spring Boot?
annotation is used to bootstrap a Spring Boot
application. It is a combination of @Configuration, @EnableAutoConfiguration,
and @ComponentScan.
In Spring Boot, what is the purpose of the @ResponseBody annotation?
used to indicate that the return value of a controller method should be
serialized and sent as the response body. It is typically used with the @RequestMapping annotation.
In Spring Boot, what is the purpose of the @PathVariableannotation?
used to extract a variable from the URI of a request. It is typically used
with the @RequestMapping annotation.
@Autowired
used to inject dependencies into a Spring Bean. It can be used to inject
dependencies on other beans, properties, and constructors.
Which of the following is a Spring module that allows you to work with relational database management systems (RDBMS) using Java Database Connectivity (JDBC)?
Spring JDBC module
@Service
It is typically used to define a business logic layer in a Spring application.
@RestController
used to create a RESTful web service. It is a specialized version of the
@Controller annotation that adds support for the HTTP methods GET, POST, PUT, DELETE, and others.
@RequestBody:
This annotation is used to extract the body of a request. It is typically used with the
@RequestMapping annotation.
@ExceptionHandler
This annotation is used to handle exceptions thrown by a controller method. It can be
used to return a specific HTTP response code or error message.
In Spring Boot, which of the following is used to bind a method parameter to the value of an HTTP header?
@RequestHeader
In Spring Boot, which of the following is a core module in Spring Framework?
Core Container
* DataAccess/Integration
* Web
* AOP/Instrumentation/Messaging
* Test
annotation is used to declare a JPA repository in Spring Data JPA?
@Repository
What is the purpose of the Spring Boot @Repository annotation?
This annotation is used to mark a class as a Spring Data repository. It tells
Spring to generate a repository implementation for the interface.
@Column
This annotation is used to specify the mapping between an entity field and a
column in a database table. It is typically used with the @Entity annotation.
@GeneratedValue
: This annotation is used to specify how the primary key of an entity is
generated.
@Id
This annotation is used to specify the primary key of an entity. It is typically used
with the @Entity annotation.
@Table:
This annotation is used to specify the name of the table that an entity is mapped
to. It is typically used with the @Entity annotation.
@Entity
This annotation is used to define an entity class. It is typically used to represent a
table in a database.
What does the Spring Framework provide to enterprise Java developers?
: Spring provides enterprise-level features like transaction management, security, and data access,
dependency management and build automation tool used in Spring Boot projects?
maven and gradle
What does the @EnableJpaRepositories annotation do in Spring Boot?
used to enable Spring Data JPA repositories
In a Spring Boot application, which of the following is the default embedded server?
Apache Tomcat.
What is Spring Data JPA primarily used for?
primarily used for simplifying the development of data access layers for Java applications that use the Java Persistence API (JPA) to interact with relational databases.
What does the Spring Boot @DeleteMapping annotation do?
used to map HTTP DELETE requests onto specific handler methods in your controller classes.
In Spring Boot, which of the following specifies a method parameter should be bound to the body of the web request?
@RequestBody
In Spring Boot, which of the following is used to handle exceptions?
@ExceptionHandler
What does the @Component annotation do in Spring Boot?
used to mark a class as a Spring Bean. It tells Spring to manage the
lifecycle of the bean and to inject its dependencies.
What is the purpose of the Spring Framework’s Inversion of Control (IoC) container?
A programming principle in which the control flow of a program is
inverted, with objects receiving dependencies from external
sources (like the Spring Framework) rather than (programmers)
creating them themselves (in the program)
The Spring IoC container is responsible for instantiating,
configuring and managing the lifecycle of the objects (beans).
* It simplifies the development of complex applications by reducing the
amount of boilerplate code required and promoting modularity and flexibility.
In Spring Boot, which of the following allows you to setup the application without the need of XML?
@Configuration and @Bean annotations.
What does the @RequestMapping annotation do in Spring Boot?
This annotation is used to map HTTP requests to controller methods. It is used to
specify the URI of the request and the HTTP method that the method should handle.
What does the Spring Boot @PutMapping annotation do?
used to map HTTP PUT requests onto specific handler methods
In Spring Boot, which of the following specifies a method, constructor argument, or field should be automatically populated with a value by Spring’s dependency injection facilities?
@Autowired.
Dependency Injection
A design pattern that allows objects to
receive their dependencies from
external sources rather than creating
them themselves.
Core Container
This contains the fundamental modules that are
the cornerstone of the Spring framework.
* Core (spring-core) is the core of the framework
that power features such as Inversion of Control
and dependency injection.
* Beans (spring-beans) provides Beanfactory,
which is a sophisticated implementation of the
factory pattern.
* Context (spring-context) builds on Core and
Beans and provides a medium to access defined
objects. ApplicationContext interface is the core
part of the Context module.
* SpEL (spring-expression) enables users to use
the Spring Expression Language to query and
manipulate the object graph at runtime.
Data Access/Integration
This includes the modules that are used to handle
data access and transaction processing in an
application.
* JDBC (spring-jdbc) provides a JDBC abstraction
layer that eliminates the need to separate JDBC
coding when dealing with databases.
* ORM (spring-orm) are integration layers for
popular object-relational mapping API such as
JPA, JDO Hibernate.
* OXM (spring-oxm) is the abstraction layer that
supports Object/XML mapping implementations
like JAXB, XStream.
* JMS (spring-jms) is the Java Messaging Service
module that creates and consumes messages
that directly integrate with the Spring messaging
module.
* Transaction (spring-tx) offers programmatic and
declarative transaction management for classes
that include special interfaces and POJOs.
Web
The Web layer relates to modules that
power web-based functions in Spring.
* WebSocket (spring-websocket) powers
the web socket-based communication for
clients and servers.
* Servlet (spring-webmvc) is the Spring
WebMVC module that contains the MVC
and REST implementations.
* Web (spring-web) provides all the basic
web-oriented features and contains an
HTTP client and web-related parts of the
Spring remoting.
* Portlet (spring-webmvc-portlet) provides
the MVC implementation to be used in a
portlet environment.
Other modules
AOP (spring
-aop) provides an aspect
-oriented
programming implementation. AOP aims to provide
more modularity to the cross
-cutting concerns, which
are functions that span across the application, such as
Logging, Caching, Transaction management,
Authentication
.
* Aspects (spring
-aspects) enables direct integration
with the AspectJ programming extension by the
eclipse foundation.
* Instrumentation (spring
-instrument) is the class
instrumentation support and class loader
implementations for application servers.
* Messaging (spring
-messaging) provides a robust
platform to manage messaging in applications.
* Spring Messaging module includes key abstractions
from the Spring Integration project and a set of
annotations for mapping messages to methods.
* Test (spring
-test) is the Spring test module that
supports unit and integration testing with JUnit and
TestNG.
Main Features of Spring Boot
Autoconfiguration automatically configures most of the application components
Embedded Server includes an embedded Tomcat, Jetty or Undertow server
Dependency
Management
manages the dependencies and their versions
Actuator provides information about the application health, metrics, and other details
Spring Data provides support for database integration
Spring Security provides security features such as authentication and authorization
What is the purpose of Hibernate in relation to JPA?
Hibernate is an open-source, lightweight, ORM tool.
* Hibernate implements JPA and further extends it with additional
features.
What does JPA stand for in the context of Java development?
Java Persistence API
In the context of JPA, what is an Entity?
Entities are persistence objects that are stored as records in database tables.
An entity represents a table in a relational database, and each entity instance
corresponds to a row in the table.
What does the @Entity annotation indicate in JPA?
ndicating that it is a JPA entity
How can CRUD operations be implemented using JPA and Hibernate?
using entitymanager
Which of the following best describes Object-Relational Mapping (ORM)?
JPA provides a way to map Java classes to
database tables and Java data types to SQL data types. This is defined through
annotations or XML, or a combination of both.
What does the @Table annotation do in JPA?
used to specify the details of the table that will be used to persist an entity in the database
What is the difference between @Embeddable and @Entity in JPA?
@Entity: Marks a class as a persistent entity, representing a table in the database.
@Embeddable: Defines a class whose instances are stored as part of an owning entity, sharing its identity
In JPA, what is a persistence context?
a set of entities such that for any persistent identity there is a unique entity instance
a valid way to create an instance of EntityManager?
EntityManagerFactory emf = Persistence.createEntityManagerFactory(“myPersistenceUnit”);
// Create EntityManager EntityManager em = emf.createEntityManager();
or
@PersistenceContext
private EntityManager entityManager;
public void performOperation() { // Use EntityManager entityManager.getTransaction().begin(); // Your CRUD operations here entityManager.getTransaction().commit(); }
What does the @Column annotation do in JPA?
Specify the column mapping
What does the @ElementCollection annotation do in JPA?
used to map a collection of basic or embeddable objects to a separate table in the database.
Which of the following is a valid role of the persistence context in JPA?
Managing Entity Lifecycle,First-Level Cache
what is the primary purpose of the Java Persistence API?
to provide a standardized way for Java developers to manage the persistence of object data by mapping Java objects to relational database tables,
responsibility of a repository in Spring Data JPA?
JPA Repository manages the persistent data in
a Spring Boot Application.
What does the term “Lazy Loading” refer to in the context of JPA?
to defer the loading of data until it is actually needed
What is the role of the @GeneratedValue annotation in JPA?
This annotation is used to specify how the primary key of an entity is
generated. It is typically used with the @Id annotation.
What is the purpose of the @Transient annotation in JPA?
Fields that should not be persisted
What is the purpose of the persistence.xml file in a JPA application?
used to configure a given JPA Persistence Unit
What is the purpose of the @OrderBy annotation in JPA?
Specifies the ordering of the elements of a collection valued association or element collection at the point when the association or collection is retrieved.